ПИбд-22 Боровков М В 3 лабораторная работа #3
@ -14,8 +14,8 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new SushiBarDatabase();
|
using var context = new SushiBarDatabase();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.ToList()
|
.Include(x => x.Sushi)
|
||||||
.Select(x => x.GetViewModel(context))
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
@ -36,7 +36,8 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
using var context = new SushiBarDatabase();
|
using var context = new SushiBarDatabase();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel(context);
|
.Include (x => x.Sushi)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -48,7 +49,7 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
context.Orders.Add(newOrder);
|
context.Orders.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return newOrder.GetViewModel(context);
|
return newOrder.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -65,7 +66,7 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
order.Update(model);
|
order.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
return order.GetViewModel(context);
|
return order.GetViewModel;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -82,7 +83,7 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return element.GetViewModel(context);
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1,169 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
||||||
using SushiBarDatabaseImplement;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace SushiBarDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(SushiBarDatabase))]
|
|
||||||
[Migration("20240313064708_InitialCreate3")]
|
|
||||||
partial class InitialCreate3
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "7.0.16")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("ComponentName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<double>("Cost")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Components");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<int>("Status")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<double>("Sum")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.Property<int>("SushiId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("SushiId");
|
|
||||||
|
|
||||||
b.ToTable("Orders");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<double>("Price")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.Property<string>("SushiName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Sushis");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("ComponentId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("SushiId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ComponentId");
|
|
||||||
|
|
||||||
b.HasIndex("SushiId");
|
|
||||||
|
|
||||||
b.ToTable("SushiComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", null)
|
|
||||||
.WithMany("Orders")
|
|
||||||
.HasForeignKey("SushiId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Component", "Component")
|
|
||||||
.WithMany("SushiComponents")
|
|
||||||
.HasForeignKey("ComponentId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
|
|
||||||
.WithMany("Components")
|
|
||||||
.HasForeignKey("SushiId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Component");
|
|
||||||
|
|
||||||
b.Navigation("Sushi");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("SushiComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Sushi", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Components");
|
|
||||||
|
|
||||||
b.Navigation("Orders");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace SushiBarDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class InitialCreate3 : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,8 +12,8 @@ using SushiBarDatabaseImplement;
|
|||||||
namespace SushiBarDatabaseImplement.Migrations
|
namespace SushiBarDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(SushiBarDatabase))]
|
[DbContext(typeof(SushiBarDatabase))]
|
||||||
[Migration("20240313061851_InitialCreate2")]
|
[Migration("20240424132544_InitialCreate")]
|
||||||
partial class InitialCreate2
|
partial class InitialCreate
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -57,10 +57,10 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
b.Property<DateTime>("DateCreate")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp without time zone");
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
b.Property<DateTime?>("DateImplement")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp without time zone");
|
||||||
|
|
||||||
b.Property<int>("Status")
|
b.Property<int>("Status")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
@ -126,11 +126,13 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", null)
|
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("SushiId")
|
.HasForeignKey("SushiId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Sushi");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace SushiBarDatabaseImplement.Migrations
|
namespace SushiBarDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class InitialCreate2 : Migration
|
public partial class InitialCreate : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
@ -46,12 +46,12 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
{
|
{
|
||||||
Id = table.Column<int>(type: "integer", nullable: false)
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
SushiId = table.Column<int>(type: "integer", nullable: false),
|
|
||||||
Count = table.Column<int>(type: "integer", nullable: false),
|
Count = table.Column<int>(type: "integer", nullable: false),
|
||||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||||
Status = table.Column<int>(type: "integer", nullable: false),
|
Status = table.Column<int>(type: "integer", nullable: false),
|
||||||
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
||||||
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
DateImplement = table.Column<DateTime>(type: "timestamp without time zone", nullable: true),
|
||||||
|
SushiId = table.Column<int>(type: "integer", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
@ -54,10 +54,10 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
b.Property<DateTime>("DateCreate")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp without time zone");
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
b.Property<DateTime?>("DateImplement")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp without time zone");
|
||||||
|
|
||||||
b.Property<int>("Status")
|
b.Property<int>("Status")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
@ -123,11 +123,13 @@ namespace SushiBarDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", null)
|
b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi")
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("SushiId")
|
.HasForeignKey("SushiId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Sushi");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
modelBuilder.Entity("SushiBarDatabaseImplement.Models.SushiComponent", b =>
|
||||||
|
@ -10,8 +10,6 @@ namespace SushiBarDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int SushiId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public double Sum { get; set; }
|
public double Sum { get; set; }
|
||||||
@ -20,44 +18,46 @@ namespace SushiBarDatabaseImplement.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int SushiId { get; private set; }
|
||||||
|
public virtual Sushi Sushi { get; set; }
|
||||||
public static Order Create(SushiBarDatabase context, OrderBindingModel model)
|
public static Order Create(SushiBarDatabase context, OrderBindingModel model)
|
||||||
{
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
SushiId = model.SushiId,
|
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement,
|
DateImplement = model.DateImplement,
|
||||||
|
SushiId = model.SushiId,
|
||||||
|
Sushi = context.Sushis.First(x => x.Id == model.SushiId)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(OrderBindingModel model)
|
public void Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
Id = model.Id;
|
if (model == null)
|
||||||
SushiId = model.SushiId;
|
{
|
||||||
Sum = model.Sum;
|
return;
|
||||||
|
}
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
DateCreate = model.DateCreate;
|
|
||||||
DateImplement = model.DateImplement;
|
DateImplement = model.DateImplement;
|
||||||
}
|
}
|
||||||
public OrderViewModel GetViewModel(SushiBarDatabase context)
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
return new()
|
Id = Id,
|
||||||
{
|
SushiId = SushiId,
|
||||||
Id = Id,
|
Count = Count,
|
||||||
SushiId = SushiId,
|
Sum = Sum,
|
||||||
Count = Count,
|
Status = Status,
|
||||||
Sum = Sum,
|
DateCreate = DateCreate,
|
||||||
Status = Status,
|
DateImplement = DateImplement,
|
||||||
DateCreate = DateCreate,
|
SushiName = Sushi.SushiName
|
||||||
DateImplement = DateImplement,
|
};
|
||||||
SushiName = context.Sushis
|
|
||||||
.Where(s => s.Id == SushiId)
|
|
||||||
.Select(s => s.SushiName)
|
|
||||||
.First(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user