Всё во имя демократии

This commit is contained in:
Игорь Гордеев 2024-05-25 15:04:18 +04:00
parent 741d60317e
commit ea17d23db7
25 changed files with 390 additions and 336 deletions

View File

@ -1,89 +0,0 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class CategoryProductLogic : ICategoryProductLogic
{
private readonly ILogger _logger;
private readonly ICategoryProductStorage _storage;
public CategoryProductLogic(ILogger<CategoryProductLogic> logger, ICategoryProductStorage storage) {
_logger = logger;
_storage = storage;
}
public bool Create(CategoryProductBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null) {
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(CategoryProductBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete. ID:{model.ID}");
if (_storage.Delete(model) == null) {
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Update(CategoryProductBindingModel model)
{
CheckModel(model);
if (_storage.Update(model) == null) {
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public List<CategoryProductViewModel>? ReadList(CategoryProductSearchModel? model)
{
_logger.LogInformation($"ReadList. ID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
if (list == null) {
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation($"ReadList. Count:{list.Count}");
return list;
}
private void CheckModel(CategoryProductBindingModel model, bool withParams = true) {
if (model == null) {
throw new ArgumentNullException(nameof(model));
}
if (!withParams) {
return;
}
if (string.IsNullOrEmpty(model.Name)) {
throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name));
}
_logger.LogInformation($"CategoryProduct. ID:{model.ID}.Name:{model.Name}");
var element = _storage.GetElement(new CategoryProductSearchModel
{
Name = model.Name
});
if (element != null && element.Name != model.Name) {
throw new InvalidOperationException("Категория с таким названием уже есть");
}
}
}
}

View File

@ -12,18 +12,18 @@ using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
internal class UserLogic : IUserLogic
internal class ClientLogic : IClientLogic
{
private readonly ILogger _logger;
private readonly IClientStorage _storage;
public UserLogic(ILogger<UserLogic> logger, IClientStorage storage)
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage storage)
{
_logger = logger;
_storage = storage;
}
public bool Add(UserBindingModel model)
public bool Add(ClientBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null)
@ -34,7 +34,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return true;
}
public bool Update(UserBindingModel model)
public bool Update(ClientBindingModel model)
{
CheckModel(model);
if (_storage.Update(model) == null)
@ -45,7 +45,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return true;
}
public bool Delete(UserBindingModel model)
public bool Delete(ClientBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete.ID:{model.ID}");
@ -64,7 +64,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation($"ReadElement.Login:{model.Login}.ID:{model.ID}");
_logger.LogInformation($"ReadElement.Email:{model.Email}.ID:{model.ID}");
var element = _storage.GetElement(model);
if (element == null)
{
@ -89,7 +89,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return list;
}
private void CheckModel(UserBindingModel model, bool withParams = true)
private void CheckModel(ClientBindingModel model, bool withParams = true)
{
if (model == null)
{
@ -99,41 +99,27 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{
return;
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login));
}
if (string.IsNullOrEmpty(model.FirstName))
{
throw new ArgumentNullException("Нет имени пользователя", nameof(model.FirstName));
}
if (string.IsNullOrEmpty(model.LastName))
{
throw new ArgumentNullException("Нет фамилии пользоватея", nameof(model.LastName));
}
if (string.IsNullOrEmpty(model.Email))
{
throw new ArgumentNullException("Нет почты клиента", nameof(model.Email));
throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email));
}
if (string.IsNullOrEmpty(model.ClientFIO))
{
throw new ArgumentNullException("Нет имени пользователя", nameof(model.ClientFIO));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
}
if (string.IsNullOrEmpty(model.PhoneNumber))
{
throw new ArgumentNullException("Нет номер телефона пользователя", nameof(model.PhoneNumber));
}
_logger.LogInformation($"Client. ID:{model.ID}.RoleID:{model.RoleID}.FirstName:{model.FirstName}." +
$"LastName:{model.LastName}.Password:{model.Password}.PhoneNumber:{model.PhoneNumber}.Login:{model.Login}." +
$"Email:{model.Email}");
_logger.LogInformation($"Client. ID:{model.ID}.ClientFIO:{model.ClientFIO}.Password:{model.Password}.Email:{model.Email}.");
var element = _storage.GetElement(new ClientSearchModel
{
Login = model.Login
Email= model.Email
});
if (element != null && element.Login != model.Login)
if (element != null && element.Email != model.Email)
{
throw new InvalidOperationException("Клиент с таким логином уже есть");
throw new InvalidOperationException("Клиент с такой почтой уже есть");
}
}

View File

@ -0,0 +1,102 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class CostItemLogic : ICostItemLogic
{
private readonly ILogger _logger;
private readonly ICostItemStorage _storage;
public bool Create(CostItemBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Add operation failed");
return false;
}
return true;
}
public bool Delete(CostItemBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete.ID:{model.ID}");
if (_storage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public CostItemViewModel? ReadElement(CostItemSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation($"ReadElement.Name:{model.Name}.ID:{model.ID}");
var element = _storage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement. element not fount");
return null;
}
_logger.LogInformation($"ReadElement.find.ID:{element.ID}");
return element;
}
public List<CostItemViewModel>? ReadList(CostItemSearchModel model)
{
_logger.LogInformation($"ReadList. ClientID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ;
if (list == null)
{
_logger.LogWarning("ReadList. return null list");
return null;
}
_logger.LogInformation($"ReadList.Count:{list.Count}");
return list;
}
public bool Update(CostItemBindingModel model)
{
CheckModel(model);
if (_storage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(CostItemBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation($"CostItem. ID:{model.ID}.EmployeeID:{model.EmployeeID}.Name:{model.Name}.Price:{model.Price}");
var element = _storage.GetElement(new CostItemSearchModel { ID = model.ID });
if (element != null && element.EmployeeID != model.EmployeeID)
{
throw new InvalidOperationException("Продукт с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,117 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class EmployeeLogic : IEmployeeLogic
{
private readonly ILogger _logger;
private readonly IEmployeeStorage _storage;
public bool Add(EmployeeBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Add operation failed");
return false;
}
return true;
}
public bool Delete(EmployeeBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete.ID:{model.ID}");
if (_storage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public EmployeeViewModel? ReadElemet(EmployeeSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation($"ReadElement.Login:{model.Login}.ID:{model.ID}");
var element = _storage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement. element not fount");
return null;
}
_logger.LogInformation($"ReadElement.find.ID:{element.ID}");
return element;
}
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel model)
{
_logger.LogInformation($"ReadList. ClientID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); ;
if (list == null)
{
_logger.LogWarning("ReadList. return null list");
return null;
}
_logger.LogInformation($"ReadList.Count:{list.Count}");
return list;
}
public bool Update(EmployeeBindingModel model)
{
CheckModel(model);
if (_storage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(EmployeeBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Login))
{
throw new ArgumentNullException("Нет логина пользователя", nameof(model.Login));
}
if (string.IsNullOrEmpty(model.EmployeeFIO))
{
throw new ArgumentNullException("Нет имени пользователя", nameof(model.EmployeeFIO));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
}
_logger.LogInformation($"Client. ID:{model.ID}.ClientFIO:{model.EmployeeFIO}.Password:{model.Password}.Email:{model.Login}.");
var element = _storage.GetElement(new EmployeeSearchModel
{
Login = model.Login
});
if (element != null && element.Login != model.Login)
{
throw new InvalidOperationException("Клиент с такой почтой уже есть");
}
}
}
}

View File

@ -25,29 +25,12 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
model.Status = OrderStatus.Принят;
if (_storage.Insert(model) == null) {
_logger.LogInformation("Insert operation failed");
return false;
}
return true;
}
public bool DeliveryOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выдан);
}
public bool FinishOrder(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Готов);
}
public bool TakeOrderInWork(OrderBindingModel model)
{
return StatusUpdate(model, OrderStatus.Выполняется);
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
_logger.LogInformation($"ReadList:ID:{model?.ID}");
@ -73,37 +56,21 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
if (model.Sum <= 0) {
throw new ArgumentNullException("Цена зака должна быть больше 0", nameof(model.Sum));
}
_logger.LogInformation($"Order. ID:{model.ID}.Sum:{model.Sum}.Status:{model.Status}.PaymeantOption:{model.PaymeantOption}." +
$"DateCreate:{model.DateCreate}.DataImplement:{model.DateImplement}");
}
private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus)
{
CheckModel(model, false);
var viewModel = _storage.GetElement(new OrderSearchModel { ID = model.ID });
if (viewModel == null) {
throw new ArgumentNullException(nameof(model));
}
if (viewModel.OrderStatus + 1 != newOrderStatus) {
_logger.LogWarning("Status update to " + newOrderStatus.ToString() + " operation failed.");
return false;
}
model.Status = newOrderStatus;
if (model.Status == OrderStatus.Готов) {
model.DateImplement = DateTime.Now;
}
else {
model.DateImplement = viewModel.DateImplement;
}
if (_storage.Update(model) == null) {
_logger.LogWarning("Update operarion failed");
return false;
}
return true;
_logger.LogInformation($"Order. ID:{model.ID}.Sum:{model.Sum}.DateCreate:{model.DateCreate}.");
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
throw new NotImplementedException();
if (model == null) throw new ArgumentNullException(nameof(model));
_logger.LogInformation($"ReadElement. ID:{model.ID}");
var element = _storage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement. elementn not found");
return null;
}
_logger.LogInformation($"ReadElement find. ID:{element.ID}");
return element;
}
}
}

