feat: Add Lawn Care Tips section and improve Dashboard layout
This commit is contained in:
parent
1f50fedb80
commit
985c944e16
17 changed files with 689 additions and 18 deletions
|
|
@ -10,22 +10,18 @@ public class HomeController : Controller
|
|||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
// Step 2.1: Inject the database context
|
||||
public HomeController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// Step 2.2: Make the Index action async
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
// Step 2.3: Query for the last mow event to get its date and pattern
|
||||
var lastMowEvent = await _context.LawnCareEvents
|
||||
.Where(e => e.EventType == LawnCareEventType.Mowing)
|
||||
.OrderByDescending(e => e.EventDate)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
// Step 2.4: Query for the last water and fertilize dates
|
||||
var lastWaterDate = await _context.LawnCareEvents
|
||||
.Where(e => e.EventType == LawnCareEventType.Watering)
|
||||
.OrderByDescending(e => e.EventDate)
|
||||
|
|
@ -38,6 +34,12 @@ public class HomeController : Controller
|
|||
.Select(e => (DateTime?)e.EventDate)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
var lastAerationDate = await _context.LawnCareEvents
|
||||
.Where(e => e.EventType == LawnCareEventType.Aeration)
|
||||
.OrderByDescending(e => e.EventDate)
|
||||
.Select(e => (DateTime?)e.EventDate)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
// Determine the next mowing pattern
|
||||
MowingPattern? nextPattern = MowingPattern.Vertical; // Default
|
||||
if (lastMowEvent?.MowingPattern != null)
|
||||
|
|
@ -48,16 +50,15 @@ public class HomeController : Controller
|
|||
nextPattern = (MowingPattern)nextPatternValue;
|
||||
}
|
||||
|
||||
// Step 2.5: Create the ViewModel and populate it
|
||||
var viewModel = new DashboardViewModel
|
||||
{
|
||||
LastMowDate = lastMowEvent?.EventDate,
|
||||
LastWaterDate = lastWaterDate,
|
||||
LastFertilizeDate = lastFertilizeDate,
|
||||
LastAerationDate = lastAerationDate,
|
||||
NextMowingPattern = nextPattern
|
||||
};
|
||||
|
||||
// Step 2.6: Pass the populated ViewModel to the view
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue