DatabaseImplement 214.0

This commit is contained in:
Игорь Гордеев 2024-05-25 13:06:38 +04:00
parent db0dbba5b4
commit 741d60317e
20 changed files with 333 additions and 370 deletions

View File

@ -17,6 +17,6 @@ namespace ElectronicsShopContracts.BindingModels
public double Price { get; set; } public double Price { get; set; }
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неоплачено; public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
} }
} }

View File

@ -14,5 +14,6 @@ namespace ElectronicsShopContracts.SearchModels
public int? ClientID { get; set; } public int? ClientID { get; set; }
public int? EmployeeID { get; set; } public int? EmployeeID { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set;}
} }
} }

View File

@ -8,7 +8,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ElectronicsShopContracts.StorageContracts { namespace ElectronicsShopContracts.StorageContracts {
public interface ICostItemModel { public interface ICostItemStorage {
List<CostItemViewModel> GetFullList(); List<CostItemViewModel> GetFullList();
List<CostItemViewModel> GetFillteredList(CostItemSearchModel model); List<CostItemViewModel> GetFillteredList(CostItemSearchModel model);

View File

@ -14,7 +14,7 @@ namespace ElectronicsShopContracts.StorageContracts
List<EmployeeViewModel> GetFullList(); List<EmployeeViewModel> GetFullList();
List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model); List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model);
EmployeeViewModel? GetElement(ClientSearchModel model); EmployeeViewModel? GetElement(EmployeeSearchModel model);
EmployeeViewModel? Insert(EmployeeBindingModel model); EmployeeViewModel? Insert(EmployeeBindingModel model);
EmployeeViewModel? Update(EmployeeBindingModel model); EmployeeViewModel? Update(EmployeeBindingModel model);
EmployeeViewModel? Delete(EmployeeBindingModel model); EmployeeViewModel? Delete(EmployeeBindingModel model);

View File

@ -21,6 +21,6 @@ namespace ElectronicsShopContracts.ViewModels
public double Price { get; set; } public double Price { get; set; }
[DisplayName("Статус оплаты")] [DisplayName("Статус оплаты")]
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неоплачено; public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
} }
} }

View File

@ -15,11 +15,12 @@ namespace ElectronicsShopDataBaseImplement
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }
public virtual DbSet<CategoryProduct> CategoryProducts { set; get; } public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<User> Users { set; get; }
public virtual DbSet<Role> Roles { set; get; }
public virtual DbSet<Product> Products { set; get; } public virtual DbSet<Product> Products { set; get; }
public virtual DbSet<Order> Orders { set; get; } public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
public virtual DbSet<Employee> Employees { set; get; }
public virtual DbSet<CostItem> CostItems { set; get; }
} }
} }

View File

