Balberova D.N. LabWork03 #4

Closed
august wants to merge 7 commits from LabWork03 into LabWork02
8 changed files with 20 additions and 20 deletions
Showing only changes of commit eaafd9b703 - Show all commits

View File

@ -12,7 +12,7 @@ namespace SushiBarDatabaseImplement.Implements
public List<SushiViewModel> GetFullList()
{
using var context = new SushiBarDatabase();
return context.SushiList
return context.ListSushi
.Include(x => x.Ingredients)
.ThenInclude(x => x.Ingredient)
.ToList()
@ -27,7 +27,7 @@ namespace SushiBarDatabaseImplement.Implements
return new();
}
using var context = new SushiBarDatabase();
return context.SushiList
return context.ListSushi
.Include(x => x.Ingredients)
.ThenInclude(x => x.Ingredient)
.Where(x => x.SushiName.Contains(model.SushiName))
@ -43,7 +43,7 @@ namespace SushiBarDatabaseImplement.Implements
return null;
}
using var context = new SushiBarDatabase();
return context.SushiList
return context.ListSushi
.Include(x => x.Ingredients)
.ThenInclude(x => x.Ingredient)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SushiName) && x.SushiName == model.SushiName) ||
@ -59,7 +59,7 @@ namespace SushiBarDatabaseImplement.Implements
{
return null;
}
context.SushiList.Add(newSushi);
context.ListSushi.Add(newSushi);
context.SaveChanges();
return newSushi.GetViewModel;
}
@ -70,7 +70,7 @@ namespace SushiBarDatabaseImplement.Implements
using var transaction = context.Database.BeginTransaction();
try
{
var sushi = context.SushiList.FirstOrDefault(rec => rec.Id == model.Id);
var sushi = context.ListSushi.FirstOrDefault(rec => rec.Id == model.Id);
if (sushi == null)
{
return null;
@ -91,13 +91,13 @@ namespace SushiBarDatabaseImplement.Implements
public SushiViewModel? Delete(SushiBindingModel model)
{
using var context = new SushiBarDatabase();
var element = context.SushiList
var element = context.ListSushi
.Include(x => x.Ingredients)
.Include(x => x.Orders)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.SushiList.Remove(element);
context.ListSushi.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}

View File

@ -93,7 +93,7 @@ namespace SushiBarDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("SushiList");
b.ToTable("ListSushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiIngredient", b =>

View File

@ -44,7 +44,7 @@ namespace SushiBarDatabaseImplement.Migrations
});
migrationBuilder.CreateTable(
name: "SushiList",
name: "ListSushi",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
@ -54,7 +54,7 @@ namespace SushiBarDatabaseImplement.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_SushiList", x => x.Id);
table.PrimaryKey("PK_ListSushi", x => x.Id);
});
migrationBuilder.CreateTable(
@ -77,9 +77,9 @@ namespace SushiBarDatabaseImplement.Migrations
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_SushiIngredients_SushiList_SushiId",
name: "FK_SushiIngredients_ListSushi_SushiId",
column: x => x.SushiId,
principalTable: "SushiList",
principalTable: "ListSushi",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
@ -108,7 +108,7 @@ namespace SushiBarDatabaseImplement.Migrations
name: "Ingredients");
migrationBuilder.DropTable(
name: "SushiList");
name: "ListSushi");
}
}
}

View File

@ -95,7 +95,7 @@ namespace SushiBarDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("SushiList");
b.ToTable("ListSushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiIngredient", b =>

View File

@ -16,10 +16,10 @@ namespace SushiBarDatabaseImplement.Migrations
column: "SushiId");
migrationBuilder.AddForeignKey(
name: "FK_Orders_SushiList_SushiId",
name: "FK_Orders_ListSushi_SushiId",
table: "Orders",
column: "SushiId",
principalTable: "SushiList",
principalTable: "ListSushi",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
@ -28,7 +28,7 @@ namespace SushiBarDatabaseImplement.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Orders_SushiList_SushiId",
name: "FK_Orders_ListSushi_SushiId",
table: "Orders");
migrationBuilder.DropIndex(

View File

@ -88,7 +88,7 @@ namespace SushiBarDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("SushiList");
b.ToTable("ListSushi");
});
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiIngredient", b =>

View File

@ -81,7 +81,7 @@ namespace SushiBarDatabaseImplement.Models
}
context.SaveChanges();
}
var sushi = context.SushiList.First(x => x.Id == Id);
var sushi = context.ListSushi.First(x => x.Id == Id);
foreach (var si in model.SushiIngredients)
{
context.SushiIngredients.Add(new SushiIngredient

View File

@ -16,7 +16,7 @@ namespace SushiBarDatabaseImplement
public virtual DbSet<Ingredient> Ingredients { set; get; }
public virtual DbSet<Sushi> SushiList { set; get; }
public virtual DbSet<Sushi> ListSushi { set; get; }
public virtual DbSet<SushiIngredient> SushiIngredients { set; get; }