-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
48f9bda
commit 83c5f2a
Showing
25 changed files
with
1,386 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using PropertyInventorySystem.Data; | ||
using PropertyInventorySystem.Models; | ||
|
||
namespace PropertyInventorySystem.Controllers | ||
{ | ||
public class PropertyDashboardController : Controller | ||
{ | ||
private readonly AppDbContext _context; | ||
|
||
public PropertyDashboardController(AppDbContext context) | ||
{ | ||
_context = context; | ||
} | ||
public async Task<IActionResult> Index() | ||
{ | ||
try | ||
{ | ||
// Fetch sold properties including related Property and Contact data | ||
var soldProperties = await _context.SoldProperties | ||
.Include(sp => sp.Property) | ||
.Include(sp => sp.Contact) | ||
.ToListAsync(); | ||
|
||
// Map to the ViewModel | ||
var dashboardData = soldProperties.Select(sp => new PropertyDashboardViewModel | ||
{ | ||
// Id = sp.Property.Id,s | ||
PropertyName = sp.Property.Name, | ||
AskingPriceEUR = sp.Property.Price, // Assuming this is the asking price | ||
Owner = $"{sp.Contact.FirstName} {sp.Contact.LastName}", | ||
ContactNumber = sp.Contact.PhoneNumber, | ||
Email = sp.Contact.Email, | ||
PropertyAddress = sp.Property.Address, | ||
DateOfPurchase = sp.Property.DateOfRegistration, // Assuming this is the purchase date | ||
SoldAtPriceEUR = sp.AcquisitionPrice, // Assuming SoldProperty has this field | ||
SoldAtPriceUSD = ConvertEURtoUSD(sp.AcquisitionPrice) // Convert using your method | ||
}).ToList(); | ||
|
||
return View(dashboardData); | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Log the exception details | ||
// Consider using a logging framework or service | ||
Console.WriteLine(ex.ToString()); | ||
|
||
// Optionally, return a custom error view | ||
// return View("Error"); | ||
|
||
// Or return a generic error message to the user | ||
return Content("An error occurred while processing your request. Please try again later."); | ||
} | ||
} | ||
private decimal ConvertEURtoUSD(decimal amountEUR) | ||
{ | ||
decimal exchangeRate = 1.10M; // Placeholder exchange rate | ||
return amountEUR * exchangeRate; | ||
} | ||
} | ||
} |
Oops, something went wrong.