diff --git a/InternetShop/InternetShopDatabase/InternetShopDatabase.cs b/InternetShop/InternetShopDatabase/InternetShopDatabase.cs new file mode 100644 index 0000000..f2f3024 --- /dev/null +++ b/InternetShop/InternetShopDatabase/InternetShopDatabase.cs @@ -0,0 +1,19 @@ +using InternetShopDatabase.Models; +using Microsoft.EntityFrameworkCore; + +namespace InternetShopDatabase +{ + public class InternetShopDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=localhost;User Id=SA;Password=87cbn9y48392nu32;Initial Catalog=InternetShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Orders { set; get; } + public virtual DbSet Products { set; get; } + } +} diff --git a/InternetShop/InternetShopDatabase/InternetShopDatabase.csproj b/InternetShop/InternetShopDatabase/InternetShopDatabase.csproj index fa71b7a..99cacac 100644 --- a/InternetShop/InternetShopDatabase/InternetShopDatabase.csproj +++ b/InternetShop/InternetShopDatabase/InternetShopDatabase.csproj @@ -6,4 +6,18 @@ enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/InternetShop/InternetShopDatabase/Models/Order.cs b/InternetShop/InternetShopDatabase/Models/Order.cs new file mode 100644 index 0000000..49f0885 --- /dev/null +++ b/InternetShop/InternetShopDatabase/Models/Order.cs @@ -0,0 +1,45 @@ +using InternetShopContracts.DataBindingModels; +using InternetShopContracts.DataViewModels; +using InternetShopDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace InternetShopDatabase.Models +{ + public class Order : IOrderModel + { + [Required] + public string CustomerFIO { get; set; } = string.Empty; + [Required] + public string CustomerEmail { get; set; } = string.Empty; + [Required] + public string ImagePath { get; set; } = string.Empty; + public List ProductNames { get; set; } = new List(); + public int Id { get; set; } + public OrderViewModel GetViewModel => new() + { + Id = Id, + CustomerFIO = CustomerFIO, + CustomerEmail = CustomerEmail, + ImagePath = ImagePath, + ProductNames = ProductNames, + }; + public static Order? Create(OrderBindingModel model) + { + return new Order() + { + Id = model.Id, + CustomerFIO = model.CustomerFIO, + CustomerEmail = model.CustomerEmail, + ImagePath = model.ImagePath, + ProductNames = model.ProductNames, + }; + } + public void Update(OrderBindingModel model) + { + CustomerFIO = model.CustomerFIO; + CustomerEmail = model.CustomerEmail; + ImagePath = model.ImagePath; + ProductNames = model.ProductNames; + } + } +} diff --git a/InternetShop/InternetShopDatabase/Models/Product.cs b/InternetShop/InternetShopDatabase/Models/Product.cs new file mode 100644 index 0000000..294cf9b --- /dev/null +++ b/InternetShop/InternetShopDatabase/Models/Product.cs @@ -0,0 +1,31 @@ +using InternetShopContracts.DataBindingModels; +using InternetShopContracts.DataViewModels; +using InternetShopDataModels.Models; +using System.ComponentModel.DataAnnotations; + +namespace InternetShopDatabase.Models +{ + public class Product : IProductModel + { + [Required] + public string Name { get; set; } = string.Empty; + public int Id { get; set; } + public ProductViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + }; + public static Product? Create(ProductBindingModel model) + { + return new Product() + { + Id = model.Id, + Name = model.Name, + }; + } + public void Update(ProductBindingModel model) + { + Name = model.Name; + } + } +}