Merge branch 'Storekeeper' into Worker_Raspaev
This commit is contained in:
commit
0829a31e13
@ -0,0 +1,122 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.BuisnessLogicsContracts;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
|
||||
{
|
||||
public class ComponentLogic : IComponentLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_componentStorage = componentStorage;
|
||||
}
|
||||
public bool Create(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||
if (_componentStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ComponentViewModel? ReadElement(ComponentSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ComponentName: {ComponentName}. Id: {Id}",
|
||||
model.ComponentName, model.Id);
|
||||
var element = _componentStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName: {ComponentName}. Id: {Id}",
|
||||
model?.ComponentName, model?.Id);
|
||||
var list = model == null ? _componentStorage.GetFullList() :
|
||||
_componentStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(ComponentBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_componentStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ComponentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия комплектующего", nameof(model.ComponentName));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена комплектующего должна быть больше 0",
|
||||
nameof(model.Cost));
|
||||
}
|
||||
if (model.UserId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор у пользователя",
|
||||
nameof(model.UserId));
|
||||
}
|
||||
_logger.LogInformation("Component. ComponentName: {ComponentName}. Cost: {Cost}. Id: {Id}",
|
||||
model.ComponentName, model.Cost, model.Id);
|
||||
var element = _componentStorage.GetElement(new ComponentSearchModel
|
||||
{
|
||||
ComponentName = model.ComponentName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Комплектующее с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.BuisnessLogicsContracts;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
|
||||
{
|
||||
public class GoodLogic : IGoodLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IGoodStorage _goodStorage;
|
||||
public GoodLogic(ILogger<GoodLogic> logger, IGoodStorage goodStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_goodStorage = goodStorage;
|
||||
}
|
||||
public bool Create(GoodBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_goodStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(GoodBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||
if (_goodStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public GoodViewModel? ReadElement(GoodSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. GoodName: {GoodName}. Id: {Id}",
|
||||
model.GoodName, model.Id);
|
||||
var element = _goodStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<GoodViewModel>? ReadList(GoodSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. GoodName: {GoodName}. Id: {Id}",
|
||||
model?.GoodName, model?.Id);
|
||||
var list = model == null ? _goodStorage.GetFullList() :
|
||||
_goodStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(GoodBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_goodStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(GoodBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.GoodName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия товара", nameof(model.GoodName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена товара должна быть больше 0",
|
||||
nameof(model.Price));
|
||||
}
|
||||
if (model.UserId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор у пользователя",
|
||||
nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Good. GoodName: {GoodName}. Price: {Price}. Id: {Id}",
|
||||
model.GoodName, model.Price, model.Id);
|
||||
var element = _goodStorage.GetElement(new GoodSearchModel
|
||||
{
|
||||
GoodName = model.GoodName
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Товар с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.BuisnessLogicsContracts;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HardwareShopBusinessLogic.BusinessLogics.Storekeeper
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (model.Status != OrderStatus.Неизвестен)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
model.Status = OrderStatus.Принят;
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
model.Status = OrderStatus.Неизвестен;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("Order. OrderId: {Id}", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (viewModel == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (viewModel.Status + 1 != newStatus)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
model.Status = newStatus;
|
||||
if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now;
|
||||
else
|
||||
{
|
||||
model.DateImplement = viewModel.DateImplement;
|
||||
}
|
||||
CheckModel(model, false);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.GoodId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор у товара", nameof(model.GoodId));
|
||||
}
|
||||
if (model.UserId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор у пользователя", nameof(model.UserId));
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество товара в заказе должно быть больше 0", nameof(model.Count));
|
||||
}
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("Order. OrderId: {Id}. Sum: {Sum}. GoodId: {GoodId}", model.Id, model.Sum, model.GoodId);
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выдан);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,128 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.BusinessLogicsContracts;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HardwareShopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class UserLogic : IUserLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUserStorage _userStorage;
|
||||
public UserLogic(ILogger<UserLogic> logger, IUserStorage userStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_userStorage = userStorage;
|
||||
}
|
||||
public bool Create(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_userStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||
if (_userStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public UserViewModel? ReadElement(UserSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Login: {Login}. Email: {Email}. Id: {Id}.",
|
||||
model.Login, model.Email, model.Id);
|
||||
var element = _userStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<UserViewModel>? ReadList(UserSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Login: {Login}. Email: {Email}. Id: {Id}.",
|
||||
model?.Login, model?.Email, model?.Id);
|
||||
var list = model == null ? _userStorage.GetFullList() :
|
||||
_userStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public bool Update(UserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_userStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(UserBindingModel 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.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("User. Login: {Login}. Email: {Email}. Id: {Id}",
|
||||
model.Login, model.Email, model.Id);
|
||||
var elementLogin = _userStorage.GetElement(new UserSearchModel
|
||||
{
|
||||
Login = model.Login
|
||||
});
|
||||
var elementEmail = _userStorage.GetElement(new UserSearchModel
|
||||
{
|
||||
Email = model.Email
|
||||
});
|
||||
if (elementEmail != null && elementEmail.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Клиент с такой почтой уже есть");
|
||||
}
|
||||
if (elementLogin != null && elementLogin.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Клиент с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,10 +6,6 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="BusinessLogics\Storekeeper\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
</ItemGroup>
|
||||
|
@ -1,39 +0,0 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
{
|
||||
public class UserStorage : IUserStorage
|
||||
{
|
||||
public UserViewModel? Delete(UserBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserViewModel? GetElement(UserSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<UserViewModel> GetFilteredList(UserSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<UserViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserViewModel? Insert(UserBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserViewModel? Update(UserBindingModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement.Models;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Implements
|
||||
{
|
||||
public class UserStorage : IUserStorage
|
||||
{
|
||||
public UserViewModel? Delete(UserBindingModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
var element = context.Users
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Users.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserViewModel? GetElement(UserSearchModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
if (model.Id.HasValue)
|
||||
return context.Users
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
|
||||
return context.Users
|
||||
.FirstOrDefault(x => x.Email
|
||||
.Equals(model.Email) && x.Password
|
||||
.Equals(model.Password))?
|
||||
.GetViewModel;
|
||||
if (!string.IsNullOrEmpty(model.Email))
|
||||
return context.Users
|
||||
.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<UserViewModel> GetFilteredList(UserSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Users
|
||||
.Where(x => x.Login.Contains(model.Login))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<UserViewModel> GetFullList()
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
return context.Users
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public UserViewModel? Insert(UserBindingModel model)
|
||||
{
|
||||
var newUser = User.Create(model);
|
||||
if (newUser == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new HardwareShopDatabase();
|
||||
context.Users.Add(newUser);
|
||||
context.SaveChanges();
|
||||
return newUser.GetViewModel;
|
||||
}
|
||||
|
||||
public UserViewModel? Update(UserBindingModel model)
|
||||
{
|
||||
using var context = new HardwareShopDatabase();
|
||||
var user = context.Users
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (user == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
user.Update(model);
|
||||
context.SaveChanges();
|
||||
return user.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
public class BuildStorage : IBuildStorage
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
public class CommentStorage : ICommentStorage
|
||||
{
|
||||
|
@ -1,12 +1,11 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement;
|
||||
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HardwareShopContracts.StoragesContracts
|
||||
namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
{
|
||||
public class PurchaseStorage : IPurchaseStorage
|
||||
{
|
||||
|
@ -0,0 +1,55 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.BusinessLogicsContracts;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace HardwareShopRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ClientController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IUserLogic _logic;
|
||||
|
||||
public ClientController(IUserLogic logic, ILogger<ClientController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public UserViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new UserSearchModel
|
||||
{
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(UserBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
HardwareShop/HardwareShopRestApi/HardwareShopRestApi.csproj
Normal file
20
HardwareShop/HardwareShopRestApi/HardwareShopRestApi.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HardwareShopBusinessLogic\HardwareShopBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\HardwareShopContracts\HardwareShopContracts.csproj" />
|
||||
<ProjectReference Include="..\HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
58
HardwareShop/HardwareShopRestApi/Program.cs
Normal file
58
HardwareShop/HardwareShopRestApi/Program.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using HardwareShopBusinessLogic.BusinessLogics;
|
||||
using HardwareShopBusinessLogic.BusinessLogics.Storekeeper;
|
||||
using HardwareShopContracts.BuisnessLogicsContracts;
|
||||
using HardwareShopContracts.BusinessLogicsContracts;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopDatabaseImplement.Implements;
|
||||
using HardwareShopDatabaseImplement.Implements.Storekeeper;
|
||||
using HardwareShopDatabaseImplement.Implements.Worker;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using NLog.Extensions.Logging;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Logging.SetMinimumLevel(LogLevel.Information);
|
||||
builder.Logging.AddNLog("nlog.config");
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddTransient<IUserStorage, UserStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IGoodStorage, GoodStorage>();
|
||||
builder.Services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
|
||||
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
|
||||
builder.Services.AddTransient<IBuildStorage, BuildStorage>();
|
||||
builder.Services.AddTransient<ICommentStorage, CommentStorage>();
|
||||
|
||||
builder.Services.AddTransient<IUserLogic, UserLogic>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IGoodLogic, GoodLogic>();
|
||||
builder.Services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
builder.Services.AddTransient<IPurchaseLogic, PurchaseLogic>();
|
||||
builder.Services.AddTransient<IBuildLogic, BuildLogic>();
|
||||
builder.Services.AddTransient<ICommentLogic, CommentLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "HardwareShopRestApi", Version = "v1" });
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "HardwareShopRestApi v1"));
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:45313",
|
||||
"sslPort": 44367
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"HardwareShopRestApi": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7205;http://localhost:5205",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
HardwareShop/HardwareShopRestApi/appsettings.json
Normal file
9
HardwareShop/HardwareShopRestApi/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
15
HardwareShop/HardwareShopRestApi/nlog.config
Normal file
15
HardwareShop/HardwareShopRestApi/nlog.config
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.3.32929.385
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopView", "HardwareShopView\HardwareShopView.csproj", "{14E5377A-FF6B-4FBA-B18A-5F6EB513123C}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopDataModels", "HardwareShopDataModels\HardwareShopDataModels.csproj", "{1589524F-918D-40B8-A44B-8C7FCABFD29A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HardwareShopDataModels", "HardwareShopDataModels\HardwareShopDataModels.csproj", "{1589524F-918D-40B8-A44B-8C7FCABFD29A}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopContracts", "HardwareShopContracts\HardwareShopContracts.csproj", "{91B12343-FCFB-4B7D-BBB8-C6A2C9D73996}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HardwareShopContracts", "HardwareShopContracts\HardwareShopContracts.csproj", "{91B12343-FCFB-4B7D-BBB8-C6A2C9D73996}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopBusinessLogic", "HardwareShopBusinessLogic\HardwareShopBusinessLogic.csproj", "{3B96A73E-3385-4712-A7C4-9D67D424CE43}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HardwareShopBusinessLogic", "HardwareShopBusinessLogic\HardwareShopBusinessLogic.csproj", "{3B96A73E-3385-4712-A7C4-9D67D424CE43}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HardwareShopDatabaseImplement", "HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj", "{1E5156F6-1F67-497C-A660-8AC61BC451BC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HardwareShopDatabaseImplement", "HardwareShopDatabaseImplement\HardwareShopDatabaseImplement.csproj", "{1E5156F6-1F67-497C-A660-8AC61BC451BC}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HardwareShopRestApi", "HardwareShopRestApi\HardwareShopRestApi.csproj", "{623AF3E7-85DA-4DB7-BC0E-8D669CEE9402}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -19,10 +19,6 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{14E5377A-FF6B-4FBA-B18A-5F6EB513123C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{14E5377A-FF6B-4FBA-B18A-5F6EB513123C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{14E5377A-FF6B-4FBA-B18A-5F6EB513123C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{14E5377A-FF6B-4FBA-B18A-5F6EB513123C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1589524F-918D-40B8-A44B-8C7FCABFD29A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1589524F-918D-40B8-A44B-8C7FCABFD29A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1589524F-918D-40B8-A44B-8C7FCABFD29A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@ -39,6 +35,10 @@ Global
|
||||
{1E5156F6-1F67-497C-A660-8AC61BC451BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1E5156F6-1F67-497C-A660-8AC61BC451BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1E5156F6-1F67-497C-A660-8AC61BC451BC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{623AF3E7-85DA-4DB7-BC0E-8D669CEE9402}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{623AF3E7-85DA-4DB7-BC0E-8D669CEE9402}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{623AF3E7-85DA-4DB7-BC0E-8D669CEE9402}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{623AF3E7-85DA-4DB7-BC0E-8D669CEE9402}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user