 5074a9664a
			
		
	
	
		5074a9664a
		
	
	
	
	
		
			
			This commit introduces a new "Lawn Care Tips" section to the application and refines the visual layout of the main Dashboard.
**Key Changes:**
*   **Lawn Care Tips Feature:**
    *   Added `LawnCareTip` model with `Title`, `Category`, and `Content` properties.
    *   Defined `TipCategory` enum for better organization (Mowing, Watering, Fertilizing, Weed Control, Aeration, General).
    *   Integrated `LawnCareTip` into `ApplicationDbContext` for database persistence.
    *   Updated `_Layout.cshtml` to include a new "Lawn Tips" navigation link.
*   **Dashboard Layout Fix:**
    *   Refactored `Views/Home/Index.cshtml` to correctly use Bootstrap's grid system by placing the "Log a New Activity" card in its own `div.row`. This resolves the layout issue where the card was appearing immediately after the previous row without proper spacing.
    *   Updated `HomeController` to include a `LastAerationDate` query for the dashboard display.
    *   Modified `DashboardViewModel` to include `LastAerationDate`.
*   **Build/Dependency Updates:**
    *   Added `Microsoft.EntityFrameworkCore.SqlServer` (likely a residue from scaffolding, though SQLite is still primary).
    *   Added `Microsoft.VisualStudio.Web.CodeGeneration.Design` for scaffolding tools.
This enhances the application's functionality by providing a knowledge base and improves the user experience with a cleaner dashboard layout.
		
	
			
		
			
				
	
	
		
			75 lines
		
	
	
		
			No EOL
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			75 lines
		
	
	
		
			No EOL
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System.Diagnostics;
 | |
| using Microsoft.AspNetCore.Mvc;
 | |
| using Microsoft.EntityFrameworkCore;
 | |
| using turf_tasker.Data;
 | |
| using turf_tasker.Models;
 | |
| 
 | |
| namespace turf_tasker.Controllers;
 | |
| 
 | |
| public class HomeController : Controller
 | |
| {
 | |
|     private readonly ApplicationDbContext _context;
 | |
| 
 | |
|     public HomeController(ApplicationDbContext context)
 | |
|     {
 | |
|         _context = context;
 | |
|     }
 | |
| 
 | |
|     public async Task<IActionResult> Index()
 | |
|     {
 | |
|         var lastMowEvent = await _context.LawnCareEvents
 | |
|             .Where(e => e.EventType == LawnCareEventType.Mowing)
 | |
|             .OrderByDescending(e => e.EventDate)
 | |
|             .FirstOrDefaultAsync();
 | |
| 
 | |
|         var lastWaterDate = await _context.LawnCareEvents
 | |
|             .Where(e => e.EventType == LawnCareEventType.Watering)
 | |
|             .OrderByDescending(e => e.EventDate)
 | |
|             .Select(e => (DateTime?)e.EventDate) // Select just the date
 | |
|             .FirstOrDefaultAsync();
 | |
| 
 | |
|         var lastFertilizeDate = await _context.LawnCareEvents
 | |
|             .Where(e => e.EventType == LawnCareEventType.Fertilizing)
 | |
|             .OrderByDescending(e => e.EventDate)
 | |
|             .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)
 | |
|         {
 | |
|             // This logic cycles through the enum values
 | |
|             int currentPatternValue = (int)lastMowEvent.MowingPattern;
 | |
|             int nextPatternValue = (currentPatternValue + 1) % 4; // 4 patterns total
 | |
|             nextPattern = (MowingPattern)nextPatternValue;
 | |
|         }
 | |
| 
 | |
|         var viewModel = new DashboardViewModel
 | |
|         {
 | |
|             LastMowDate = lastMowEvent?.EventDate,
 | |
|             LastWaterDate = lastWaterDate,
 | |
|             LastFertilizeDate = lastFertilizeDate,
 | |
|             LastAerationDate = lastAerationDate,
 | |
|             NextMowingPattern = nextPattern
 | |
|         };
 | |
|         
 | |
|         return View(viewModel);
 | |
|     }
 | |
| 
 | |
|     public IActionResult Privacy()
 | |
|     {
 | |
|         return View();
 | |
|     }
 | |
| 
 | |
|     [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
 | |
|     public IActionResult Error()
 | |
|     {
 | |
|         return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
 | |
|     }
 | |
| } |