From 1814173da374c76221c6bcf6324567fa83d19da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9F=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BF=D0=BE=D0=B2?= Date: Wed, 20 Nov 2024 11:53:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D1=8E=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=20=D0=91=D0=94=20=D0=B8=20?= =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InternetShopDatabase.cs | 19 ++++++++ .../InternetShopDatabase.csproj | 14 ++++++ .../InternetShopDatabase/Models/Order.cs | 45 +++++++++++++++++++ .../InternetShopDatabase/Models/Product.cs | 31 +++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 InternetShop/InternetShopDatabase/InternetShopDatabase.cs create mode 100644 InternetShop/InternetShopDatabase/Models/Order.cs create mode 100644 InternetShop/InternetShopDatabase/Models/Product.cs 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; + } + } +}