@ -1,83 +0,0 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements
{
public class CategoryProductStorage : ICategoryProductStorage
{
public CategoryProductViewModel? Delete(CategoryProductBindingModel model)
{
using var context = new Database();
var element = context.CategoryProducts.FirstOrDefault(rec => rec.ID == model.ID);
if (element != null)
{
context.CategoryProducts.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public CategoryProductViewModel? GetElement(CategoryProductSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue)
{
return null;
}
using var context = new Database();
return context.CategoryProducts.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
}
public List<CategoryProductViewModel> GetFilteredList(CategoryProductSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new Database();
return context.CategoryProducts.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
}
public List<CategoryProductViewModel> GetFullList()
{
using var context = new Database();
return context.CategoryProducts.Select(x => x.GetViewModel).ToList();
}
public CategoryProductViewModel? Insert(CategoryProductBindingModel model)
{
var newComponent = CategoryProduct.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new Database();
context.CategoryProducts.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public CategoryProductViewModel? Update(CategoryProductBindingModel model)
{
using var context = new Database();
var component = context.CategoryProducts.FirstOrDefault(x => x.ID == model.ID);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -11,15 +11,15 @@ using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements namespace ElectronicsShopDataBaseImplement.Implements
{ {
public class UserStorage : IClientStorage public class ClientStorage : IClientStorage
{ {
public ClientViewModel? Delete(UserBindingModel model) public ClientViewModel? Delete(ClientBindingModel model)
{ {
using var context = new Database(); using var context = new Database();
var element = context.Users.FirstOrDefault(rec => rec.ID == model.ID); var element = context.Clients.FirstOrDefault(rec => rec.ID == model.ID);
if (element != null) if (element != null)
{ {
context.Users.Remove(element); context.Clients.Remove(element);
context.SaveChanges(); context.SaveChanges();
return element.GetViewModel; return element.GetViewModel;
} }
@ -28,49 +28,49 @@ namespace ElectronicsShopDataBaseImplement.Implements
public ClientViewModel? GetElement(ClientSearchModel model) public ClientViewModel? GetElement(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Login) && !model.ID.HasValue) if (string.IsNullOrEmpty(model.Email) && !model.ID.HasValue)
{ {
return null; return null;
} }
using var context = new Database(); using var context = new Database();
return context.Users.FirstOrDefault(x => return context.Clients.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Login) && x.Login == model.Login || (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email ||
(model.ID.HasValue && x.ID == model.ID)))?.GetViewModel; (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
} }
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Login)) if (string.IsNullOrEmpty(model.Email))
{ {
return new(); return new();
} }
using var context = new Database(); using var context = new Database();
return context.Users.Where(x => x.Login.Contains(model.Login)).Select(x => x.GetViewModel).ToList(); return context.Clients.Where(x => x.Email.Contains(model.Email)).Select(x => x.GetViewModel).ToList();
} }
public List<ClientViewModel> GetFullList() public List<ClientViewModel> GetFullList()
{ {
using var context = new Database(); using var context = new Database();
return context.Users.Select(x => x.GetViewModel).ToList(); return context.Clients.Select(x => x.GetViewModel).ToList();
} }
public ClientViewModel? Insert(UserBindingModel model) public ClientViewModel? Insert(ClientBindingModel model)
{ {
var newComponent = User.Create(model); var newComponent = Client.Create(model);
if (newComponent == null) if (newComponent == null)
{ {
return null; return null;
} }
using var context = new Database(); using var context = new Database();
context.Users.Add(newComponent); context.Clients.Add(newComponent);
context.SaveChanges(); context.SaveChanges();
return newComponent.GetViewModel; return newComponent.GetViewModel;
} }
public ClientViewModel? Update(UserBindingModel model) public ClientViewModel? Update(ClientBindingModel model)
{ {
using var context = new Database(); using var context = new Database();
var component = context.Users.FirstOrDefault(x => x.ID == model.ID); var component = context.Clients.FirstOrDefault(x => x.ID == model.ID);
if (component == null) if (component == null)
{ {
return null; return null;

View File

@ -11,65 +11,66 @@ using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements namespace ElectronicsShopDataBaseImplement.Implements
{ {
public class RoleStorage: IRoleStorage public class CostItemStorage : ICostItemStorage
{ {
public RoleViewModel? Delete(RoleBindingModel model) public CostItemViewModel? Delete(CostItemBindingModel model)
{ {
using var context = new Database(); using var context = new Database();
var element = context.Roles.FirstOrDefault(rec => rec.ID == model.ID); var element = context.CostItems.FirstOrDefault(rec => rec.ID == model.ID);
if (element != null) if (element != null)
{ {
context.Roles.Remove(element); context.CostItems.Remove(element);
context.SaveChanges(); context.SaveChanges();
return element.GetViewModel; return element.GetViewModel;
} }
return null; return null;
} }
public RoleViewModel? GetElement(RoleSearchModel model) public CostItemViewModel GetElement(CostItemSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue)
{ {
return null; return null;
} }
using var context = new Database(); using var context = new Database();
return context.Roles.FirstOrDefault(x => return context.CostItems.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name == model.Name && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel; (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name ||
(model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
} }
public List<RoleViewModel> GetFilteredList(RoleSearchModel model) public List<CostItemViewModel> GetFillteredList(CostItemSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Name)) if (string.IsNullOrEmpty(model.Name))
{ {
return new(); return new();
} }
using var context = new Database(); using var context = new Database();
return context.Roles.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList(); return context.CostItems.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
} }
public List<RoleViewModel> GetFullList() public List<CostItemViewModel> GetFullList()
{ {
using var context = new Database(); using var context = new Database();
return context.Roles.Select(x => x.GetViewModel).ToList(); return context.CostItems.Select(x => x.GetViewModel).ToList();
} }
public RoleViewModel? Insert(RoleBindingModel model) public CostItemViewModel? Insert(CostItemBindingModel model)
{ {
var newComponent = Role.Create(model); var newComponent = CostItem.Create(model);
if (newComponent == null) if (newComponent == null)
{ {
return null; return null;
} }
using var context = new Database(); using var context = new Database();
context.Roles.Add(newComponent); context.CostItems.Add(newComponent);
context.SaveChanges(); context.SaveChanges();
return newComponent.GetViewModel; return newComponent.GetViewModel;
} }
public RoleViewModel? Update(RoleBindingModel model) public CostItemViewModel? Update(CostItemBindingModel model)
{ {
using var context = new Database(); using var context = new Database();
var component = context.Roles.FirstOrDefault(x => x.ID == model.ID); var component = context.CostItems.FirstOrDefault(x => x.ID == model.ID);
if (component == null) if (component == null)
{ {
return null; return null;

View File

@ -0,0 +1,79 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models;
namespace ElectronicsShopDataBaseImplement.Implements
{
public class EmployeeStorage : IEmployeeStorage
{
public EmployeeViewModel? Delete(EmployeeBindingModel model)
{
using var context = new Database();
var element = context.Employees.FirstOrDefault(rec => rec.ID == model.ID);
if (element != null)
{
context.Employees.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public EmployeeViewModel? GetElement(EmployeeSearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && !model.ID.HasValue)
{
return null;
}
using var context = new Database();
return context.Employees.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Login) && x.EmployeeFIO == model.EmployeFIO ||
(model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
}
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
{
if (string.IsNullOrEmpty(model.Login))
{
return new();
}
using var context = new Database();
return context.Employees.Where(x => x.Login.Contains(model.Login)).Select(x => x.GetViewModel).ToList();
}
public List<EmployeeViewModel> GetFullList()
{
using var context = new Database();
return context.Employees.Select(x => x.GetViewModel).ToList();
}
public EmployeeViewModel? Insert(EmployeeBindingModel model)
{
var newComponent = Employee.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new Database();
context.Employees.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public EmployeeViewModel? Update(EmployeeBindingModel model)
{
using var context = new Database();
var component = context.Employees.FirstOrDefault(x => x.ID == model.ID);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -4,12 +4,7 @@ using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels; using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models; using ElectronicsShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements namespace ElectronicsShopDataBaseImplement.Implements
{ {
@ -35,7 +30,7 @@ namespace ElectronicsShopDataBaseImplement.Implements
} }
using var context = new Database(); using var context = new Database();
return context.Orders.FirstOrDefault(x => return context.Orders.FirstOrDefault(x =>
(x.DateCreate == model.DateFrom && (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel; (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -80,7 +75,7 @@ namespace ElectronicsShopDataBaseImplement.Implements
{ {
return null; return null;
} }
component.Update(model); component.Update(context ,model);
context.SaveChanges(); context.SaveChanges();
return component.GetViewModel; return component.GetViewModel;
} }

View File

@ -1,57 +0,0 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class CategoryProduct : ICategoryProductModel
{
public int ID { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
public static CategoryProduct? Create(CategoryProductBindingModel? model)
{
if(model == null)
{
return null;
}
return new CategoryProduct()
{
ID = model.ID,
Name = model.Name
};
}
public static CategoryProduct? Create(CategoryProductViewModel model)
{
return new CategoryProduct
{
ID = model.ID,
Name = model.Name
};
}
public void Update(CategoryProductBindingModel model)
{
if(model == null)
{
return;
}
Name = model.Name;
}
public CategoryProductViewModel GetViewModel => new()
{
ID = ID,
Name = Name
};
}
}

View File

@ -0,0 +1,60 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class Client : IClientModel
{
public int ID { get; set; }
[Required]
public string ClientFIO { get; set; }=string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
public static Client? Create(ClientBindingModel model)
{
if(model == null)
{
return null;
}
return new Client()
{
ID = model.ID,
ClientFIO = model.ClientFIO,
Password = model.Password,
Email = model.Email
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
ID = model.ID;
ClientFIO = model.ClientFIO;
Password = model.Password;
Email = model.Email;
}
public ClientViewModel GetViewModel => new()
{
ID = ID,
ClientFIO = ClientFIO,
Password = Password,
Email = Email
};
}
}

View File

@ -0,0 +1,59 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class CostItem : ICostItemModel
{
public int ID { get; set; }
[ForeignKey("ClientID")]
public int ClientID { get; set; }
[Required]
public string Name { get; set; }= string.Empty;
[Required]
public double Price { get; set; }
public static CostItem? Create(CostItemBindingModel? model)
{
if (model == null)
{
return null;
}
return new CostItem()
{
ID = model.ID,
ClientID = model.ClientID,
Name = model.Name,
Price = model.Price,
};
}
public void Update(CostItemBindingModel model)
{
if (model == null)
{
return;
}
ID = model.ID;
ClientID = model.ClientID;
Name = model.Name;
Price = model.Price;
}
public CostItemViewModel GetViewModel => new()
{
ID = ID,
ClientID = ClientID,
Name = Name,
Price = Price,
};
}
}

View File

@ -0,0 +1,59 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class Employee : IEmployeeModel
{
public int ID { get; set; }
[Required]
public string EmployeeFIO { get; set; }=string.Empty;
[Required]
public string Login { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
public static Employee? Create(EmployeeBindingModel? model)
{
if (model == null)
{
return null;
}
return new Employee()
{
ID = model.ID,
EmployeeFIO = model.EmployeeFIO,
Login = model.Login,
Password = model.Password,
};
}
public void Update(EmployeeBindingModel model)
{
if (model == null)
{
return;
}
ID = model.ID;
EmployeeFIO = model.EmployeeFIO;
Login = model.Login;
Password = model.Password;
}
public EmployeeViewModel GetViewModel => new()
{
ID = ID,
EmployeeFIO = EmployeeFIO,
Login = Login,
Password = Password,
};
}
}

View File

@ -20,15 +20,11 @@ namespace ElectronicsShopDataBaseImplement.Models
public double Sum { get; set; } public double Sum { get; set; }
[ForeignKey("ClientID")] [ForeignKey("ClientID")]
public int ClientID { get; set; } public int ClientID { get; set; }
[Required] [ForeignKey("EmployeeID")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public int? EmployeeID { get; set; }
[Required]
public PaymeantOption PaymeantOption { get; set; } = PaymeantOption.Неизвестно;
[Required] [Required]
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
[Required] [Required]
public DateTime? DateImplement { get; set; }
[Required]
public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new(); public Dictionary<int, (IProductModel, int)> ProductList { get; set; } = new();
[NotMapped] [NotMapped]
@ -42,7 +38,7 @@ namespace ElectronicsShopDataBaseImplement.Models
} }
} }
public virtual List<OrderProducts> Products { get; set; } = new(); public virtual List<OrderProduct> Products { get; set; } = new();
public static Order? Create(Database context ,OrderBindingModel? model) public static Order? Create(Database context ,OrderBindingModel? model)
{ {
@ -55,17 +51,16 @@ namespace ElectronicsShopDataBaseImplement.Models
ID = model.ID, ID = model.ID,
ClientID=model.ClientID, ClientID=model.ClientID,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, EmployeeID=model.EmployeeID,
PaymeantOption = model.PaymeantOption,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
Products = model.ProductList.Select(x => new OrderProducts Products = model.ProductList.Select(x => new OrderProduct
{ {
_product = context.Products.First(y => y.ID == x.Key), _product = context.Products.First(y => y.ID == x.Key),
Count = x.Value.Item2 Count = x.Value.Item2
}).ToList() }).ToList()
}; };
} }
public void Update(OrderBindingModel model) public void Update(Database context,OrderBindingModel model)
{ {
if (model == null) if (model == null)
{ {
@ -74,13 +69,13 @@ namespace ElectronicsShopDataBaseImplement.Models
ID = model.ID; ID = model.ID;
ClientID = model.ClientID; ClientID = model.ClientID;
Sum = model.Sum; Sum = model.Sum;
PaymeantOption = model.PaymeantOption; EmployeeID = model.EmployeeID;
Status = model.Status;
DateCreate = model.DateCreate; DateCreate = model.DateCreate;
if (model.DateImplement != null) Products = model.ProductList.Select(x => new OrderProduct
{ {
DateImplement = model.DateImplement; _product = context.Products.First(y => y.ID == x.Key),
} Count = x.Value.Item2
}).ToList();
//todo ProductList //todo ProductList
} }
@ -89,11 +84,15 @@ namespace ElectronicsShopDataBaseImplement.Models
ID = ID, ID = ID,
ClientID = ClientID, ClientID = ClientID,
Sum = Sum, Sum = Sum,
PaymeantOption = PaymeantOption, EmployeeID = EmployeeID,
Status = Status,
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement, /*
ProductList = ProductList ProductList = ProductList.Select(x => new OrderProducts
{
/_product = context.Products.First(y => y.ID == x.Key)
Count = x.Value.Item2
}).ToList()
*/
}; };
} }
} }

View File

@ -8,10 +8,9 @@ using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models namespace ElectronicsShopDataBaseImplement.Models
{ {
public class OrderProducts public class OrderProduct
{ {
public int ID { get; set; } public int Id { get; set; }
[ForeignKey("OrderID")] [ForeignKey("OrderID")]
public int OrdersID { get; set; } public int OrdersID { get; set; }

View File

@ -1,5 +1,6 @@
using ElectronicsShopContracts.BindingModels; using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels; using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums;
using ElectronicsShopDataModels.Models; using ElectronicsShopDataModels.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -18,8 +19,9 @@ namespace ElectronicsShopDataBaseImplement.Models
public string ProductName { get; set; }=string.Empty; public string ProductName { get; set; }=string.Empty;
[Required] [Required]
public double Price { get; set; } public double Price { get; set; }
[ForeignKey("CategoryID")] [ForeignKey("CostItemID")]
public int CategoryID { get; set; } public int CostItemID { get; set; }
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
public static Product? Create(ProductBindingModel? model) public static Product? Create(ProductBindingModel? model)
{ {
@ -32,17 +34,8 @@ namespace ElectronicsShopDataBaseImplement.Models
ID = model.ID, ID = model.ID,
ProductName = model.ProductName, ProductName = model.ProductName,
Price = model.Price, Price = model.Price,
CategoryID = model.CategoryID CostItemID=model.CostItemID,
}; PayOption=model.PayOption
}
public static Product? Create(ProductViewModel model)
{
return new Product
{
ID = model.ID,
ProductName = model.ProductName,
Price = model.Price,
CategoryID = model.CategoryID
}; };
} }
public void Update(ProductBindingModel model) public void Update(ProductBindingModel model)
@ -51,9 +44,11 @@ namespace ElectronicsShopDataBaseImplement.Models
{ {
return; return;
} }
ID = model.ID;
ProductName = model.ProductName; ProductName = model.ProductName;
Price = model.Price; Price = model.Price;
CategoryID = model.CategoryID; CostItemID = model.CostItemID;
PayOption = model.PayOption;
} }
public ProductViewModel GetViewModel => new() public ProductViewModel GetViewModel => new()
@ -61,7 +56,8 @@ namespace ElectronicsShopDataBaseImplement.Models
ID = ID, ID = ID,
ProductName = ProductName, ProductName = ProductName,
Price = Price, Price = Price,
CategoryID = CategoryID CostItemID = CostItemID,
PayOption = PayOption
}; };
} }
} }

View File

@ -1,55 +0,0 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class Role : IRoleModel
{
public int ID { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
public static Role? Create(RoleBindingModel? model)
{
if (model == null)
{
return null;
}
return new Role()
{
ID = model.ID,
Name = model.Name
};
}
public static Role? Create(RoleViewModel model)
{
return new Role
{
ID = model.ID,
Name = model.Name
};
}
public void Update(RoleBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public RoleViewModel GetViewModel => new()
{
ID = ID,
Name = Name
};
}
}

View File

@ -1,91 +0,0 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class User : IUserModel
{
public int ID { get; set; }
[Required]
public string FirstName { get; set; }=string.Empty;
[Required]
public string LastName {get; set; }=string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public string PhoneNumber { get; set; } = string.Empty;
[Required]
public string Login { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[ForeignKey("RoleID")]
public int RoleID { get; set; }
public static User? Create(UserBindingModel model)
{
if(model == null)
{
return null;
}
return new User()
{
ID = model.ID,
FirstName = model.FirstName,
LastName = model.LastName,
Password = model.Password,
PhoneNumber = model.PhoneNumber,
Login = model.Login,
Email = model.Email,
RoleID = model.RoleID
};
}
public static User Create(ClientViewModel model)
{
return new User
{
ID = model.ID,
FirstName = model.FirstName,
LastName = model.LastName,
Password = model.Password,
PhoneNumber = model.PhoneNumber,
Login = model.Login,
Email = model.Email,
RoleID = model.RoleID
};
}
public void Update(UserBindingModel model)
{
if (model == null)
{
return;
}
FirstName = model.FirstName;
LastName = model.LastName;
Password = model.Password;
PhoneNumber = model.PhoneNumber;
Login = model.Login;
Email = model.Email;
RoleID = model.RoleID;
}
public ClientViewModel GetViewModel => new()
{
ID = ID,
FirstName = FirstName,
LastName = LastName,
Password = Password,
PhoneNumber = PhoneNumber,
Login = Login,
Email = Email,
RoleID = RoleID
};
}
}