View File

@ -15,17 +15,66 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
public bool CreatePay(PaymentBindingModel model)
{
throw new NotImplementedException();
CheckModel(model);
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public PaymentViewModel? ReadElement(PaymentSearchModel model)
{
throw new NotImplementedException();
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation($"ReadElement.ProductID:{model.ProductID}.ID:{model.ID}");
var element = _storage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement. element not fount");
return null;
}
_logger.LogInformation($"ReadElement.find.ID:{element.ID}");
return element;
}
public List<PaymentViewModel>? ReadList(PaymentSearchModel? model)
{
throw new NotImplementedException();
_logger.LogInformation($"ReadList. ClientID:{model?.ID}");
/*var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ;
if (list == null)
{
_logger.LogWarning("ReadList. return null list");
return null;
}
_logger.LogInformation($"ReadList.Count:{list.Count}");*/
return null;
}
private void CheckModel(PaymentBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.SumPayment <= 0)
{
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.SumPayment));
}
_logger.LogInformation($"Payment. ID:{model.ID}.ProductID:{model.ProductID}.Sum:{model.SumPayment}.OrderID:{model.OrderID}.PayOption{model.PayOption}");
var element = _storage.GetElement(new PaymentSearchModel { ID = model.ID });
if (element != null && element.PayOption != model.PayOption)
{
throw new InvalidOperationException("Продукт с таким названием уже есть");
}
}
}
}

