diff --git a/Aberwyn/Aberwyn.csproj b/Aberwyn/Aberwyn.csproj
index 6cc03ce..5e012f0 100644
--- a/Aberwyn/Aberwyn.csproj
+++ b/Aberwyn/Aberwyn.csproj
@@ -10,6 +10,7 @@
+ all
@@ -20,4 +21,9 @@
+
+
+
+
+
diff --git a/Aberwyn/Controllers/BudgetApiController.cs b/Aberwyn/Controllers/BudgetApiController.cs
index 098129a..2c39080 100644
--- a/Aberwyn/Controllers/BudgetApiController.cs
+++ b/Aberwyn/Controllers/BudgetApiController.cs
@@ -19,16 +19,31 @@ namespace Aberwyn.Controllers
[HttpGet("items")]
public IActionResult GetBudgetItems([FromQuery] int month, [FromQuery] int year)
{
- var items = _budgetService.GetBudgetItems(month, year);
- return Ok(items);
+ try
+ {
+ var items = _budgetService.GetBudgetItems(month, year);
+ return Ok(items);
+ }
+ catch (Exception ex)
+ {
+ // Log the exception (consider using a logging framework)
+ return StatusCode(500, new { message = "An error occurred while fetching budget items.", details = ex.Message });
+ }
}
- // New endpoint to get categories
[HttpGet("categories")]
public IActionResult GetCategories()
{
- var categories = _budgetService.GetCategories();
- return Ok(categories);
+ try
+ {
+ var categories = _budgetService.GetCategories();
+ return Ok(categories);
+ }
+ catch (Exception ex)
+ {
+ // Log the exception
+ return StatusCode(500, new { message = "An error occurred while fetching categories.", details = ex.Message });
+ }
}
[HttpPut("items")]
@@ -39,15 +54,20 @@ namespace Aberwyn.Controllers
return BadRequest("Invalid budget item data.");
}
- // Assuming you have a method in your BudgetService to update an item
- var result = _budgetService.UpdateBudgetItem(item);
-
- if (result)
+ try
{
- return Ok("Item updated successfully.");
+ var result = _budgetService.UpdateBudgetItem(item);
+ if (result)
+ {
+ return Ok("Item updated successfully.");
+ }
+ return StatusCode(500, "Error updating item.");
+ }
+ catch (Exception ex)
+ {
+ // Log the exception
+ return StatusCode(500, new { message = "An error occurred while updating the item.", details = ex.Message });
}
-
- return StatusCode(500, "Error updating item.");
}
[HttpPost("items")]
@@ -58,17 +78,20 @@ namespace Aberwyn.Controllers
return BadRequest("Invalid budget item data.");
}
- // Assuming you have a method in your BudgetService to add an item
- var result = _budgetService.AddBudgetItem(item);
-
- if (result)
+ try
{
- return CreatedAtAction(nameof(GetBudgetItems), new { id = item.ID }, item);
+ var result = _budgetService.AddBudgetItem(item);
+ if (result)
+ {
+ return CreatedAtAction(nameof(GetBudgetItems), new { id = item.ID }, item);
+ }
+ return StatusCode(500, "Error adding item.");
+ }
+ catch (Exception ex)
+ {
+ // Log the exception
+ return StatusCode(500, new { message = "An error occurred while adding the item.", details = ex.Message });
}
-
- return StatusCode(500, "Error adding item.");
}
-
}
-
}
diff --git a/Aberwyn/Controllers/HomeController.cs b/Aberwyn/Controllers/HomeController.cs
index 3137eec..15df38f 100644
--- a/Aberwyn/Controllers/HomeController.cs
+++ b/Aberwyn/Controllers/HomeController.cs
@@ -11,12 +11,15 @@ namespace Aberwyn.Controllers
{
private readonly ILogger _logger;
private readonly BudgetService _budgetService;
+ private readonly MenuService _menuService;
+
// Constructor to inject dependencies
- public HomeController(ILogger logger, BudgetService budgetService)
+ public HomeController(ILogger logger, BudgetService budgetService, MenuService menuService)
{
_logger = logger;
_budgetService = budgetService;
+ _menuService = menuService;
}
public IActionResult Index()
@@ -34,6 +37,31 @@ namespace Aberwyn.Controllers
return View();
}
+ public IActionResult Menu()
+ {
+ // 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);
+ }
+
+
+
// Optimized Budget Action to fetch filtered data directly from the database
public IActionResult Budget(string month, int? year)
{
diff --git a/Aberwyn/Controllers/MealMenuApiController.cs b/Aberwyn/Controllers/MealMenuApiController.cs
new file mode 100644
index 0000000..5a503ab
--- /dev/null
+++ b/Aberwyn/Controllers/MealMenuApiController.cs
@@ -0,0 +1,81 @@
+// MealMenuApiController.cs
+using Aberwyn.Models;
+using Aberwyn.Data;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Aberwyn.Controllers
+{
+ [ApiController]
+ [Route("api/[controller]")]
+ public class MealMenuApiController : ControllerBase
+ {
+ private readonly MenuService _menuService;
+
+ public MealMenuApiController(MenuService menuService)
+ {
+ _menuService = menuService;
+ }
+
+ // API endpoint to fetch the weekly menu
+ [HttpGet("menu")]
+ public IActionResult GetMenu(int weekNumber, int year)
+ {
+ var menu = _menuService.GetWeeklyMenu(weekNumber, year);
+
+ if (menu == null || !menu.Any())
+ {
+ // Return an empty object or array instead of a 404 error
+ return Ok(new List()); // Return empty list if no menu is found
+ }
+
+ return Ok(menu); // Return the menu as a JSON response
+ }
+
+ // API endpoint to fetch the weekly menu
+ [HttpGet("getMeals")]
+ public IActionResult GetMeals()
+ {
+ var meals = _menuService.GetMeals();
+
+ if (meals == null || !meals.Any())
+ {
+ // Return an empty object or array instead of a 404 error
+ return Ok(new List()); // Return empty list if no menu is found
+ }
+
+ return Ok(meals); // Return the menu as a JSON response
+ }
+
+ // API endpoint to save the updated menu (if you need this)
+ [HttpPut("menu")]
+ public IActionResult SaveMenu([FromBody] MenuViewModel weeklyMenu)
+ {
+ // Process and save the menu (you may need to write this logic)
+ _menuService.UpdateWeeklyMenu(weeklyMenu);
+
+ return Ok("Menu saved successfully");
+ }
+
+
+ [HttpPost("addMeal")]
+ public IActionResult AddMeal([FromBody] Meal meal)
+ {
+ if (meal == null || string.IsNullOrWhiteSpace(meal.Name))
+ {
+ return BadRequest("Meal Name is required.");
+ }
+
+ var mealId = _menuService.AddMeal(meal);
+
+ if (mealId > 0)
+ {
+ return Ok(new { Message = "Meal added successfully", MealId = mealId });
+ }
+
+ return StatusCode(500, "Failed to add meal.");
+ }
+
+
+
+ }
+}
diff --git a/Aberwyn/Controllers/RealEstateApiController.cs b/Aberwyn/Controllers/RealEstateApiController.cs
index 88c76b5..c33d82c 100644
--- a/Aberwyn/Controllers/RealEstateApiController.cs
+++ b/Aberwyn/Controllers/RealEstateApiController.cs
@@ -1,45 +1,157 @@
-using Microsoft.AspNetCore.Mvc;
+using HtmlAgilityPack;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
[Route("api/[controller]")]
[ApiController]
-public class RealEstateApiController : ControllerBase
+public class RealEstateController : ControllerBase
{
- private readonly HttpClient _httpClient;
-
- public RealEstateApiController(HttpClient httpClient)
+ // Step 1: Find image links without downloading
+ [HttpPost("findImages")]
+ public async Task FindImages([FromBody] UrlRequest request)
{
- _httpClient = httpClient;
- }
-
- [HttpPost("download")]
- public async Task DownloadWebsite([FromBody] WebsiteRequest request)
- {
- if (string.IsNullOrWhiteSpace(request.Url))
+ if (string.IsNullOrEmpty(request.Url))
{
- return BadRequest("URL cannot be empty.");
+ return BadRequest("URL is required.");
}
try
{
- var response = await _httpClient.GetAsync(request.Url);
- response.EnsureSuccessStatusCode();
- var content = await response.Content.ReadAsStringAsync();
+ var imageLinks = await FetchImageLinksFromWebsiteAsync(request.Url);
+ return Ok(new { images = imageLinks });
+ }
+ catch (Exception ex)
+ {
+ return StatusCode(500, $"Error: {ex.Message}");
+ }
+ }
- // Optional: Save content to a file
- System.IO.File.WriteAllText("DownloadedWebsite.html", content);
+ // Step 2: Download images when user chooses to do so
+ [HttpPost("download")]
+ public async Task DownloadWebsite([FromBody] UrlRequest request)
+ {
+ if (string.IsNullOrEmpty(request.Url))
+ {
+ return BadRequest("URL is required.");
+ }
- return Ok("Website downloaded successfully.");
+ try
+ {
+ var images = await FetchImagesFromWebsiteAsync(request.Url);
+
+ // Log the fetched images
+ Console.WriteLine("Fetched images: " + string.Join(", ", images));
+
+ return Ok(new { images });
+ }
+ catch (Exception ex)
+ {
+ return StatusCode(500, $"Error: {ex.Message}");
+ }
+ }
+
+
+ // Fetch just the image links
+ private async Task> FetchImageLinksFromWebsiteAsync(string url)
+ {
+ var imageLinks = new List();
+ var httpClient = new HttpClient();
+
+ // Set User-Agent to imitate a browser request
+ httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3");
+
+ try
+ {
+ // Send the GET request with headers
+ var response = await httpClient.GetStringAsync(url);
+
+ // Load the HTML into HtmlAgilityPack
+ var htmlDocument = new HtmlDocument();
+ htmlDocument.LoadHtml(response);
+
+ // Select all
elements containing the images you want
+ var liNodes = htmlDocument.DocumentNode.SelectNodes("//li[contains(@class, 'flex items-center justify-center')]");
+
+ if (liNodes != null)
+ {
+ foreach (var liNode in liNodes)
+ {
+ // Find the tag within the
node
+ var imgNode = liNode.SelectSingleNode(".//img[contains(@class, 'absolute top-0 left-0 w-full h-full')]");
+
+ if (imgNode != null)
+ {
+ var imgSrc = imgNode.GetAttributeValue("src", "");
+
+ if (!string.IsNullOrEmpty(imgSrc))
+ {
+ // Ensure absolute URL if necessary
+ if (!Uri.IsWellFormedUriString(imgSrc, UriKind.Absolute))
+ {
+ var baseUri = new Uri(url);
+ imgSrc = new Uri(baseUri, imgSrc).ToString();
+ }
+
+ imageLinks.Add(imgSrc);
+ }
+ }
+ }
+ }
}
catch (HttpRequestException ex)
{
- return StatusCode(500, $"Error downloading website: {ex.Message}");
+ // Catch any network-related exceptions (403, 404, etc.)
+ Console.WriteLine($"Error: {ex.Message}");
+ throw new Exception($"Error fetching images: {ex.Message}");
}
+
+ return imageLinks;
}
+
+
+
+ // Fetch images and download
+ private async Task> FetchImagesFromWebsiteAsync(string url)
+ {
+ var images = new List();
+ var httpClient = new HttpClient();
+ var response = await httpClient.GetStringAsync(url);
+
+ // Load the HTML into HtmlAgilityPack
+ var htmlDocument = new HtmlDocument();
+ htmlDocument.LoadHtml(response);
+
+ // Select all elements with the specified class
+ var imgNodes = htmlDocument.DocumentNode.SelectNodes("//li//img");
+
+ if (imgNodes != null)
+ {
+ foreach (var imgNode in imgNodes)
+ {
+ var imgSrc = imgNode.GetAttributeValue("src", "");
+ if (!string.IsNullOrEmpty(imgSrc))
+ {
+ // Ensure absolute URL if necessary
+ if (!Uri.IsWellFormedUriString(imgSrc, UriKind.Absolute))
+ {
+ var baseUri = new Uri(url);
+ imgSrc = new Uri(baseUri, imgSrc).ToString();
+ }
+ images.Add(imgSrc);
+ }
+ }
+ }
+
+ return images;
+ }
+
}
-public class WebsiteRequest
+public class UrlRequest
{
public string Url { get; set; }
}
diff --git a/Aberwyn/Data/BudgetService.cs b/Aberwyn/Data/BudgetService.cs
index 4677935..e762cfd 100644
--- a/Aberwyn/Data/BudgetService.cs
+++ b/Aberwyn/Data/BudgetService.cs
@@ -1,23 +1,31 @@
using MySql.Data.MySqlClient;
using System.Collections.Generic;
using Aberwyn.Models;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting; // Add this namespace
namespace Aberwyn.Data
{
public class BudgetService
{
private readonly IConfiguration _configuration;
+ private readonly IHostEnvironment _env; // Add this field
- public BudgetService(IConfiguration configuration)
+ public BudgetService(IConfiguration configuration, IHostEnvironment env) // Update constructor
{
_configuration = configuration;
+ _env = env; // Initialize the environment field
}
public MySqlConnection GetConnection()
{
- var connectionString = _configuration.GetConnectionString("DefaultConnection");
+ var connectionString = _env.IsDevelopment() // Use the injected environment variable
+ ? _configuration.GetConnectionString("DefaultConnection")
+ : _configuration.GetConnectionString("ProductionConnection");
+
return new MySqlConnection(connectionString);
}
+
public bool UpdateBudgetItem(BudgetItem item)
{
using (var connection = GetConnection())
@@ -25,9 +33,9 @@ namespace Aberwyn.Data
connection.Open();
string query = @"
- UPDATE tblBudgetItems
- SET Name = @name, Amount = @amount
- WHERE idtblBudgetItems = @id";
+ UPDATE tblBudgetItems
+ SET Name = @name, Amount = @amount
+ WHERE idtblBudgetItems = @id";
using (var cmd = new MySqlCommand(query, connection))
{
@@ -48,17 +56,17 @@ namespace Aberwyn.Data
connection.Open();
string query = @"
- SELECT
- b.idtblBudgetItems AS id,
- b.Name AS item_name,
- b.Amount AS amount,
- c1.Name AS category,
- b.Month,
- b.Year,
- b.Description AS description
- FROM tblBudgetItems b
- LEFT JOIN tblCategories c1 ON b.Category = c1.idtblCategories
- WHERE b.Month = @month AND b.Year = @year";
+ SELECT
+ b.idtblBudgetItems AS id,
+ b.Name AS item_name,
+ b.Amount AS amount,
+ c1.Name AS category,
+ b.Month,
+ b.Year,
+ b.Description AS description
+ FROM tblBudgetItems b
+ LEFT JOIN tblCategories c1 ON b.Category = c1.idtblCategories
+ WHERE b.Month = @month AND b.Year = @year";
using (var cmd = new MySqlCommand(query, connection))
{
@@ -96,8 +104,8 @@ namespace Aberwyn.Data
connection.Open();
string query = @"
- INSERT INTO tblBudgetItems (Name, Amount, Category, Month, Year)
- VALUES (@name, @amount, @category, @month, @year)";
+ INSERT INTO tblBudgetItems (Name, Amount, Category, Month, Year)
+ VALUES (@name, @amount, @category, @month, @year)";
using (var cmd = new MySqlCommand(query, connection))
{
@@ -111,7 +119,6 @@ namespace Aberwyn.Data
}
}
-
// New method to fetch all categories
public List GetCategories()
{
@@ -138,5 +145,4 @@ namespace Aberwyn.Data
return categories;
}
}
-
}
diff --git a/Aberwyn/Data/MenuService.cs b/Aberwyn/Data/MenuService.cs
new file mode 100644
index 0000000..dc0ad90
--- /dev/null
+++ b/Aberwyn/Data/MenuService.cs
@@ -0,0 +1,193 @@
+using MySql.Data.MySqlClient;
+using System.Collections.Generic;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
+using Aberwyn.Models;
+
+namespace Aberwyn.Data
+{
+ public class MenuService
+ {
+ private readonly IConfiguration _configuration;
+ private readonly IHostEnvironment _env;
+
+ public MenuService(IConfiguration configuration, IHostEnvironment env)
+ {
+ _configuration = configuration;
+ _env = env;
+ }
+
+ private MySqlConnection GetConnection()
+ {
+ var connectionString = _env.IsDevelopment()
+ ? _configuration.GetConnectionString("DefaultConnection")
+ : _configuration.GetConnectionString("ProductionConnection");
+
+ return new MySqlConnection(connectionString);
+ }
+
+ public List GetWeeklyMenu(int weekNumber, int year)
+ {
+ var weeklyMenu = new List();
+ using (var connection = GetConnection())
+ {
+ connection.Open();
+ string query = @"
+ SELECT wm.Id, wm.DayOfWeek, wm.DinnerMealId, wm.LunchMealId, wm.WeekNumber, wm.Year,
+ dm.Name AS DinnerMealName, lm.Name AS LunchMealName
+ FROM WeeklyMenu wm
+ LEFT JOIN Meals dm ON wm.DinnerMealId = dm.Id
+ LEFT JOIN Meals lm ON wm.LunchMealId = lm.Id
+ WHERE wm.WeekNumber = @weekNumber AND wm.Year = @year";
+
+ using (var cmd = new MySqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("@weekNumber", weekNumber);
+ cmd.Parameters.AddWithValue("@year", year);
+
+ using (var reader = cmd.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ weeklyMenu.Add(new WeeklyMenu
+ {
+ Id = reader.GetInt32("Id"),
+ DayOfWeek = reader.GetInt32("DayOfWeek"),
+ DinnerMealId = reader.IsDBNull(reader.GetOrdinal("DinnerMealId")) ? (int?)null : reader.GetInt32("DinnerMealId"),
+ LunchMealId = reader.IsDBNull(reader.GetOrdinal("LunchMealId")) ? (int?)null : reader.GetInt32("LunchMealId"),
+ WeekNumber = reader.GetInt32("WeekNumber"),
+ Year = reader.GetInt32("Year"),
+ DinnerMealName = reader.IsDBNull(reader.GetOrdinal("DinnerMealName")) ? null : reader.GetString("DinnerMealName"),
+ LunchMealName = reader.IsDBNull(reader.GetOrdinal("LunchMealName")) ? null : reader.GetString("LunchMealName"),
+
+ });
+ }
+ }
+ }
+ }
+ return weeklyMenu;
+ }
+
+ public List GetMeals()
+ {
+ var meals = new List();
+ using (var connection = GetConnection())
+ {
+ connection.Open();
+ string query = "SELECT Id, Name FROM Meals";
+ using (var cmd = new MySqlCommand(query, connection))
+ {
+ using (var reader = cmd.ExecuteReader())
+ {
+ while (reader.Read())
+ {
+ meals.Add(new Meal
+ {
+ Id = reader.GetInt32("Id"),
+ Name = reader.GetString("Name")
+ });
+ }
+ }
+ }
+ }
+ return meals;
+ }
+
+ public void UpdateWeeklyMenu(MenuViewModel menuData)
+ {
+ if (menuData == null || menuData.WeeklyMenus == null)
+ throw new ArgumentNullException(nameof(menuData), "Menu data or weekly menus cannot be null.");
+
+ using (var connection = GetConnection())
+ {
+ connection.Open();
+ using (var transaction = connection.BeginTransaction())
+ {
+ try
+ {
+ // Loop over each WeeklyMenu in the WeeklyMenus list
+ foreach (var weeklyMenu in menuData.WeeklyMenus)
+ {
+ int dayOfWeek = weeklyMenu.DayOfWeek;
+ var menu = weeklyMenu;
+
+ // SQL query to update the existing records
+ string query = @"
+ UPDATE WeeklyMenu
+ SET
+ DinnerMealId = @dinnerMealId,
+ LunchMealId = @lunchMealId,
+ Cook = @cook
+ WHERE DayOfWeek = @dayOfWeek
+ AND WeekNumber = @weekNumber
+ AND Year = @year;";
+
+ using (var cmd = new MySqlCommand(query, connection, transaction))
+ {
+ cmd.Parameters.AddWithValue("@dayOfWeek", dayOfWeek);
+ cmd.Parameters.AddWithValue("@dinnerMealId", menu.DinnerMealId ?? (object)DBNull.Value);
+ cmd.Parameters.AddWithValue("@lunchMealId", menu.LunchMealId ?? (object)DBNull.Value);
+ cmd.Parameters.AddWithValue("@weekNumber", menu.WeekNumber);
+ cmd.Parameters.AddWithValue("@year", menu.Year);
+ cmd.Parameters.AddWithValue("@cook", menu.Cook ?? (object)DBNull.Value);
+
+ cmd.ExecuteNonQuery();
+ }
+ }
+
+ transaction.Commit();
+ }
+ catch (Exception ex)
+ {
+ transaction.Rollback();
+ Console.WriteLine($"Error updating weekly menu: {ex.Message}");
+ throw;
+ }
+ }
+ }
+ }
+
+ public int AddMeal(Meal meal)
+ {
+ using (var connection = GetConnection())
+ {
+ connection.Open();
+ string query = @"
+ INSERT INTO Meals (Name, Description, ProteinType, CarbType, RecipeUrl, CreatedAt)
+ VALUES (@name, @description, @proteinType, @carbType, @recipeUrl, NOW());
+ SELECT LAST_INSERT_ID();";
+
+ using (var cmd = new MySqlCommand(query, connection))
+ {
+ cmd.Parameters.AddWithValue("@name", meal.Name);
+ cmd.Parameters.AddWithValue("@description", string.IsNullOrWhiteSpace(meal.Description) ? (object)DBNull.Value : meal.Description);
+ cmd.Parameters.AddWithValue("@proteinType", string.IsNullOrWhiteSpace(meal.ProteinType) ? (object)DBNull.Value : meal.ProteinType);
+ cmd.Parameters.AddWithValue("@carbType", string.IsNullOrWhiteSpace(meal.CarbType) ? (object)DBNull.Value : meal.CarbType);
+ cmd.Parameters.AddWithValue("@recipeUrl", string.IsNullOrWhiteSpace(meal.RecipeUrl) ? (object)DBNull.Value : meal.RecipeUrl);
+
+ var result = cmd.ExecuteScalar();
+ return result != null ? Convert.ToInt32(result) : 0;
+ }
+ }
+ }
+
+
+
+ private int GetDayOfWeek(string day)
+ {
+ return day switch
+ {
+ "Monday" => 1,
+ "Tuesday" => 2,
+ "Wednesday" => 3,
+ "Thursday" => 4,
+ "Friday" => 5,
+ "Saturday" => 6,
+ "Sunday" => 7,
+ _ => throw new System.ArgumentException("Invalid day name")
+ };
+ }
+ }
+}
+
+// Models for Meals and WeeklyMenu
diff --git a/Aberwyn/Dockerfile b/Aberwyn/Dockerfile
index c67a604..766d99a 100644
--- a/Aberwyn/Dockerfile
+++ b/Aberwyn/Dockerfile
@@ -1,27 +1,33 @@
# Base image for runtime
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
-EXPOSE 80
-EXPOSE 443
+
+# Leave the ports exposed to allow Unraid to configure them
+EXPOSE 80 443
# Image for building the project
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
# Copy the .csproj and restore dependencies
-COPY ["Aberwyn.csproj", "./"]
-RUN dotnet restore "Aberwyn.csproj"
+COPY Aberwyn.csproj ./
+RUN dotnet restore
# Copy everything else and build the app
COPY . .
-RUN dotnet build "Aberwyn.csproj" -c Release -o /app/build
+RUN dotnet build Aberwyn.csproj -c Release -o /app/build
# Publish the app to the /app/publish folder
FROM build AS publish
-RUN dotnet publish "Aberwyn.csproj" -c Release -o /app/publish
+RUN dotnet publish Aberwyn.csproj -c Release -o /app/publish
# Use the base runtime image to run the app
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
+
+# Use environment variable for ports to allow flexibility
+ENV ASPNETCORE_URLS="http://+:80"
+
+# Set entry point to start the application
ENTRYPOINT ["dotnet", "Aberwyn.dll"]
diff --git a/Aberwyn/Models/BudgetItem.cs b/Aberwyn/Models/BudgetItem.cs
index ac55af8..34d50dc 100644
--- a/Aberwyn/Models/BudgetItem.cs
+++ b/Aberwyn/Models/BudgetItem.cs
@@ -8,12 +8,15 @@
public class BudgetItem
{
public int ID { get; set; }
- public string Name { get; set; }
+
+ // Option 1: Initialize with default values
+ public string Name { get; set; } = string.Empty; // Initialize to an empty string
public decimal Amount { get; set; }
- public string Category { get; set; }
- public string SubCategory { get; set; }
+ public string Category { get; set; } = string.Empty; // Initialize to an empty string
+ public string SubCategory { get; set; } = string.Empty; // Initialize to an empty string
public int Month { get; set; }
public int Year { get; set; }
- public string Description { get; set; }
+ public string Description { get; set; } = string.Empty; // Initialize to an empty string
}
+
}
diff --git a/Aberwyn/Models/MenuViewModel.cs b/Aberwyn/Models/MenuViewModel.cs
new file mode 100644
index 0000000..c911363
--- /dev/null
+++ b/Aberwyn/Models/MenuViewModel.cs
@@ -0,0 +1,38 @@
+using System.Collections.Generic;
+using Aberwyn.Data;
+using Aberwyn.Models;
+
+namespace Aberwyn.Models
+{
+ public class MenuViewModel
+ {
+ public List Meals { get; set; } // List of all available meals
+ public List WeeklyMenus { get; set; } // List of weekly menu entries
+ public int WeekNumber { get; set; } // Week number for the menu
+ public int Year { get; set; } // Year for the menu
+ }
+ public class WeeklyMenu
+ {
+ public int Id { get; set; }
+ public int DayOfWeek { get; set; }
+ public int? DinnerMealId { get; set; }
+ public int? LunchMealId { get; set; }
+ public string Cook { get; set; }
+ public int WeekNumber { get; set; }
+ public int Year { get; set; }
+ public string DinnerMealName { get; set; }
+ public string LunchMealName { get; set; }
+ }
+
+ public class Meal
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public string Description { get; set; }
+ public string ProteinType { get; set; }
+ public string CarbType { get; set; }
+ public string RecipeUrl { get; set; }
+ public DateTime CreatedAt { get; set; }
+ }
+}
+
diff --git a/Aberwyn/Program.cs b/Aberwyn/Program.cs
index 6ffd945..b9e26af 100644
--- a/Aberwyn/Program.cs
+++ b/Aberwyn/Program.cs
@@ -14,8 +14,11 @@ builder.Services.AddHttpClient(); // Register HttpClient
builder.Services.AddDbContext(options =>
options.UseMySQL(builder.Configuration.GetConnectionString("BudgetDb")));
+
// Register your BudgetService with a scoped lifetime
builder.Services.AddScoped();
+builder.Services.AddScoped();
+
var app = builder.Build();
@@ -26,7 +29,7 @@ if (!app.Environment.IsDevelopment())
app.UseHsts();
}
-app.UseHttpsRedirection();
+//app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
diff --git a/Aberwyn/ViewComponents/RightSidebarViewComponents.cs b/Aberwyn/ViewComponents/RightSidebarViewComponents.cs
new file mode 100644
index 0000000..f2000a4
--- /dev/null
+++ b/Aberwyn/ViewComponents/RightSidebarViewComponents.cs
@@ -0,0 +1,31 @@
+using Aberwyn.Data;
+using Aberwyn.Models;
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace Aberwyn.ViewComponents
+{
+ public class RightSidebarViewComponent : ViewComponent
+ {
+ private readonly BudgetService _budgetService;
+
+ public RightSidebarViewComponent(BudgetService budgetService)
+ {
+ _budgetService = budgetService;
+ }
+
+ public async Task InvokeAsync()
+ {
+ // Get the current month and year
+ int currentMonth = DateTime.Now.Month;
+ int currentYear = DateTime.Now.Year;
+
+ // Fetch the budget items using the service
+ var budgetItems = _budgetService.GetBudgetItems(currentMonth, currentYear);
+
+ return View(budgetItems);
+ }
+ }
+}
diff --git a/Aberwyn/Views/Home/Budget.cshtml b/Aberwyn/Views/Home/Budget.cshtml
index 84ed2b4..e781fc4 100644
--- a/Aberwyn/Views/Home/Budget.cshtml
+++ b/Aberwyn/Views/Home/Budget.cshtml
@@ -1,7 +1,7 @@
@model Aberwyn.Models.BudgetModel
@{
- Layout = "_Layout"; // Assuming you have a layout file named _Layout.cshtml
+ Layout = "_Layout";
}
@@ -10,32 +10,29 @@
Budget Overview
-
+
+