Files
Aberwyn/Aberwyn/Controllers/HomeController.cs
elias 76656bb6a8
All checks were successful
continuous-integration/drone/push Build is passing
Lots of fixes
2025-06-15 10:49:04 +02:00

88 lines
2.8 KiB
C#

using Aberwyn.Data;
using Aberwyn.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
namespace Aberwyn.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
//private readonly BudgetService _budgetService;
private readonly MenuService _menuService;
private readonly ApplicationDbContext _context;
// Constructor to inject dependencies
public HomeController(ApplicationDbContext applicationDbContext, ILogger<HomeController> logger, MenuService menuService)
{
_logger = logger;
_menuService = menuService;
_context = applicationDbContext;
}
public IActionResult Index()
{
var isOpen = _context.AppSettings.FirstOrDefault(x => x.Key == "RestaurantIsOpen")?.Value == "True";
ViewBag.RestaurantIsOpen = isOpen;
var now = DateTime.Now;
var showDate = now.Hour >= 20 ? now.Date.AddDays(1) : now.Date;
var todaysMenu = _menuService.GetMenuForDate(showDate);
ViewBag.ShowDate = showDate;
return View(todaysMenu);
}
public IActionResult Privacy()
{
return View();
}
public IActionResult RealEstate()
{
return View();
}
public IActionResult Menu()
{
ViewData["HideSidebar"] = true;
// Get the current date and week
var currentDate = DateTime.Now;
var currentYear = currentDate.Year;
var calendar = new GregorianCalendar();
var currentWeek = calendar.GetWeekOfYear(currentDate, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
// Fetch weekly menu items for the current week and year
var weeklyMenus = _menuService.GetWeeklyMenu(currentWeek, currentYear);
var meals = _menuService.GetMeals(); // Fetch all meals
var model = new MenuViewModel
{
WeeklyMenus = weeklyMenus, // List of WeeklyMenu items
Meals = meals, // List of available meals
WeekNumber = currentWeek, // Dynamically set the current week number
Year = currentYear // Dynamically set the current year
};
return View(model);
}
public IActionResult Budget()
{
ViewData["HideSidebar"] = true;
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}