View File

@ -3,6 +3,7 @@ using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@ -95,8 +96,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
if (model.Price <= 0) {
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
}
_logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}" +
$".CategoryID:{model.CategoryID}");
_logger.LogInformation($"Product. ID:{model.ID}.ProductName:{model.ProductName}.Price:{model.Price}.CostItemID:{model.CostItemID}");
var element = _storage.GetElement(new ProductSearchModel { ProductName = model.ProductName });
if (element != null && element.ProductName != model.ProductName) {
throw new InvalidOperationException("Продукт с таким названием уже есть");

View File

@ -1,38 +0,0 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class ReportLogic : IReportLogic
{
private readonly IOrderStorage _orderStorage;
private readonly IProductStorage _productStorag;
public ReportLogic(IOrderStorage orderStorage, IProductStorage productStorag) {
_orderStorage = orderStorage;
_productStorag = productStorag;
}
// Получение списка заказов за определенный период
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model) {
return _orderStorage.GetFilteredList(new OrderSearchModel {
DateFrom = model.DateFrom,
DateTo = model.DateTo,
}).Select(x => new ReportOrdersViewModel {
ID = x.ID,
DateCreate = x.DateCreate,
Sum = x.Sum,
PaymeantOption = x.PaymeantOption.ToString(),
OrderStatus = x.Status.ToString(),
}).ToList();
}
}
}

