Fixed errors SA1516

This commit is contained in:
Francesco D'Amico
2025-03-24 09:27:13 +01:00
parent 02533e9bfb
commit 41f41ce3fb
14 changed files with 83 additions and 11 deletions
@@ -1,5 +1,5 @@
namespace Francesco.Recipes.World.Data namespace Francesco.Recipes.World.Data;
{
using Francesco.Recipes.World.Models.BackendModels; using Francesco.Recipes.World.Models.BackendModels;
using Francesco.Recipes.World.Models.BackendModels.Category; using Francesco.Recipes.World.Models.BackendModels.Category;
using Francesco.Recipes.World.Models.BackendModels.Favorit; using Francesco.Recipes.World.Models.BackendModels.Favorit;
@@ -21,15 +21,25 @@
} }
public DbSet<Category> Categories => Set<Category>(); public DbSet<Category> Categories => Set<Category>();
public DbSet<Ingredient> Ingredients => Set<Ingredient>(); public DbSet<Ingredient> Ingredients => Set<Ingredient>();
public DbSet<Instruction> Instructions => Set<Instruction>(); public DbSet<Instruction> Instructions => Set<Instruction>();
public DbSet<Recipe> Recipes => Set<Recipe>(); public DbSet<Recipe> Recipes => Set<Recipe>();
public DbSet<RecipeIngredient> RecipeIngredients => Set<RecipeIngredient>(); public DbSet<RecipeIngredient> RecipeIngredients => Set<RecipeIngredient>();
public DbSet<Unit> Units => Set<Unit>(); public DbSet<Unit> Units => Set<Unit>();
public DbSet<Favorit> Favorits => Set<Favorit>(); public DbSet<Favorit> Favorits => Set<Favorit>();
public DbSet<IngredientsShoppingList> IngredientsShoppingLists => Set<IngredientsShoppingList>(); public DbSet<IngredientsShoppingList> IngredientsShoppingLists => Set<IngredientsShoppingList>();
public DbSet<ShoppingList> ShoppingLists => Set<ShoppingList>(); public DbSet<ShoppingList> ShoppingLists => Set<ShoppingList>();
public DbSet<MediaFile> MediaFiles => Set<MediaFile>(); public DbSet<MediaFile> MediaFiles => Set<MediaFile>();
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default) public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{ {
foreach (var entry in ChangeTracker.Entries()) foreach (var entry in ChangeTracker.Entries())
@@ -104,4 +114,3 @@
]; ];
} }
} }
}
@@ -1,10 +1,9 @@
// <auto-generated /> // <auto-generated />
using System;
using Francesco.Recipes.World.Data; using Francesco.Recipes.World.Data;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable #nullable disable
@@ -1,10 +1,13 @@
namespace Francesco.Recipes.World.Models.BackendModels.Category namespace Francesco.Recipes.World.Models.BackendModels.Category
{ {
using Francesco.Recipes.World.Models.BackendModels.Recipe; using Francesco.Recipes.World.Models.BackendModels.Recipe;
public class Category public class Category
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public virtual ICollection<Recipe> Recipes { get; set; } = new List<Recipe>(); public virtual ICollection<Recipe> Recipes { get; set; } = new List<Recipe>();
} }
} }
@@ -5,7 +5,9 @@
public class Favorit public class Favorit
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime CreatedAt { get; set; } public DateTime CreatedAt { get; set; }
public virtual ICollection<Recipe> Recipe { get; set; } = new List<Recipe>(); public virtual ICollection<Recipe> Recipe { get; set; } = new List<Recipe>();
} }
} }
@@ -6,8 +6,11 @@
public class Ingredient public class Ingredient
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public virtual ICollection<RecipeIngredient> RecipeIngredients { get; set; } = new List<RecipeIngredient>(); public virtual ICollection<RecipeIngredient> RecipeIngredients { get; set; } = new List<RecipeIngredient>();
public virtual ICollection<IngredientsShoppingList> IngredientShoppingLists { get; set; } = new List<IngredientsShoppingList>(); public virtual ICollection<IngredientsShoppingList> IngredientShoppingLists { get; set; } = new List<IngredientsShoppingList>();
} }
} }
@@ -6,7 +6,9 @@
public class IngredientsShoppingList public class IngredientsShoppingList
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public ShoppingList Shoppinglist { get; set; } = new (); public ShoppingList Shoppinglist { get; set; } = new ();
public Ingredient Ingredient { get; set; } = new (); public Ingredient Ingredient { get; set; } = new ();
} }
} }
@@ -2,12 +2,17 @@
{ {
using Francesco.Recipes.World.Models.BackendModels.MediaFile; using Francesco.Recipes.World.Models.BackendModels.MediaFile;
using Francesco.Recipes.World.Models.BackendModels.Recipe; using Francesco.Recipes.World.Models.BackendModels.Recipe;
public class Instruction public class Instruction
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Description { get; set; } = string.Empty; public string Description { get; set; } = string.Empty;
public int Number { get; set; } public int Number { get; set; }
public virtual Recipe Recipe { get; set; } = new (); public virtual Recipe Recipe { get; set; } = new ();
public virtual ICollection<MediaFile> MediaFiles { get; set; } = new List<MediaFile>(); public virtual ICollection<MediaFile> MediaFiles { get; set; } = new List<MediaFile>();
} }
} }
@@ -2,6 +2,7 @@
{ {
using Francesco.Recipes.World.Models.BackendModels.Instruction; using Francesco.Recipes.World.Models.BackendModels.Instruction;
using Francesco.Recipes.World.Models.BackendModels.Recipe; using Francesco.Recipes.World.Models.BackendModels.Recipe;
public class MediaFile public class MediaFile
{ {
public Guid Id { get; set; } = Guid.NewGuid(); public Guid Id { get; set; } = Guid.NewGuid();
@@ -11,7 +12,9 @@
public string? MimeType { get; set; } public string? MimeType { get; set; }
public byte[]? Data { get; set; } public byte[]? Data { get; set; }
public virtual Recipe? Recipe { get; set; } = new (); public virtual Recipe? Recipe { get; set; } = new ();
public virtual Instruction Instruction { get; set; } = new (); public virtual Instruction Instruction { get; set; } = new ();
} }
} }
@@ -3,9 +3,13 @@
public enum Difficulty public enum Difficulty
{ {
VeryEasy = 1, VeryEasy = 1,
Easy = 2, Easy = 2,
Medium = 3, Medium = 3,
Hard = 4, Hard = 4,
Expert = 5, Expert = 5,
} }
} }
@@ -8,17 +8,30 @@ using Francesco.Recipes.World.Models.BackendModels.RecipeIngredient;
public class Recipe : ITimeStampedEntity public class Recipe : ITimeStampedEntity
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public string? Description { get; set; } public string? Description { get; set; }
public Difficulty Difficulty { get; set; } public Difficulty Difficulty { get; set; }
public int Servings { get; set; } public int Servings { get; set; }
public TimeSpan PreparationTime { get; set; } public TimeSpan PreparationTime { get; set; }
public TimeSpan CookingTime { get; set; } public TimeSpan CookingTime { get; set; }
public bool IsFavorite { get; set; } public bool IsFavorite { get; set; }
public DateTime CreatedAt { get; set; } public DateTime CreatedAt { get; set; }
public DateTime? ModifiedAt { get; set; } public DateTime? ModifiedAt { get; set; }
public virtual ICollection<RecipeIngredient> RecipeIngredients { get; set; } = new List<RecipeIngredient>(); public virtual ICollection<RecipeIngredient> RecipeIngredients { get; set; } = new List<RecipeIngredient>();
public virtual ICollection<Instruction> Instructions { get; set; } = new List<Instruction>(); public virtual ICollection<Instruction> Instructions { get; set; } = new List<Instruction>();
public virtual ICollection<MediaFile> MediaFiles { get; set; } = new List<MediaFile>(); public virtual ICollection<MediaFile> MediaFiles { get; set; } = new List<MediaFile>();
public virtual Favorit Favorit { get; set; } = new (); public virtual Favorit Favorit { get; set; } = new ();
} }
@@ -3,12 +3,17 @@
using Francesco.Recipes.World.Models.BackendModels.Ingredient; using Francesco.Recipes.World.Models.BackendModels.Ingredient;
using Francesco.Recipes.World.Models.BackendModels.Recipe; using Francesco.Recipes.World.Models.BackendModels.Recipe;
using Francesco.Recipes.World.Models.BackendModels.Unit; using Francesco.Recipes.World.Models.BackendModels.Unit;
public class RecipeIngredient public class RecipeIngredient
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public virtual Recipe Recipe { get; set; } = new (); public virtual Recipe Recipe { get; set; } = new ();
public virtual Ingredient Ingredient { get; set; } = new (); public virtual Ingredient Ingredient { get; set; } = new ();
public virtual Unit Unit { get; set; } = new (); public virtual Unit Unit { get; set; } = new ();
public int Quantity { get; set; } public int Quantity { get; set; }
} }
} }
@@ -5,8 +5,11 @@
public class ShoppingList : ITimeStampedEntity public class ShoppingList : ITimeStampedEntity
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime CreatedAt { get; set; } public DateTime CreatedAt { get; set; }
public DateTime? ModifiedAt { get; set; } public DateTime? ModifiedAt { get; set; }
public virtual ICollection<IngredientsShoppingList> IngredientsShoppingLists { get; set; } = new List<IngredientsShoppingList>(); public virtual ICollection<IngredientsShoppingList> IngredientsShoppingLists { get; set; } = new List<IngredientsShoppingList>();
} }
} }
@@ -1,11 +1,15 @@
namespace Francesco.Recipes.World.Models.BackendModels.Unit; namespace Francesco.Recipes.World.Models.BackendModels.Unit
{
using Francesco.Recipes.World.Models.BackendModels.RecipeIngredient; using Francesco.Recipes.World.Models.BackendModels.RecipeIngredient;
public class Unit public class Unit
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public string Symbol { get; set; } = string.Empty; public string Symbol { get; set; } = string.Empty;
public virtual ICollection<RecipeIngredient> RecipeIngredient { get; set; } = new List<RecipeIngredient>(); public virtual ICollection<RecipeIngredient> RecipeIngredient { get; set; } = new List<RecipeIngredient>();
} }
}
+20 -3
View File
@@ -1,15 +1,22 @@
using Francesco.Recipes.World.Data; using Francesco.Recipes.World.Data;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Serilog;
using Francesco.Recipes.World.Repositories;
using FrancescoRecipesWorld.Repositories;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
var services = builder.Services; var services = builder.Services;
var configuration = builder.Configuration; var configuration = builder.Configuration;
var connectionString = builder.Configuration.GetConnectionString("FrancescosRecipesWorldDbContextConnection") var connectionString = builder.Configuration.GetConnectionString("FrancescosRecipesWorldDbContextConnection")
?? throw new InvalidOperationException("Connection string 'FrancescosRecipesWorldDbContextConnection' not found."); ?? throw new InvalidOperationException("Connection string 'FrancescosRecipesWorldDbContextConnection' not found.");
services.AddDbContext<FrancescosRecipesWorldDbContext>(options => services.AddDbContext<FrancescosRecipesWorldDbContext>(options =>
options.UseSqlServer(connectionString)); options.UseSqlServer(connectionString));
@@ -19,6 +26,14 @@ services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfi
// Add services to the container. // Add services to the container.
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
builder.Services.AddScoped<IRecipeRepository, RecipeRepository>();
builder.Services.AddScoped<IIngredientRepository, IngredientRepository>();
builder.Services.AddScoped<IUnitRepository, UnitRepository>();
builder.Services.AddScoped<ICategoryRepository, CategoryRepository>();
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
@@ -31,9 +46,11 @@ if (!app.Environment.IsDevelopment())
} }
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseAuthentication(); app.UseAuthentication();
app.UseAuthorization(); app.UseAuthorization();