fixes in namespaces, added new model and relation with contracts and etc, added res api with crud
This commit is contained in:
parent
c7871c3866
commit
465606f054
@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyContracts"
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssembly", "FurnitureAssembly\FurnitureAssembly.csproj", "{C7E2829D-78C7-400B-8BBB-47FE7B2DB878}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssembly", "FurnitureAssembly\FurnitureAssembly.csproj", "{C7E2829D-78C7-400B-8BBB-47FE7B2DB878}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyBusinessLogic", "FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj", "{D7934CFF-BB47-4F7A-8B6D-2FF213542B5B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyBusinessLogic", "FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj", "{D7934CFF-BB47-4F7A-8B6D-2FF213542B5B}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyRestApi", "FurnitureAssemblyRestApi\FurnitureAssemblyRestApi.csproj", "{61874779-CE96-475E-A17B-69F86C1C5A85}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -39,6 +41,10 @@ Global
|
|||||||
{D7934CFF-BB47-4F7A-8B6D-2FF213542B5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D7934CFF-BB47-4F7A-8B6D-2FF213542B5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D7934CFF-BB47-4F7A-8B6D-2FF213542B5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D7934CFF-BB47-4F7A-8B6D-2FF213542B5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{D7934CFF-BB47-4F7A-8B6D-2FF213542B5B}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D7934CFF-BB47-4F7A-8B6D-2FF213542B5B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{61874779-CE96-475E-A17B-69F86C1C5A85}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{61874779-CE96-475E-A17B-69F86C1C5A85}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{61874779-CE96-475E-A17B-69F86C1C5A85}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{61874779-CE96-475E-A17B-69F86C1C5A85}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -10,7 +10,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace FurnitureAssembly_StorekeeperBusinessLogic.BusinessLogics
|
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class FurnitureLogic: IFurnitureLogic
|
public class FurnitureLogic: IFurnitureLogic
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using FurnitureAssemblyContracts.StorageContracts;
|
|||||||
using FurnitureAssemblyContracts.ViewModels;
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace FurnitureAssembly_Storekeeper_BusinessLogic.BusinessLogics
|
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class MaterialLogic : IMaterialLogic
|
public class MaterialLogic : IMaterialLogic
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,108 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.BusinessLogicContracts;
|
||||||
|
using FurnitureAssemblyContracts.SearchModels;
|
||||||
|
using FurnitureAssemblyContracts.StorageContracts;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class OrderInfoLogic : IOrderInfoLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IOrderInfoStorage _orderInfoStorage;
|
||||||
|
public OrderInfoLogic(ILogger<OrderInfoLogic> logger, IOrderInfoStorage orderInfoStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_orderInfoStorage = orderInfoStorage;
|
||||||
|
}
|
||||||
|
public List<OrderInfoViewModel>? ReadList(OrderInfoSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. OrderInfoId:{Id}", model?.Id);
|
||||||
|
var list = model == null ? _orderInfoStorage.GetFullList() : _orderInfoStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
public OrderInfoViewModel? ReadElement(OrderInfoSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. OrderInfoId:{ Id}", model.Id);
|
||||||
|
var element = _orderInfoStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
public bool Create(OrderInfoBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_orderInfoStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Update(OrderInfoBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_orderInfoStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Update operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public bool Delete(OrderInfoBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_orderInfoStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void CheckModel(OrderInfoBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (model.PaymentType == FurnitureAssemblyDataModels.Enums.PaymentType.Неизвестен)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Неизвестный тип оплаты", nameof(model.PaymentType));
|
||||||
|
}
|
||||||
|
if (model.Sum < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||||
|
}
|
||||||
|
if (model.UserId < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Неправильный Id пользователя", nameof(model.UserId));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("OrderInfo. Id: {Id}.", model.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -94,9 +94,9 @@ namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("Некорректный идентификатор гарнитура", nameof(model.SetId));
|
throw new ArgumentNullException("Некорректный идентификатор гарнитура", nameof(model.SetId));
|
||||||
}
|
}
|
||||||
if (model.Sum < 0)
|
if (model.OrderInfoId < 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
throw new ArgumentNullException("Некорректный индентификатор order_info", nameof(model.OrderInfoId));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Order. Id: {Id}. SetId: {SetId}", model.Id, model.SetId);
|
_logger.LogInformation("Order. Id: {Id}. SetId: {SetId}", model.Id, model.SetId);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ using FurnitureAssemblyContracts.StorageContracts;
|
|||||||
using FurnitureAssemblyContracts.ViewModels;
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace FurnitureAssembly_Storekeeper_BusinessLogic.BusinessLogics
|
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class ScopeLogic : IScopeLogic
|
public class ScopeLogic : IScopeLogic
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
namespace FurnitureAssemblyBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
internal class UserLogic : IUserLogic
|
public class UserLogic : IUserLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IUserStorage _userStorage;
|
private readonly IUserStorage _userStorage;
|
||||||
|
@ -13,11 +13,8 @@ namespace FurnitureAssemblyContracts.BindingModels
|
|||||||
public class OrderBindingModel : IOrderModel
|
public class OrderBindingModel : IOrderModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string CustomerName { get; set; } = string.Empty;
|
|
||||||
public PaymentType PaymentType { get; set; } = PaymentType.Неизвестен;
|
|
||||||
public int SetId { get; set; }
|
public int SetId { get; set; }
|
||||||
public DateTime DateCreate { get; set; }
|
public int OrderInfoId { get; set; }
|
||||||
public double Sum { get; set; }
|
public int Count { get; set; }
|
||||||
public int UserId { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
using FurnitureAssemblyDataModels.Enums;
|
||||||
|
using FurnitureAssemblyDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class OrderInfoBindingModel : IOrderInfoModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string CustomerName { get; set; } = string.Empty;
|
||||||
|
public PaymentType PaymentType { get; set; } = PaymentType.Неизвестен;
|
||||||
|
public DateTime DateCreate { get; set; }
|
||||||
|
public double Sum { get; set; }
|
||||||
|
public int UserId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.SearchModels;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyContracts.BusinessLogicContracts
|
||||||
|
{
|
||||||
|
public interface IOrderInfoLogic
|
||||||
|
{
|
||||||
|
List<OrderInfoViewModel>? ReadList(OrderInfoSearchModel? model);
|
||||||
|
OrderInfoViewModel? ReadElement(OrderInfoSearchModel model);
|
||||||
|
bool Create(OrderInfoBindingModel model);
|
||||||
|
bool Update(OrderInfoBindingModel model);
|
||||||
|
bool Delete(OrderInfoBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class OrderInfoSearchModel
|
||||||
|
{
|
||||||
|
public int? Id { get; set; }
|
||||||
|
public int? UserId { get; set; }
|
||||||
|
public DateTime? DateFrom { get; set; }
|
||||||
|
public DateTime? DateTo { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -9,8 +9,7 @@ namespace FurnitureAssemblyContracts.SearchModels
|
|||||||
public class OrderSearchModel
|
public class OrderSearchModel
|
||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public int? UserId { get; set; }
|
public int? SetId { get; set; }
|
||||||
public DateTime? DateFrom { get; set; }
|
public int? OrderInfoId { get; set; }
|
||||||
public DateTime? DateTo { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.SearchModels;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyContracts.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IOrderInfoStorage
|
||||||
|
{
|
||||||
|
List<OrderInfoViewModel> GetFullList();
|
||||||
|
List<OrderInfoViewModel> GetFilteredList(OrderInfoSearchModel model);
|
||||||
|
OrderInfoViewModel? GetElement(OrderInfoSearchModel model);
|
||||||
|
OrderInfoViewModel? Insert(OrderInfoBindingModel model);
|
||||||
|
OrderInfoViewModel? Update(OrderInfoBindingModel model);
|
||||||
|
OrderInfoViewModel? Delete(OrderInfoBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
using FurnitureAssemblyDataModels.Enums;
|
||||||
|
using FurnitureAssemblyDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class OrderInfoViewModel : IOrderInfoModel
|
||||||
|
{
|
||||||
|
[DisplayName("Номер")]
|
||||||
|
public int Id { get; set; }
|
||||||
|
[DisplayName("Имя заказчика")]
|
||||||
|
public string CustomerName { get; set; } = string.Empty;
|
||||||
|
[DisplayName("Тип оплаты")]
|
||||||
|
public PaymentType PaymentType { get; set; } = PaymentType.Неизвестен;
|
||||||
|
[DisplayName("Дата создания")]
|
||||||
|
public DateTime DateCreate { get; set; }
|
||||||
|
[DisplayName("Сумма")]
|
||||||
|
public double Sum { get; set; }
|
||||||
|
public int UserId { get; set; }
|
||||||
|
[DisplayName("Менеджер")]
|
||||||
|
public string UserName { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -11,21 +11,12 @@ namespace FurnitureAssemblyContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public class OrderViewModel : IOrderModel
|
public class OrderViewModel : IOrderModel
|
||||||
{
|
{
|
||||||
[DisplayName("Номер")]
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Имя заказчика")]
|
|
||||||
public string CustomerName { get; set; } = string.Empty;
|
|
||||||
[DisplayName("Тип оплаты")]
|
|
||||||
public PaymentType PaymentType { get; set; } = PaymentType.Неизвестен;
|
|
||||||
public int SetId { get; set; }
|
public int SetId { get; set; }
|
||||||
[DisplayName("Гарнитур")]
|
[DisplayName("Гарнитур")]
|
||||||
public string SetName { get; set; } = string.Empty;
|
public string SetName { get; set; } = string.Empty;
|
||||||
[DisplayName("Дата создания")]
|
[DisplayName("Количество")]
|
||||||
public DateTime DateCreate { get; set; }
|
public int Count { get; set; }
|
||||||
[DisplayName("Сумма")]
|
public int OrderInfoId { get; set; }
|
||||||
public double Sum { get; set; }
|
|
||||||
public int UserId { get; set; }
|
|
||||||
[DisplayName("Менеджер")]
|
|
||||||
public string UserName { get; set; } = string.Empty;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace FurnitureAssemblyDataModels.Models
|
|||||||
string Name { get; }
|
string Name { get; }
|
||||||
double Cost { get; }
|
double Cost { get; }
|
||||||
DateTime DateCreate { get; }
|
DateTime DateCreate { get; }
|
||||||
Dictionary<int, (IMaterialModel, int)> FurnitureMaterials { get; }
|
|
||||||
int UserId { get; }
|
int UserId { get; }
|
||||||
|
Dictionary<int, (IMaterialModel, int)> FurnitureMaterials { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
using FurnitureAssemblyDataModels.Enums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDataModels.Models
|
||||||
|
{
|
||||||
|
public class IOrderInfoModel
|
||||||
|
{
|
||||||
|
PaymentType PaymentType { get; }
|
||||||
|
DateTime DateCreate { get; }
|
||||||
|
string CustomerName { get; }
|
||||||
|
double Sum { get; }
|
||||||
|
int UserId { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -9,11 +9,8 @@ namespace FurnitureAssemblyDataModels.Models
|
|||||||
{
|
{
|
||||||
public interface IOrderModel : IId
|
public interface IOrderModel : IId
|
||||||
{
|
{
|
||||||
string CustomerName { get; }
|
|
||||||
PaymentType PaymentType { get; }
|
|
||||||
int SetId { get; }
|
int SetId { get; }
|
||||||
int UserId { get; }
|
int OrderInfoId { get; }
|
||||||
double Sum { get; }
|
int Count { get; }
|
||||||
DateTime DateCreate { get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,5 +29,6 @@ namespace FurnitureAssemblyDatabaseImplement
|
|||||||
public virtual DbSet<Scope> Scopes { get; set; }
|
public virtual DbSet<Scope> Scopes { get; set; }
|
||||||
public virtual DbSet<User> Users { get; set; }
|
public virtual DbSet<User> Users { get; set; }
|
||||||
public virtual DbSet<Order> Orders { get; set; }
|
public virtual DbSet<Order> Orders { get; set; }
|
||||||
|
public virtual DbSet<OrderInfo> OrderInfos { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
.Include(x => x.Materials)
|
.Include(x => x.Materials)
|
||||||
.ThenInclude(x => x.Material).ToList()
|
.ThenInclude(x => x.Material).ToList()
|
||||||
.Select(x => x.GetViewModel).ToList();
|
.Select(x => x.GetViewModel).ToList();
|
||||||
|
return context.Furnitures.Include(x => x.FurnitureModules).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
public List<FurnitureViewModel> GetFilteredList(FurnitureSearchModel model)
|
public List<FurnitureViewModel> GetFilteredList(FurnitureSearchModel model)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,117 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.SearchModels;
|
||||||
|
using FurnitureAssemblyContracts.StorageContracts;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDatabaseImplement.Models;
|
||||||
|
using FurnitureAssemblyDataModels.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderInfoStorage : IOrderInfoStorage
|
||||||
|
{
|
||||||
|
public OrderInfoViewModel? Delete(OrderInfoBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
var element = context.OrderInfos.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
var deletedElement = context.OrderInfos
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
context.OrderInfos.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return deletedElement;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public OrderInfoViewModel? GetElement(OrderInfoSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
return context.OrderInfos
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public List<OrderInfoViewModel> GetFilteredList(OrderInfoSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.OrderInfos
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else if (model.DateFrom != null && model.DateTo != null)
|
||||||
|
{
|
||||||
|
return context.OrderInfos
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else if (model.UserId.HasValue)
|
||||||
|
{
|
||||||
|
return context.OrderInfos
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Where(x => x.UserId == model.UserId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<OrderInfoViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
return context.OrderInfos
|
||||||
|
.Include(x => x.User)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public OrderInfoViewModel? Insert(OrderInfoBindingModel model)
|
||||||
|
{
|
||||||
|
var newOrderInfo = OrderInfo.Create(model);
|
||||||
|
if (newOrderInfo == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
context.OrderInfos.Add(newOrderInfo);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.OrderInfos
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(x => x.Id == newOrderInfo.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public OrderInfoViewModel? Update(OrderInfoBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
var orderInfo = context.OrderInfos.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (orderInfo == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
orderInfo.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.OrderInfos
|
||||||
|
.Include(x => x.User)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
var deletedElement = context.Orders
|
var deletedElement = context.Orders
|
||||||
.Include(x => x.Set)
|
.Include(x => x.Set)
|
||||||
.Include(x => x.User)
|
.Include(x => x.OrderInfoId)
|
||||||
.FirstOrDefault(x => x.Id == model.Id)
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
@ -40,7 +40,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Set)
|
.Include(x => x.Set)
|
||||||
.Include(x => x.User)
|
.Include(x => x.OrderInfoId)
|
||||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
@ -51,26 +51,35 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Set)
|
.Include(x => x.Set)
|
||||||
.Include(x => x.User)
|
.Include(x => x.OrderInfoId)
|
||||||
.Where(x => x.Id == model.Id)
|
.Where(x => x.Id == model.Id)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
else if (model.DateFrom != null && model.DateTo != null)
|
else if (model.SetId.HasValue && model.OrderInfoId.HasValue)
|
||||||
{
|
{
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Set)
|
.Include(x => x.Set)
|
||||||
.Include(x => x.User)
|
.Include(x => x.OrderInfoId)
|
||||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
.Where(x => x.SetId == model.SetId && x.OrderInfoId == model.OrderInfoId)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
else if (model.UserId.HasValue)
|
else if (model.SetId.HasValue)
|
||||||
{
|
{
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Set)
|
.Include(x => x.Set)
|
||||||
.Include(x => x.User)
|
.Include(x => x.OrderInfoId)
|
||||||
.Where(x => x.UserId == model.UserId)
|
.Where(x => x.SetId == model.SetId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else if (model.OrderInfoId.HasValue)
|
||||||
|
{
|
||||||
|
return context.Orders
|
||||||
|
.Include(x => x.Set)
|
||||||
|
.Include(x => x.OrderInfoId)
|
||||||
|
.Where(x => x.OrderInfoId == model.OrderInfoId)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -84,7 +93,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
using var context = new FurnitureAssemblyDatabase();
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Set)
|
.Include(x => x.Set)
|
||||||
.Include(x => x.User)
|
.Include(x => x.OrderInfoId)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
@ -100,7 +109,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Set)
|
.Include(x => x.Set)
|
||||||
.Include(x => x.User)
|
.Include(x => x.OrderInfoId)
|
||||||
.FirstOrDefault(x => x.Id == newOrder.Id)
|
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
@ -116,7 +125,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
|||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Set)
|
.Include(x => x.Set)
|
||||||
.Include(x => x.User)
|
.Include(x => x.OrderInfoId)
|
||||||
.FirstOrDefault(x => x.Id == model.Id)
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,94 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.SearchModels;
|
||||||
|
using FurnitureAssemblyContracts.StorageContracts;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class RoleStorage : IRoleStorage
|
||||||
|
{
|
||||||
|
public RoleViewModel? Delete(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
var element = context.Roles.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
var deletedElement = context.Roles
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
context.Roles.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return deletedElement;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public RoleViewModel? GetElement(RoleSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
return context.Roles
|
||||||
|
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public List<RoleViewModel> GetFilteredList(RoleSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return context.Roles
|
||||||
|
.Where(x => x.Id == model.Id)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public List<RoleViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
return context.Roles
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
public RoleViewModel? Insert(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
var newRole = Role.Create(model);
|
||||||
|
if (newRole == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
context.Roles.Add(newRole);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.Roles
|
||||||
|
.FirstOrDefault(x => x.Id == newRole.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
public RoleViewModel? Update(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new FurnitureAssemblyDatabase();
|
||||||
|
var role = context.Roles.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (role == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
role.Update(model);
|
||||||
|
context.SaveChanges();
|
||||||
|
return context.Roles
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -163,7 +163,7 @@ namespace FurnitureAssembly_WorkerDatabaseImplement.Migrations
|
|||||||
b.ToTable("Materials");
|
b.ToTable("Materials");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -196,7 +196,7 @@ namespace FurnitureAssembly_WorkerDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasIndex("UserId");
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("Roles");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||||
@ -396,16 +396,16 @@ namespace FurnitureAssembly_WorkerDatabaseImplement.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", "Set")
|
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", "Set")
|
||||||
.WithMany("Orders")
|
.WithMany("Roles")
|
||||||
.HasForeignKey("SetId")
|
.HasForeignKey("SetId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||||
.WithMany("Orders")
|
.WithMany("Roles")
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
@ -487,7 +487,7 @@ namespace FurnitureAssembly_WorkerDatabaseImplement.Migrations
|
|||||||
{
|
{
|
||||||
b.Navigation("FurnitureModules");
|
b.Navigation("FurnitureModules");
|
||||||
|
|
||||||
b.Navigation("Orders");
|
b.Navigation("Roles");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
||||||
@ -498,7 +498,7 @@ namespace FurnitureAssembly_WorkerDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.Navigation("Materials");
|
b.Navigation("Materials");
|
||||||
|
|
||||||
b.Navigation("Orders");
|
b.Navigation("Roles");
|
||||||
|
|
||||||
b.Navigation("Sets");
|
b.Navigation("Sets");
|
||||||
});
|
});
|
||||||
|
@ -209,7 +209,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
|||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "Orders",
|
name: "Roles",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
Id = table.Column<int>(type: "integer", nullable: false)
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
@ -223,15 +223,15 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
|||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
table.PrimaryKey("PK_Roles", x => x.Id);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Orders_Sets_SetId",
|
name: "FK_Roles_Sets_SetId",
|
||||||
column: x => x.SetId,
|
column: x => x.SetId,
|
||||||
principalTable: "Sets",
|
principalTable: "Sets",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_Orders_Users_UserId",
|
name: "FK_Roles_Users_UserId",
|
||||||
column: x => x.UserId,
|
column: x => x.UserId,
|
||||||
principalTable: "Users",
|
principalTable: "Users",
|
||||||
principalColumn: "Id",
|
principalColumn: "Id",
|
||||||
@ -306,13 +306,13 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
|||||||
column: "UserId");
|
column: "UserId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Orders_SetId",
|
name: "IX_Roles_SetId",
|
||||||
table: "Orders",
|
table: "Roles",
|
||||||
column: "SetId");
|
column: "SetId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_Orders_UserId",
|
name: "IX_Roles_UserId",
|
||||||
table: "Orders",
|
table: "Roles",
|
||||||
column: "UserId");
|
column: "UserId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
@ -346,7 +346,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
|||||||
name: "FurnitureModuleFurnitures");
|
name: "FurnitureModuleFurnitures");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "Orders");
|
name: "Roles");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "SetFurnitureModules");
|
name: "SetFurnitureModules");
|
||||||
|
@ -160,7 +160,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
|||||||
b.ToTable("Materials");
|
b.ToTable("Materials");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
@ -193,7 +193,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasIndex("UserId");
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("Roles");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||||
@ -393,16 +393,16 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.Role", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", "Set")
|
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.Set", "Set")
|
||||||
.WithMany("Orders")
|
.WithMany("Roles")
|
||||||
.HasForeignKey("SetId")
|
.HasForeignKey("SetId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
b.HasOne("FurnitureAssembly_WorkerDatabaseImplement.Models.User", "User")
|
||||||
.WithMany("Orders")
|
.WithMany("Roles")
|
||||||
.HasForeignKey("UserId")
|
.HasForeignKey("UserId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
@ -484,7 +484,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
|||||||
{
|
{
|
||||||
b.Navigation("FurnitureModules");
|
b.Navigation("FurnitureModules");
|
||||||
|
|
||||||
b.Navigation("Orders");
|
b.Navigation("Roles");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
modelBuilder.Entity("FurnitureAssembly_WorkerDatabaseImplement.Models.User", b =>
|
||||||
@ -495,7 +495,7 @@ namespace FurnitureAssemblyDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.Navigation("Materials");
|
b.Navigation("Materials");
|
||||||
|
|
||||||
b.Navigation("Orders");
|
b.Navigation("Roles");
|
||||||
|
|
||||||
b.Navigation("Sets");
|
b.Navigation("Sets");
|
||||||
});
|
});
|
||||||
|
@ -15,19 +15,12 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string CustomerName { get; set; } = string.Empty;
|
|
||||||
[Required]
|
|
||||||
public PaymentType PaymentType { get; set; } = PaymentType.Неизвестен;
|
|
||||||
[Required]
|
|
||||||
public int SetId { get; set; }
|
public int SetId { get; set; }
|
||||||
public virtual Set Set { get; set; }
|
public virtual Set Set { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime DateCreate { get; set; }
|
public int Count { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public double Sum { get; set; }
|
public int OrderInfoId { get; set; }
|
||||||
[Required]
|
|
||||||
public int UserId { get; set; }
|
|
||||||
public virtual User User { get; set; }
|
|
||||||
public static Order? Create(OrderBindingModel? model)
|
public static Order? Create(OrderBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -37,12 +30,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
CustomerName = model.CustomerName,
|
|
||||||
PaymentType = model.PaymentType,
|
|
||||||
SetId = model.SetId,
|
SetId = model.SetId,
|
||||||
Sum = model.Sum,
|
Count = model.Count,
|
||||||
DateCreate = model.DateCreate,
|
OrderInfoId = model.OrderInfoId
|
||||||
UserId = model.UserId
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(OrderBindingModel? model)
|
public void Update(OrderBindingModel? model)
|
||||||
@ -51,22 +41,18 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CustomerName = model.CustomerName;
|
|
||||||
PaymentType = model.PaymentType;
|
|
||||||
SetId = model.SetId;
|
SetId = model.SetId;
|
||||||
UserId = model.UserId;
|
Count = model.Count;
|
||||||
|
OrderInfoId = model.OrderInfoId;
|
||||||
}
|
}
|
||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
CustomerName = CustomerName,
|
|
||||||
PaymentType = PaymentType,
|
|
||||||
SetId = SetId,
|
SetId = SetId,
|
||||||
SetName = Set.Name,
|
SetName = Set.Name,
|
||||||
DateCreate = DateCreate,
|
Count = Count,
|
||||||
Sum = Sum,
|
OrderInfoId = OrderInfoId
|
||||||
UserId = UserId,
|
|
||||||
UserName = User.Name
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDataModels.Enums;
|
||||||
|
using FurnitureAssemblyDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class OrderInfo : IOrderInfoModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
[Required]
|
||||||
|
public string CustomerName { get; set; } = string.Empty;
|
||||||
|
[Required]
|
||||||
|
public PaymentType PaymentType { get; set; } = PaymentType.Неизвестен;
|
||||||
|
[Required]
|
||||||
|
public DateTime DateCreate { get; set; }
|
||||||
|
[Required]
|
||||||
|
public double Sum { get; set; }
|
||||||
|
[Required]
|
||||||
|
public int UserId { get; set; }
|
||||||
|
public virtual User User { get; set; }
|
||||||
|
public static OrderInfo? Create(OrderInfoBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new OrderInfo()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
CustomerName = model.CustomerName,
|
||||||
|
PaymentType = model.PaymentType,
|
||||||
|
Sum = model.Sum,
|
||||||
|
DateCreate = model.DateCreate,
|
||||||
|
UserId = model.UserId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(OrderInfoBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CustomerName = model.CustomerName;
|
||||||
|
PaymentType = model.PaymentType;
|
||||||
|
UserId = model.UserId;
|
||||||
|
}
|
||||||
|
public OrderInfoViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
CustomerName = CustomerName,
|
||||||
|
PaymentType = PaymentType,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
Sum = Sum,
|
||||||
|
UserId = UserId,
|
||||||
|
UserName = User.Name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,650 @@
|
|||||||
|
using DocumentFormat.OpenXml.Spreadsheet;
|
||||||
|
using FurnitureAssemblyContracts.BindingModels;
|
||||||
|
using FurnitureAssemblyContracts.BusinessLogicContracts;
|
||||||
|
using FurnitureAssemblyContracts.SearchModels;
|
||||||
|
using FurnitureAssemblyContracts.ViewModels;
|
||||||
|
using FurnitureAssemblyDatabaseImplement.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace FurnitureAssemblyRestApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class MainController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IFurnitureLogic _furniture;
|
||||||
|
private readonly IFurnitureModuleLogic _furnitureModule;
|
||||||
|
private readonly IMaterialLogic _material;
|
||||||
|
private readonly IOrderInfoLogic _orderInfo;
|
||||||
|
private readonly IOrderLogic _order;
|
||||||
|
private readonly IRoleLogic _role;
|
||||||
|
private readonly IScopeLogic _scope;
|
||||||
|
private readonly ISetLogic _set;
|
||||||
|
private readonly IUserLogic _user;
|
||||||
|
public MainController(ILogger<MainController> logger,
|
||||||
|
IFurnitureLogic furniture,
|
||||||
|
IFurnitureModuleLogic furnitureModule,
|
||||||
|
IMaterialLogic material,
|
||||||
|
IOrderInfoLogic orderInfo,
|
||||||
|
IOrderLogic order,
|
||||||
|
IRoleLogic role,
|
||||||
|
IScopeLogic scope,
|
||||||
|
ISetLogic set,
|
||||||
|
IUserLogic user)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_furniture = furniture;
|
||||||
|
_furnitureModule = furnitureModule;
|
||||||
|
_material = material;
|
||||||
|
_orderInfo = orderInfo;
|
||||||
|
_order = order;
|
||||||
|
_role = role;
|
||||||
|
_scope = scope;
|
||||||
|
_set = set;
|
||||||
|
_user = user;
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public List<FurnitureViewModel>? GetFurnitureList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _furniture.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка мебели");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public FurnitureViewModel? GetFurniture(int Id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _furniture.ReadElement(new FurnitureSearchModel { Id = Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения мебели по id={Id}", Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void AddFurniture(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_furniture.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания мебели");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPut]
|
||||||
|
public void UpdateFurniture(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_furniture.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления мебели");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteFurniture(FurnitureBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_furniture.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления мебели");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<FurnitureModuleViewModel>? GetFurnitureModuleList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _furnitureModule.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка мебельных модулей");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public FurnitureModuleViewModel? GetFurnitureModule(int Id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _furnitureModule.ReadElement(new FurnitureModuleSearchModel { Id = Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения мебельного модуля по id={Id}", Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void AddFurnitureModule(FurnitureModuleBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_furnitureModule.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания мебельного модуля");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPut]
|
||||||
|
public void UpdateFurnitureModule(FurnitureModuleBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_furnitureModule.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления мебельного модуля");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteFurnitureModule(FurnitureModuleBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_furnitureModule.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления мебельного модуля");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<MaterialViewModel>? GetMaterialList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _material.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка материалов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public MaterialViewModel? GetMaterial(int Id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _material.ReadElement(new MaterialSearchModel { Id = Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения материала по id={Id}", Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void AddMaterial(MaterialBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_material.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPut]
|
||||||
|
public void UpdateMaterial(MaterialBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_material.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteMaterial(MaterialBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_material.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<OrderViewModel>? GetOrderList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _order.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка материалов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public OrderViewModel? GetOrder(int Id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _order.ReadElement(new OrderSearchModel { Id = Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения материала по id={Id}", Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void AddOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_order.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPut]
|
||||||
|
public void UpdateOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_order.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_order.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<OrderInfoViewModel>? GetOrderInfoList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _orderInfo.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка материалов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public OrderInfoViewModel? GetOrderInfo(int Id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _orderInfo.ReadElement(new OrderInfoSearchModel { Id = Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения материала по id={Id}", Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void AddOrderInfo(OrderInfoBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_orderInfo.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPut]
|
||||||
|
public void UpdateOrderInfo(OrderInfoBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_orderInfo.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteOrderInfo(OrderInfoBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_orderInfo.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<RoleViewModel>? GetRoleList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _role.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка материалов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public RoleViewModel? GetRole(int Id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _role.ReadElement(new RoleSearchModel { Id = Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения материала по id={Id}", Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void AddRole(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_role.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPut]
|
||||||
|
public void UpdateRole(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_role.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteRole(RoleBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_role.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<ScopeViewModel>? GetScopeList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _scope.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка материалов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public ScopeViewModel? GetScope(int Id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _scope.ReadElement(new ScopeSearchModel { Id = Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения материала по id={Id}", Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void AddScope(ScopeBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_scope.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPut]
|
||||||
|
public void UpdateScope(ScopeBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_scope.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteScope(ScopeBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_scope.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<SetViewModel>? GetSetList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _set.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка материалов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public SetViewModel? GetSet(int Id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _set.ReadElement(new SetSearchModel { Id = Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения материала по id={Id}", Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void AddSet(SetBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_set.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPut]
|
||||||
|
public void UpdateSet(SetBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_set.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteSet(SetBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_set.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<UserViewModel>? GetUserList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _user.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка материалов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public UserViewModel? GetUser(int Id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _user.ReadElement(new UserSearchModel { Id = Id });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения материала по id={Id}", Id);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void AddUser(UserBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_user.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPut]
|
||||||
|
public void UpdateUser(UserBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_user.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpDelete]
|
||||||
|
public void DeleteUser(UserBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_user.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления материала");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\FurnitureAssemblyContracts\FurnitureAssemblyContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\FurnitureAssemblyDatabaseImplement\FurnitureAssemblyDatabaseImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
56
FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs
Normal file
56
FurnitureAssembly/FurnitureAssemblyRestApi/Program.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using FurnitureAssemblyBusinessLogic.BusinessLogics;
|
||||||
|
using FurnitureAssemblyContracts.BusinessLogicContracts;
|
||||||
|
using FurnitureAssemblyContracts.StorageContracts;
|
||||||
|
using FurnitureAssemblyDatabaseImplement.Implements;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||||
|
builder.Logging.AddLog4Net("log4net.config");
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
builder.Services.AddTransient<IFurnitureModuleStorage, FurnitureModuleStorage>();
|
||||||
|
builder.Services.AddTransient<IFurnitureStorage, FurnitureStorage>();
|
||||||
|
builder.Services.AddTransient<IMaterialStorage, MaterialStorage>();
|
||||||
|
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
|
builder.Services.AddTransient<IOrderInfoStorage, OrderInfoStorage>();
|
||||||
|
builder.Services.AddTransient<IRoleStorage, RoleStorage>();
|
||||||
|
builder.Services.AddTransient<IScopeStorage, ScopeStorage>();
|
||||||
|
builder.Services.AddTransient<ISetStorage, SetStorage>();
|
||||||
|
builder.Services.AddTransient<IUserStorage, UserStorage>();
|
||||||
|
|
||||||
|
builder.Services.AddTransient<IFurnitureModuleLogic, FurnitureModuleLogic>();
|
||||||
|
builder.Services.AddTransient<IFurnitureLogic, FurnitureLogic>();
|
||||||
|
builder.Services.AddTransient<IMaterialLogic, MaterialLogic>();
|
||||||
|
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
builder.Services.AddTransient<IOrderInfoLogic, OrderInfoLogic>();
|
||||||
|
builder.Services.AddTransient<IRoleLogic, RoleLogic>();
|
||||||
|
builder.Services.AddTransient<IScopeLogic, ScopeLogic>();
|
||||||
|
builder.Services.AddTransient<ISetLogic, SetLogic>();
|
||||||
|
builder.Services.AddTransient<IUserLogic, UserLogic>();
|
||||||
|
|
||||||
|
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 = "BlacksmithWorkshopRestApi", 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", "AbstractShopRestApi 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:38599",
|
||||||
|
"sslPort": 44309
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"FurnitureAssemblyRestApi": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:7181;http://localhost:5201",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user