View File

@ -1,99 +0,0 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class RoleLogic : IRoleLogic
{
private readonly ILogger _logger;
private readonly IRoleStorage _storage;
public RoleLogic(ILogger<RoleLogic> logger, IRoleStorage storage)
{
_logger = logger;
_storage = storage;
}
public bool Create(RoleBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(RoleBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation($"Delete. ID:{model.ID}");
if (_storage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public bool Update(RoleBindingModel model)
{
CheckModel(model);
if (_storage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public List<RoleViewModel>? ReadList(RoleSearchModel? model)
{
_logger.LogInformation($"ReadList. ID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation($"ReadList. Count:{list.Count}");
return list;
}
private void CheckModel(RoleBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentNullException("Нет названия категории продукта", nameof(model.Name));
}
_logger.LogInformation($"CategoryProduct. ID:{model.ID}.Name:{model.Name}");
var element = _storage.GetElement(new RoleSearchModel
{
Name = model.Name
});
if (element != null && element.Name != model.Name)
{
throw new InvalidOperationException("Такая роль уже есть");
}
}
}
}

View File

@ -9,7 +9,7 @@ namespace ElectronicsShopContracts.BindingModels {
public class CostItemBindingModel : ICostItemModel {
public int ID { get; set; }
public int ClientID { get; set; }
public int EmployeeID { get; set; }
public string Name { get; set; } = string.Empty;

View File

@ -1,4 +1,5 @@
using ElectronicsShopDataModels.Models;
using ElectronicsShopDataModels.Enums;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,12 +12,12 @@ namespace ElectronicsShopContracts.BindingModels
{
public int ID { get; set; }
public int ClientID { get; set; }
public int ProductID { get; set; }
public int OrderID { get; set; }
public double SumPayment { get; set; }
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
}
}

View File

@ -16,7 +16,5 @@ namespace ElectronicsShopContracts.BindingModels
public string ProductName { get; set; } = string.Empty;
public double Price { get; set; }
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
}
}

View File

@ -18,5 +18,6 @@ namespace ElectronicsShopContracts.StorageContracts
EmployeeViewModel? Insert(EmployeeBindingModel model);
EmployeeViewModel? Update(EmployeeBindingModel model);
EmployeeViewModel? Delete(EmployeeBindingModel model);
object GetElement(CostItemSearchModel costItemSearchModel);
}
}

View File

@ -11,7 +11,7 @@ namespace ElectronicsShopContracts.ViewModels {
public class CostItemViewModel : ICostItemModel {
public int ID { get; set; }
public int ClientID { get; set; }
public int EmployeeID { get; set; }
[DisplayName("Название статьи затрат")]
public string Name { get; set; } = string.Empty;

View File

@ -1,4 +1,5 @@
using ElectronicsShopDataModels.Models;
using ElectronicsShopDataModels.Enums;
using ElectronicsShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -17,5 +18,8 @@ namespace ElectronicsShopContracts.ViewModels
[DisplayName("Cумма оплаты продукта")]
public double SumPayment { get; set; }
[DisplayName("Статус оплаты")]
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
}
}

View File

@ -20,7 +20,5 @@ namespace ElectronicsShopContracts.ViewModels
[DisplayName("Стоимость продукта")]
public double Price { get; set; }
[DisplayName("Статус оплаты")]
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
}
}

View File

@ -44,7 +44,6 @@ namespace ElectronicsShopDataBaseImplement.Models
{
return;
}
ID = model.ID;
ClientFIO = model.ClientFIO;
Password = model.Password;
Email = model.Email;

View File

