Compare commits
3 Commits
af3573a8d8
...
7a75216f0b
Author | SHA1 | Date | |
---|---|---|---|
|
7a75216f0b | ||
|
c659b227b7 | ||
|
10b4de276c |
@ -0,0 +1,85 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDatabaseImplement.Models;
|
||||
using TypographyDatabaseImplements;
|
||||
|
||||
namespace TypographyDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Components
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Components
|
||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Components
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
var newComponent = Component.Create(model);
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
98
TypographyShopDatabaseImplements/Implements/OrderStorage.cs
Normal file
98
TypographyShopDatabaseImplements/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TypographyDatabaseImplements;
|
||||
|
||||
namespace TypographyDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Printed)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Printed)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Printed)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return context.Orders
|
||||
.Include(x => x.Printed)
|
||||
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Orders
|
||||
.Include(x => x.Printed)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
var deletedElement = context.Orders
|
||||
.Include(x => x.Printed)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return deletedElement;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
108
TypographyShopDatabaseImplements/Implements/PrintedStorage.cs
Normal file
108
TypographyShopDatabaseImplements/Implements/PrintedStorage.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TypographyDatabaseImplements;
|
||||
using TypographyDatabaseImplements.Models;
|
||||
|
||||
namespace TypographyDatabaseImplement.Implements
|
||||
{
|
||||
public class PrintedStorage : IPrintedStorage
|
||||
{
|
||||
public List<PrintedViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Printeds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<PrintedViewModel> GetFilteredList(PrintedSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PrintedName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Printeds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.PrintedName.Contains(model.PrintedName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public PrintedViewModel? GetElement(PrintedSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PrintedName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Printeds
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PrintedName) && x.PrintedName == model.PrintedName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public PrintedViewModel? Insert(PrintedBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
var newPrinted = Printed.Create(context, model);
|
||||
if (newPrinted == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Printeds.Add(newPrinted);
|
||||
context.SaveChanges();
|
||||
return newPrinted.GetViewModel;
|
||||
}
|
||||
|
||||
public PrintedViewModel? Update(PrintedBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var printed = context.Printeds.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (printed == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
printed.Update(model);
|
||||
context.SaveChanges();
|
||||
printed.UpdateComponents(context, model);
|
||||
transaction.Commit();
|
||||
return printed.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public PrintedViewModel? Delete(PrintedBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
var element = context.Printeds
|
||||
.Include(x => x.Components)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Printeds.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
144
TypographyShopDatabaseImplements/Implements/ShopStorage.cs
Normal file
144
TypographyShopDatabaseImplements/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,144 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.SearchModels;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDatabaseImplement.Models;
|
||||
using TypographyDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TypographyDatabaseImplements;
|
||||
|
||||
namespace TypographyDatabaseImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Shops.Include(x => x.Printeds).ThenInclude(x => x.Printed).FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ShopName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Shops.Include(x => x.Printeds).ThenInclude(x => x.Printed).Where(x => x.ShopName.Contains(model.ShopName)).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
return context.Shops.Include(x => x.Printeds).ThenInclude(x => x.Printed).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var newShop = Shop.Create(context, model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (context.Shops.Any(x => x.ShopName == newShop.ShopName))
|
||||
{
|
||||
throw new Exception("Название магазина уже занято");
|
||||
}
|
||||
|
||||
context.Shops.Add(newShop);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var shop = context.Shops.Include(x => x.Printeds).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
context.SaveChanges();
|
||||
if (model.ShopPrinteds.Count > 0)
|
||||
{
|
||||
shop.UpdatePrinteds(context, model);
|
||||
}
|
||||
transaction.Commit();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
var shop = context.Shops.Include(x => x.Printeds).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop != null)
|
||||
{
|
||||
context.Shops.Remove(shop);
|
||||
context.SaveChanges();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellPrinted(IPrintedModel model, int count)
|
||||
{
|
||||
using var context = new TypographyDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
foreach (var shopPrinteds in context.ShopPrinteds.Where(x => x.PrintedId == model.Id))
|
||||
{
|
||||
var min = Math.Min(count, shopPrinteds.Count);
|
||||
shopPrinteds.Count -= min;
|
||||
count -= min;
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
else
|
||||
transaction.Rollback();
|
||||
|
||||
if (count > 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
248
TypographyShopDatabaseImplements/Migrations/20240422081714_InitialCreate.Designer.cs
generated
Normal file
248
TypographyShopDatabaseImplements/Migrations/20240422081714_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,248 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using TypographyDatabaseImplements;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TypographyDatabaseImplements.Migrations
|
||||
{
|
||||
[DbContext(typeof(TypographyDatabase))]
|
||||
[Migration("20240422081714_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("PrintedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PrintedId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("DateOpening")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("MaxCountPrinteds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.ShopPrinted", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PrintedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PrintedId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopPrinteds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplements.Models.Printed", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("PrintedName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Printeds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplements.Models.PrintedComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PrintedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("PrintedId");
|
||||
|
||||
b.ToTable("PrintedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("TypographyDatabaseImplements.Models.Printed", "Printed")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("PrintedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Printed");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.ShopPrinted", b =>
|
||||
{
|
||||
b.HasOne("TypographyDatabaseImplements.Models.Printed", "Printed")
|
||||
.WithMany()
|
||||
.HasForeignKey("PrintedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TypographyDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Printeds")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Printed");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplements.Models.PrintedComponent", b =>
|
||||
{
|
||||
b.HasOne("TypographyDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("PrintedComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TypographyDatabaseImplements.Models.Printed", "Printed")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("PrintedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Printed");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("PrintedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Printeds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplements.Models.Printed", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,184 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TypographyDatabaseImplements.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Printeds",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
PrintedName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Printeds", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateOpening = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
MaxCountPrinteds = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
PrintedId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Printeds_PrintedId",
|
||||
column: x => x.PrintedId,
|
||||
principalTable: "Printeds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PrintedComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
PrintedId = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PrintedComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_PrintedComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_PrintedComponents_Printeds_PrintedId",
|
||||
column: x => x.PrintedId,
|
||||
principalTable: "Printeds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopPrinteds",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
PrintedId = table.Column<int>(type: "int", nullable: false),
|
||||
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopPrinteds", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopPrinteds_Printeds_PrintedId",
|
||||
column: x => x.PrintedId,
|
||||
principalTable: "Printeds",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopPrinteds_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_PrintedId",
|
||||
table: "Orders",
|
||||
column: "PrintedId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PrintedComponents_ComponentId",
|
||||
table: "PrintedComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PrintedComponents_PrintedId",
|
||||
table: "PrintedComponents",
|
||||
column: "PrintedId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopPrinteds_PrintedId",
|
||||
table: "ShopPrinteds",
|
||||
column: "PrintedId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopPrinteds_ShopId",
|
||||
table: "ShopPrinteds",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PrintedComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopPrinteds");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Printeds");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,245 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using TypographyDatabaseImplements;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace TypographyDatabaseImplements.Migrations
|
||||
{
|
||||
[DbContext(typeof(TypographyDatabase))]
|
||||
partial class TypographyDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.16")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("PrintedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PrintedId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("DateOpening")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("MaxCountPrinteds")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.ShopPrinted", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PrintedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PrintedId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopPrinteds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplements.Models.Printed", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<string>("PrintedName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Printeds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplements.Models.PrintedComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PrintedId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("PrintedId");
|
||||
|
||||
b.ToTable("PrintedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("TypographyDatabaseImplements.Models.Printed", "Printed")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("PrintedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Printed");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.ShopPrinted", b =>
|
||||
{
|
||||
b.HasOne("TypographyDatabaseImplements.Models.Printed", "Printed")
|
||||
.WithMany()
|
||||
.HasForeignKey("PrintedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TypographyDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Printeds")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Printed");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplements.Models.PrintedComponent", b =>
|
||||
{
|
||||
b.HasOne("TypographyDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("PrintedComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("TypographyDatabaseImplements.Models.Printed", "Printed")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("PrintedId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Printed");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("PrintedComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Printeds");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("TypographyDatabaseImplements.Models.Printed", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
57
TypographyShopDatabaseImplements/Models/Component.cs
Normal file
57
TypographyShopDatabaseImplements/Models/Component.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDatabaseImplements.Models;
|
||||
using TypographyDataModels.Models;
|
||||
|
||||
namespace TypographyDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<PrintedComponent> PrintedComponents { get; set; } = new();
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public static Component Create(ComponentViewModel model)
|
||||
{
|
||||
return new Component
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public void Update(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
74
TypographyShopDatabaseImplements/Models/Order.cs
Normal file
74
TypographyShopDatabaseImplements/Models/Order.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TypographyDatabaseImplements.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using TypographyDataModels.Models;
|
||||
|
||||
namespace TypographyDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int PrintedId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; set; }
|
||||
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
public virtual Printed Printed { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
PrintedId = model.PrintedId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PrintedId = PrintedId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
PrintedName = Printed.PrintedName
|
||||
};
|
||||
}
|
||||
}
|
89
TypographyShopDatabaseImplements/Models/Printed.cs
Normal file
89
TypographyShopDatabaseImplements/Models/Printed.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TypographyDataModels.Models;
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using TypographyDatabaseImplement.Models;
|
||||
|
||||
namespace TypographyDatabaseImplements.Models
|
||||
{
|
||||
public class Printed : IPrintedModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string PrintedName { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
private Dictionary<int, (IComponentModel, int)>? _printedComponents = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> PrintedComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_printedComponents == null)
|
||||
{
|
||||
_printedComponents = Components.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
|
||||
}
|
||||
return _printedComponents;
|
||||
}
|
||||
}
|
||||
[ForeignKey("PrintedId")]
|
||||
public virtual List<PrintedComponent> Components { get; set; } = new();
|
||||
[ForeignKey("PrintedId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public static Printed Create(TypographyDatabase context, PrintedBindingModel model)
|
||||
{
|
||||
return new Printed()
|
||||
{
|
||||
Id = model.Id,
|
||||
PrintedName = model.PrintedName,
|
||||
Price = model.Price,
|
||||
Components = model.PrintedComponents.Select(x => new PrintedComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(PrintedBindingModel model)
|
||||
{
|
||||
PrintedName = model.PrintedName;
|
||||
Price = model.Price;
|
||||
}
|
||||
public PrintedViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PrintedName = PrintedName,
|
||||
Price = Price,
|
||||
PrintedComponents = PrintedComponents
|
||||
};
|
||||
public void UpdateComponents(TypographyDatabase context, PrintedBindingModel model)
|
||||
{
|
||||
var printedComponents = context.PrintedComponents.Where(rec => rec.PrintedId == model.Id).ToList();
|
||||
if (printedComponents != null && printedComponents.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.PrintedComponents.RemoveRange(printedComponents.Where(rec => !model.PrintedComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateComponent in printedComponents)
|
||||
{
|
||||
updateComponent.Count = model.PrintedComponents[updateComponent.ComponentId].Item2;
|
||||
model.PrintedComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var printed = context.Printeds.First(x => x.Id == Id);
|
||||
foreach (var pc in model.PrintedComponents)
|
||||
{
|
||||
context.PrintedComponents.Add(new PrintedComponent
|
||||
{
|
||||
Printed = printed,
|
||||
Component = context.Components.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_printedComponents = null;
|
||||
}
|
||||
}
|
||||
}
|
27
TypographyShopDatabaseImplements/Models/PrintedComponent.cs
Normal file
27
TypographyShopDatabaseImplements/Models/PrintedComponent.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TypographyDatabaseImplement.Models;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Models;
|
||||
|
||||
namespace TypographyDatabaseImplements.Models
|
||||
{
|
||||
public class PrintedComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int PrintedId { get; set; }
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Printed Printed { get; set; } = new();
|
||||
}
|
||||
}
|
115
TypographyShopDatabaseImplements/Models/Shop.cs
Normal file
115
TypographyShopDatabaseImplements/Models/Shop.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using TypographyContracts.BindingModels;
|
||||
using TypographyContracts.ViewModels;
|
||||
using TypographyDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TypographyDatabaseImplements;
|
||||
|
||||
namespace TypographyDatabaseImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ShopName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public DateTime DateOpening { get; set; }
|
||||
|
||||
[ForeignKey("ShopId")]
|
||||
public List<ShopPrinted> Printeds { get; set; } = new();
|
||||
|
||||
private Dictionary<int, (IPrintedModel, int)>? _shopPrinteds = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IPrintedModel, int)> ShopPrinteds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopPrinteds == null)
|
||||
{
|
||||
_shopPrinteds = Printeds.ToDictionary(recPC => recPC.PrintedId, recPC => (recPC.Printed as IPrintedModel, recPC.Count));
|
||||
}
|
||||
return _shopPrinteds;
|
||||
}
|
||||
}
|
||||
|
||||
[Required]
|
||||
public int MaxCountPrinteds { get; set; }
|
||||
|
||||
public static Shop Create(TypographyDatabase context, ShopBindingModel model)
|
||||
{
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShopName = model.ShopName,
|
||||
Address = model.Address,
|
||||
DateOpening = model.DateOpening,
|
||||
Printeds = model.ShopPrinteds.Select(x => new ShopPrinted
|
||||
{
|
||||
Printed = context.Printeds.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
MaxCountPrinteds = model.MaxCountPrinteds
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShopBindingModel model)
|
||||
{
|
||||
ShopName = model.ShopName;
|
||||
Address = model.Address;
|
||||
DateOpening = model.DateOpening;
|
||||
MaxCountPrinteds = model.MaxCountPrinteds;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShopName = ShopName,
|
||||
Address = Address,
|
||||
DateOpening = DateOpening,
|
||||
ShopPrinteds = ShopPrinteds,
|
||||
MaxCountPrinteds = MaxCountPrinteds
|
||||
};
|
||||
|
||||
public void UpdatePrinteds(TypographyDatabase context, ShopBindingModel model)
|
||||
{
|
||||
var ShopPrinteds = context.ShopPrinteds.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
if (ShopPrinteds != null && ShopPrinteds.Count > 0)
|
||||
{
|
||||
// удалили те, которых нет в модели
|
||||
context.ShopPrinteds.RemoveRange(ShopPrinteds.Where(rec => !model.ShopPrinteds.ContainsKey(rec.PrintedId)));
|
||||
context.SaveChanges();
|
||||
ShopPrinteds = context.ShopPrinteds.Where(rec => rec.ShopId == model.Id).ToList();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updatePrinted in ShopPrinteds)
|
||||
{
|
||||
updatePrinted.Count = model.ShopPrinteds[updatePrinted.PrintedId].Item2;
|
||||
model.ShopPrinteds.Remove(updatePrinted.PrintedId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var shop = context.Shops.First(x => x.Id == Id);
|
||||
foreach (var elem in model.ShopPrinteds)
|
||||
{
|
||||
context.ShopPrinteds.Add(new ShopPrinted
|
||||
{
|
||||
Shop = shop,
|
||||
Printed = context.Printeds.First(x => x.Id == elem.Key),
|
||||
Count = elem.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_shopPrinteds = null;
|
||||
}
|
||||
}
|
||||
}
|
23
TypographyShopDatabaseImplements/Models/ShopPrinteds.cs
Normal file
23
TypographyShopDatabaseImplements/Models/ShopPrinteds.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TypographyDatabaseImplements.Models;
|
||||
|
||||
namespace TypographyDatabaseImplement.Models
|
||||
{
|
||||
public class ShopPrinted
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int PrintedId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ShopId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Shop Shop { get; set; } = new();
|
||||
|
||||
public virtual Printed Printed { get; set; } = new();
|
||||
}
|
||||
}
|
32
TypographyShopDatabaseImplements/TypographyDatabase.cs
Normal file
32
TypographyShopDatabaseImplements/TypographyDatabase.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TypographyDatabaseImplements.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TypographyDatabaseImplement.Models;
|
||||
|
||||
namespace TypographyDatabaseImplements
|
||||
{
|
||||
public class TypographyDatabase: DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source = .\SQLEXPRESS;
|
||||
Initial Catalog=TypographyDatabaseHardFull;
|
||||
Integrated Security=True;MultipleActiveResultSets=True;;
|
||||
TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Printed> Printeds { set; get; }
|
||||
public virtual DbSet<PrintedComponent> PrintedComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Shop> Shops { set; get; }
|
||||
public virtual DbSet<ShopPrinted> ShopPrinteds { set; get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TypographyContracts\TypographyContracts.csproj" />
|
||||
<ProjectReference Include="..\TypographyDataModels\TypographyDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
14
TypographyView/FormShopSell.Designer.cs
generated
14
TypographyView/FormShopSell.Designer.cs
generated
@ -57,18 +57,18 @@
|
||||
// comboBoxPrinted
|
||||
//
|
||||
comboBoxPrinted.FormattingEnabled = true;
|
||||
comboBoxPrinted.Location = new Point(70, 8);
|
||||
comboBoxPrinted.Location = new Point(106, 8);
|
||||
comboBoxPrinted.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxPrinted.Name = "comboBoxPrinted";
|
||||
comboBoxPrinted.Size = new Size(370, 28);
|
||||
comboBoxPrinted.Size = new Size(334, 28);
|
||||
comboBoxPrinted.TabIndex = 2;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
textBoxCount.Location = new Point(70, 47);
|
||||
textBoxCount.Location = new Point(106, 47);
|
||||
textBoxCount.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxCount.Name = "textBoxCount";
|
||||
textBoxCount.Size = new Size(370, 27);
|
||||
textBoxCount.Size = new Size(334, 27);
|
||||
textBoxCount.TabIndex = 3;
|
||||
//
|
||||
// buttonCancel
|
||||
@ -78,7 +78,7 @@
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(86, 31);
|
||||
buttonCancel.TabIndex = 4;
|
||||
buttonCancel.Text = "Cancel";
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
buttonCancel.Click += buttonCancel_Click;
|
||||
//
|
||||
@ -89,7 +89,7 @@
|
||||
buttonSell.Name = "buttonSell";
|
||||
buttonSell.Size = new Size(86, 31);
|
||||
buttonSell.TabIndex = 5;
|
||||
buttonSell.Text = "Sell";
|
||||
buttonSell.Text = "Продать";
|
||||
buttonSell.UseVisualStyleBackColor = true;
|
||||
buttonSell.Click += buttonSell_Click;
|
||||
//
|
||||
@ -106,7 +106,7 @@
|
||||
Controls.Add(labelPrinted);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormShopSell";
|
||||
Text = "Sell";
|
||||
Text = "Продажа";
|
||||
Load += FormShopSell_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
|
@ -1,7 +1,7 @@
|
||||
using TypographyBusinessLogic.BusinessLogics;
|
||||
using TypographyContracts.BusinessLogicsContracts;
|
||||
using TypographyContracts.StoragesContracts;
|
||||
using TypographyFileImplement.Implements;
|
||||
using TypographyDatabaseImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
@ -9,6 +9,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.16">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.8" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -18,6 +28,7 @@
|
||||
<ProjectReference Include="..\TypographyDataModels\TypographyDataModels.csproj" />
|
||||
<ProjectReference Include="..\TypographyFileImplement\TypographyFileImplement.csproj" />
|
||||
<ProjectReference Include="..\TypographyListImplement\TypographyListImplement.csproj" />
|
||||
<ProjectReference Include="..\TypographyShopDatabaseImplements\TypographyDatabaseImplements.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyContracts", "..\T
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyBusinessLogic", "..\TypographyBusinessLogic\TypographyBusinessLogic.csproj", "{1057A33D-538D-4E7F-862B-1FF8E9E021A0}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyFileImplement", "..\TypographyFileImplement\TypographyFileImplement.csproj", "{DCBDF361-C514-4319-A542-5629650E7E8A}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyFileImplement", "..\TypographyFileImplement\TypographyFileImplement.csproj", "{DCBDF361-C514-4319-A542-5629650E7E8A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyDatabaseImplements", "..\TypographyShopDatabaseImplements\TypographyDatabaseImplements.csproj", "{53696C80-7558-41F5-AF69-73ACA345C92B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -45,6 +47,10 @@ Global
|
||||
{DCBDF361-C514-4319-A542-5629650E7E8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DCBDF361-C514-4319-A542-5629650E7E8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DCBDF361-C514-4319-A542-5629650E7E8A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{53696C80-7558-41F5-AF69-73ACA345C92B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{53696C80-7558-41F5-AF69-73ACA345C92B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{53696C80-7558-41F5-AF69-73ACA345C92B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{53696C80-7558-41F5-AF69-73ACA345C92B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user