@ -15,7 +15,7 @@ namespace ElectronicsShopDataBaseImplement.Models
{
public int ID { get; set; }
[ForeignKey("ClientID")]
public int ClientID { get; set; }
public int EmployeeID { get; set; }
[Required]
public string Name { get; set; }= string.Empty;
[Required]
@ -30,7 +30,7 @@ namespace ElectronicsShopDataBaseImplement.Models
return new CostItem()
{
ID = model.ID,
ClientID = model.ClientID,
EmployeeID = model.EmployeeID,
Name = model.Name,
Price = model.Price,
};
@ -41,8 +41,7 @@ namespace ElectronicsShopDataBaseImplement.Models
{
return;
}
ID = model.ID;
ClientID = model.ClientID;
EmployeeID = model.EmployeeID;
Name = model.Name;
Price = model.Price;
}
@ -50,7 +49,7 @@ namespace ElectronicsShopDataBaseImplement.Models
public CostItemViewModel GetViewModel => new()
{
ID = ID,
ClientID = ClientID,
EmployeeID = EmployeeID,
Name = Name,
Price = Price,
};

View File

@ -42,7 +42,6 @@ namespace ElectronicsShopDataBaseImplement.Models
{
return;
}
ID = model.ID;
EmployeeFIO = model.EmployeeFIO;
Login = model.Login;
Password = model.Password;

View File

@ -66,7 +66,6 @@ namespace ElectronicsShopDataBaseImplement.Models
{
return;
}
ID = model.ID;
ClientID = model.ClientID;
Sum = model.Sum;
EmployeeID = model.EmployeeID;

View File

@ -0,0 +1,64 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums;
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 Payment : IPaymentModel
{
public int ID { get; set; }
[ForeignKey("ProductID")]
public int ProductID { get; set; }
[ForeignKey("OrderID")]
public int OrderID { get; set; }
[Required]
public double SumPayment { get; set; }
[Required]
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
public static Payment? Create(PaymentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Payment()
{
ID = model.ID,
ProductID = model.ProductID,
OrderID = model.OrderID,
SumPayment = model.SumPayment,
PayOption = model.PayOption,
};
}
public void Update(PaymentBindingModel model)
{
if (model == null)
{
return;
}
ProductID = model.ProductID;
OrderID = model.OrderID;
SumPayment = model.SumPayment;
PayOption = model.PayOption;
}
public PaymentViewModel GetViewModel => new()
{
ID = ID,
ProductID = ProductID,
OrderID = OrderID,
SumPayment = SumPayment,
PayOption = PayOption,
};
}
}

View File

@ -21,7 +21,6 @@ namespace ElectronicsShopDataBaseImplement.Models
public double Price { get; set; }
[ForeignKey("CostItemID")]
public int CostItemID { get; set; }
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неизвестно;
public static Product? Create(ProductBindingModel? model)
{
@ -35,7 +34,6 @@ namespace ElectronicsShopDataBaseImplement.Models
ProductName = model.ProductName,
Price = model.Price,
CostItemID=model.CostItemID,
PayOption=model.PayOption
};
}
public void Update(ProductBindingModel model)
@ -44,11 +42,9 @@ namespace ElectronicsShopDataBaseImplement.Models
{
return;
}
ID = model.ID;
ProductName = model.ProductName;
Price = model.Price;
CostItemID = model.CostItemID;
PayOption = model.PayOption;
}
public ProductViewModel GetViewModel => new()
@ -57,7 +53,6 @@ namespace ElectronicsShopDataBaseImplement.Models
ProductName = ProductName,
Price = Price,
CostItemID = CostItemID,
PayOption = PayOption
};
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ElectronicsShopDataModels.Models {
public interface ICostItemModel : IID{
int ClientID { get; }
int EmployeeID { get; }
string Name { get; }
double Price { get; }
}

View File

@ -1,4 +1,5 @@
using Microsoft.VisualBasic;
using ElectronicsShopDataModels.Enums;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
@ -12,6 +13,7 @@ namespace ElectronicsShopDataModels.Models
int ProductID { get; }
int OrderID { get; }
double SumPayment { get; }
PaymeantOption PayOption { get; }
}
}

View File

@ -12,6 +12,6 @@ namespace ElectronicsShopDataModels.Models
string ProductName { get; }
double Price { get; }
int CostItemID { get; }
PaymeantOption PayOption { get; }
}
}