ааа
This commit is contained in:
parent
6b0a1e44d1
commit
ab1c2c3a88
@ -3,6 +3,7 @@ using BeautySalonContracts.BusinessLogicContracts;
|
||||
using BeautySalonContracts.SearchModels;
|
||||
using BeautySalonContracts.StoragesContracts;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using DocumentFormat.OpenXml.Bibliography;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -102,8 +103,19 @@ namespace BeautySalonBusinesLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Не указана сложность трудозатраты", nameof(model.Difficulty));
|
||||
}
|
||||
_logger.LogInformation("LaborCosts. NumberHours: {NumberHours}. Difficulty: {Difficulty}. Id: {Id}",
|
||||
var element = _laborCostsStorage.GetElement(new LaborCostsSearchModel
|
||||
{
|
||||
NumberHours = model.NumberHours,
|
||||
Difficulty = model.Difficulty,
|
||||
StorekeeperId = model.StorekeeperId
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Такая трудозатрата уже уже есть");
|
||||
}
|
||||
_logger.LogInformation("LaborCosts. NumberHours: {NumberHours}. Difficulty: {Difficulty}. Id: {Id}",
|
||||
model.NumberHours, model.Difficulty, model.Id);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,5 @@ namespace BeautySalonContracts.BindingModels
|
||||
public int NumberHours { get; set; }
|
||||
public string Difficulty { get; set; } = string.Empty;
|
||||
public int StorekeeperId { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ namespace BeautySalonContracts.SearchModels
|
||||
public class LaborCostsSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? StorekeeperId { get; set; }
|
||||
public int? NumberHours { get; set; }
|
||||
public string? Difficulty { get; set; }
|
||||
public int? StorekeeperId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,5 @@ namespace BeautySalonDataModels.Models
|
||||
int NumberHours { get; }
|
||||
string Difficulty { get; }
|
||||
int StorekeeperId { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,12 +35,20 @@ namespace BeautySalonDatabaseImplement.Implements
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.LaborCosts
|
||||
.FirstOrDefault(x => x.NumberHours == model.NumberHours
|
||||
&& x.Difficulty == model.Difficulty
|
||||
&& x.StorekeeperId == model.StorekeeperId)
|
||||
?.GetViewModel;
|
||||
}
|
||||
else
|
||||
{
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.LaborCosts
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
using var context = new BeautySalonDatabase();
|
||||
return context.LaborCosts
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<LaborCostsViewModel> GetFilteredList(LaborCostsSearchModel model)
|
||||
|
@ -68,9 +68,6 @@ namespace BeautySalonDatabaseImplement.Models
|
||||
CosmeticPrice = model.CosmeticPrice,
|
||||
StorekeeperId = model.StorekeeperId,
|
||||
LaborCostId = model.LaborCostId,
|
||||
LaborCost = context.LaborCosts
|
||||
.First(x => x.Id == model.LaborCostId)
|
||||
|
||||
};
|
||||
return cosmetic;
|
||||
}
|
||||
@ -80,9 +77,6 @@ namespace BeautySalonDatabaseImplement.Models
|
||||
Brand = model.Brand;
|
||||
CosmeticPrice = model.CosmeticPrice;
|
||||
LaborCostId = model.LaborCostId;
|
||||
LaborCost = context.LaborCosts
|
||||
.First(x => x.Id == model.LaborCostId);
|
||||
|
||||
}
|
||||
|
||||
public CosmeticViewModel GetViewModel => new()
|
||||
|
@ -1,36 +1,46 @@
|
||||
using BeautySalonBusinesLogic.BusinessLogic;
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.BindingModels;
|
||||
using BeautySalonContracts.BusinessLogicContracts;
|
||||
using BeautySalonContracts.SearchModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using BeautySalonDatabaseImplement.Models;
|
||||
using BeautySalonDataModels.Models;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WorkerWebApp.Controllers
|
||||
using WorkerWebApp;
|
||||
/*
|
||||
namespace BeautySalonRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class OrderController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger logger;
|
||||
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
private readonly IOrderLogic order;
|
||||
private readonly ILaborCostsLogic laborCost;
|
||||
private readonly IProcedureLogic procedure;
|
||||
|
||||
private readonly IServiceLogic _serviceLogic;
|
||||
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Процедура"
|
||||
/// </summary>
|
||||
private readonly IProcedureLogic _procedureLogic;
|
||||
|
||||
public OrderController(ILogger<OrderController> logger, IOrderLogic orderLogic, IProcedureLogic procedureLogic, IServiceLogic serviceLogic)
|
||||
public OrderController(ILogger<OrderController> logger, IOrderLogic order, IProcedureLogic procedure, ILaborCostsLogic laborCost)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
_procedureLogic = procedureLogic;
|
||||
_serviceLogic = serviceLogic;
|
||||
this.logger = logger;
|
||||
this.order = order;
|
||||
this.procedure = procedure;
|
||||
this.laborCost = laborCost;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public OrderViewModel? GetOrder(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return order.ReadElement(new OrderSearchModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Ошибка получения косметики");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -41,199 +51,114 @@ namespace WorkerWebApp.Controllers
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
return View(_orderLogic.ReadList(new OrderSearchModel
|
||||
{
|
||||
WorkerId = APIWorker.Worker.Id,
|
||||
}));
|
||||
return View(order.ReadList(null));
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение заказов по id пользователя (полный список, кот. будет выводиться)
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateOrder()
|
||||
public IActionResult CreateOrders()
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Services = _serviceLogic.ReadList(null);
|
||||
ViewBag.LaborCosts = laborCost.ReadList(new LaborCostsSearchModel
|
||||
{
|
||||
WorkerId = APIWorker.Worker.Id,
|
||||
});
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateOrder(double amount, DateTime datacreate, DateTime dateimplement, List<int> services)
|
||||
public void CreateOrders(string name, string brand, double price, int laborCost)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
if (amount == 0 || datacreate == DateTime.MinValue || dateimplement == DateTime.MinValue || services == null)
|
||||
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(brand) || price <= 0 || laborCost <= 0)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
Dictionary<int, IServiceModel> orderServices = new Dictionary<int, IServiceModel>();
|
||||
foreach (var serviceId in services)
|
||||
order.Create(new OrderBindingModel
|
||||
{
|
||||
orderServices.Add(serviceId, _serviceLogic.ReadElement(new ServiceSearchModel { Id = serviceId })!);
|
||||
}
|
||||
|
||||
_orderLogic.Create(new OrderBindingModel
|
||||
{
|
||||
OrderAmount = amount,
|
||||
DateCreate = datacreate,
|
||||
DateImplement = dateimplement,
|
||||
WorkerId = APIWorker.Worker.Id,
|
||||
OrderServices = orderServices
|
||||
OrderName = name,
|
||||
Brand = brand,
|
||||
OrderPrice = price,
|
||||
LaborCostId = laborCost,
|
||||
WorkerId = APIWorker.Worker.Id
|
||||
});
|
||||
|
||||
Response.Redirect("/Order/Orders");
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult UpdateOrder(int id)
|
||||
public IActionResult UpdateOrders(int id)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Services = _serviceLogic.ReadList(null);
|
||||
ViewBag.LaborCosts = laborCost.ReadList(new LaborCostsSearchModel
|
||||
{
|
||||
WorkerId = APIWorker.Worker.Id,
|
||||
});
|
||||
|
||||
return View(_orderLogic.ReadElement(new OrderSearchModel
|
||||
return View(order.ReadElement(new OrderSearchModel
|
||||
{
|
||||
Id = id
|
||||
}));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateOrder(int id, double amount, DateTime datacreate, DateTime dateimplement, List<int> services)
|
||||
public void UpdateOrders(int id, string name, string brand, double price, int laborCost)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
if (amount == 0 || datacreate == DateTime.MinValue || dateimplement == DateTime.MinValue || services == null)
|
||||
if (string.IsNullOrEmpty(name) || laborCost <= 0)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
Dictionary<int, IServiceModel> orderServices = new Dictionary<int, IServiceModel>();
|
||||
foreach (var serviceId in services)
|
||||
{
|
||||
orderServices.Add(serviceId, _serviceLogic.ReadElement(new ServiceSearchModel { Id = serviceId })!);
|
||||
}
|
||||
|
||||
var order = _orderLogic.ReadElement(new OrderSearchModel { Id = id });
|
||||
_orderLogic.Update(new OrderBindingModel
|
||||
order.Update(new OrderBindingModel
|
||||
{
|
||||
Id = id,
|
||||
OrderAmount = amount,
|
||||
DateCreate = datacreate,
|
||||
DateImplement = dateimplement,
|
||||
WorkerId = APIWorker.Worker.Id,
|
||||
OrderProcedures = order!.OrderProcedures,
|
||||
OrderServices = orderServices
|
||||
OrderName = name,
|
||||
Brand = brand,
|
||||
OrderPrice = price,
|
||||
LaborCostId = laborCost
|
||||
});
|
||||
|
||||
Response.Redirect("/Order/Orders");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить косметику
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public void DeleteOrder(int id)
|
||||
public void DeleteOrders(int id)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
_orderLogic.Delete(new OrderBindingModel
|
||||
order.Delete(new OrderBindingModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
|
||||
Response.Redirect("/Order/Orders");
|
||||
}
|
||||
[HttpGet]
|
||||
public IActionResult CreateOrderProcedure()
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
ViewBag.Orders = _orderLogic.ReadList(new OrderSearchModel
|
||||
{
|
||||
WorkerId = APIWorker.Worker.Id
|
||||
});
|
||||
ViewBag.Procedures = _procedureLogic.ReadList(new ProcedureSearchModel
|
||||
{
|
||||
WorkerId = APIWorker.Worker.Id
|
||||
});
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreatePatientProcedure(int orderId, List<int> procedures)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
if (orderId <= 0 || procedures == null)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
Dictionary<int, IProcedureModel> orderProcedures = new Dictionary<int, IProcedureModel>();
|
||||
foreach (var procedureId in procedures)
|
||||
{
|
||||
orderProcedures.Add(procedureId, _procedureLogic.ReadElement(new ProcedureSearchModel { Id = procedureId })!);
|
||||
}
|
||||
|
||||
var order = _orderLogic.ReadElement(new OrderSearchModel { Id = orderId });
|
||||
_orderLogic.Update(new OrderBindingModel
|
||||
{
|
||||
Id = order!.Id,
|
||||
OrderAmount = order!.OrderAmount,
|
||||
DateCreate = order!.DateCreate,
|
||||
DateImplement = order!.DateImplement,
|
||||
WorkerId = APIWorker.Worker.Id,
|
||||
OrderServices = order!.OrderServices,
|
||||
OrderProcedures = orderProcedures
|
||||
});
|
||||
|
||||
Response.Redirect("/Order/Orders");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public JsonResult GetOrderProcedures(int orderId)
|
||||
{
|
||||
if (APIWorker.Worker == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
var allProcedures = _procedureLogic.ReadList(new ProcedureSearchModel
|
||||
{
|
||||
WorkerId = APIWorker.Worker.Id
|
||||
});
|
||||
|
||||
var order = _orderLogic.ReadElement(new OrderSearchModel { Id = orderId });
|
||||
var orderProceduresIds = order?.OrderProcedures?.Select(x => x.Key).ToList() ?? new List<int>();
|
||||
|
||||
var result = new
|
||||
{
|
||||
allProcedures = allProcedures.Select(r => new { id = r.Id }),
|
||||
orderProceduresIds = orderProceduresIds
|
||||
};
|
||||
|
||||
return Json(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
@ -2,207 +2,94 @@
|
||||
using BeautySalonContracts.BusinessLogicContracts;
|
||||
using BeautySalonContracts.SearchModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using BeautySalonDatabaseImplement.Models;
|
||||
using BeautySalonDataModels.Models;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using StorekeeperWebApp;
|
||||
|
||||
namespace BeautySalonRestApi.Controllers
|
||||
{
|
||||
public class CosmeticController : Controller
|
||||
public class LaborCostsController : Controller
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly ICosmeticLogic cosmetic;
|
||||
private readonly ILaborCostsLogic laborCost;
|
||||
private readonly IProcedureLogic procedure;
|
||||
private readonly ILaborCostsLogic _logic;
|
||||
|
||||
public CosmeticController(ILogger<CosmeticController> logger, ICosmeticLogic cosmetic, IProcedureLogic procedure, ILaborCostsLogic laborCost)
|
||||
public LaborCostsController(ILaborCostsLogic logic, ILogger<LaborCostsController> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.cosmetic = cosmetic;
|
||||
this.procedure = procedure;
|
||||
this.laborCost = laborCost;
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public CosmeticViewModel? GetCosmetic(int id)
|
||||
public LaborCostsViewModel? GetLaborCosts(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return cosmetic.ReadElement(new CosmeticSearchModel
|
||||
return _logic.ReadElement(new LaborCostsSearchModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Ошибка получения косметики");
|
||||
_logger.LogError(ex, "Ошибка получения трудозатраты");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Cosmetics()
|
||||
public List<LaborCostsViewModel>? GetAllLaborCosts()
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
try
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
return _logic.ReadList(null);
|
||||
}
|
||||
|
||||
return View(cosmetic.ReadList(null));
|
||||
}
|
||||
|
||||
/*[HttpGet]
|
||||
public IActionResult CreateCosmetics()
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
_logger.LogError(ex, "Ошибка получения списка трудозатрат");
|
||||
throw;
|
||||
}
|
||||
|
||||
ViewBag.Procedures = procedure.ReadList(null);
|
||||
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateCosmetics(CosmeticBindingModel model, int[] procedureIds)
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
var procedures = procedure.ReadList(null);
|
||||
if (model.Id == 0)
|
||||
{
|
||||
model.StorekeeperId = APIStorekeeper.Storekeeper.Id;
|
||||
for (int i = 0; i < procedureIds.Length; i++)
|
||||
{
|
||||
var procedure = procedures!.FirstOrDefault(x => x.Id == procedureIds[i])!;
|
||||
model.CosmeticProcedures.Add(i, procedure);
|
||||
}
|
||||
if (cosmetic.Create(model))
|
||||
Response.Redirect("/Cosmetic/Cosmetics");
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < procedureIds.Length; i++)
|
||||
{
|
||||
var procedure = procedures!.FirstOrDefault(x => x.Id == procedureIds[i])!;
|
||||
model.CosmeticProcedures.Add(i, procedure);
|
||||
}
|
||||
model.StorekeeperId = APIStorekeeper.Storekeeper.Id;
|
||||
if (cosmetic.Create(model))
|
||||
Response.Redirect("/Cosmetic/Cosmetics");
|
||||
}
|
||||
}*/
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateCosmetics()
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.LaborCosts = laborCost.ReadList(new LaborCostsSearchModel
|
||||
{
|
||||
StorekeeperId = APIStorekeeper.Storekeeper.Id,
|
||||
});
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateCosmetics(string name, string brand, double price, int laborCost)
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(brand) || price <= 0 || laborCost <= 0)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
cosmetic.Create(new CosmeticBindingModel
|
||||
{
|
||||
CosmeticName = name,
|
||||
Brand = brand,
|
||||
CosmeticPrice = price,
|
||||
LaborCostId = laborCost,
|
||||
StorekeeperId = APIStorekeeper.Storekeeper.Id
|
||||
});
|
||||
|
||||
Response.Redirect("/Cosmetic/Cosmetics");
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult UpdateCosmetics(int id)
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.LaborCosts = laborCost.ReadList(new LaborCostsSearchModel
|
||||
{
|
||||
StorekeeperId = APIStorekeeper.Storekeeper.Id,
|
||||
});
|
||||
|
||||
return View(cosmetic.ReadElement(new CosmeticSearchModel
|
||||
{
|
||||
Id = id
|
||||
}));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateCosmetics(int id, string name, string brand, double price, int laborCost)
|
||||
public void CreateLaborCosts(LaborCostsBindingModel model)
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
try
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
_logic.Create(model);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(name) || laborCost <= 0)
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
_logger.LogError(ex, "Ошибка создания трудозатраты");
|
||||
throw;
|
||||
}
|
||||
|
||||
cosmetic.Update(new CosmeticBindingModel
|
||||
{
|
||||
Id = id,
|
||||
CosmeticName = name,
|
||||
Brand = brand,
|
||||
CosmeticPrice = price,
|
||||
LaborCostId = laborCost
|
||||
});
|
||||
|
||||
Response.Redirect("/Cosmetic/Cosmetics");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить косметику
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public void DeleteCosmetics(int id)
|
||||
[HttpPost]
|
||||
public void UpdateLaborCosts(LaborCostsBindingModel model)
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
try
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
_logic.Update(model);
|
||||
}
|
||||
|
||||
cosmetic.Delete(new CosmeticBindingModel
|
||||
catch (Exception ex)
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
_logger.LogError(ex, "Ошибка обновления трудозатраты");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
Response.Redirect("/Cosmetic/Cosmetics");
|
||||
[HttpDelete]
|
||||
public void DeleteLaborCosts(LaborCostsBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления трудозатраты");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,94 +2,179 @@
|
||||
using BeautySalonContracts.BusinessLogicContracts;
|
||||
using BeautySalonContracts.SearchModels;
|
||||
using BeautySalonContracts.ViewModels;
|
||||
using BeautySalonDatabaseImplement.Models;
|
||||
using BeautySalonDataModels.Models;
|
||||
using DocumentFormat.OpenXml.Bibliography;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using StorekeeperWebApp;
|
||||
|
||||
namespace BeautySalonRestApi.Controllers
|
||||
{
|
||||
public class LaborCostsController : Controller
|
||||
public class LaborCostController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly ILogger logger;
|
||||
|
||||
private readonly ILaborCostsLogic _logic;
|
||||
private readonly ILaborCostsLogic laborCost;
|
||||
private readonly ICosmeticLogic cosmetic;
|
||||
|
||||
public LaborCostsController(ILaborCostsLogic logic, ILogger<LaborCostsController> logger)
|
||||
public LaborCostController(ILogger<LaborCostController> logger, ILaborCostsLogic laborCost, ICosmeticLogic cosmetic)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
this.logger = logger;
|
||||
this.laborCost = laborCost;
|
||||
this.cosmetic = cosmetic;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public LaborCostsViewModel? GetLaborCosts(int id)
|
||||
public LaborCostsViewModel? GetLaborCost(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new LaborCostsSearchModel
|
||||
return laborCost.ReadElement(new LaborCostsSearchModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения трудозатраты");
|
||||
logger.LogError(ex, "Ошибка получения трудозатраты");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<LaborCostsViewModel>? GetAllLaborCosts()
|
||||
public IActionResult LaborCosts()
|
||||
{
|
||||
try
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
return _logic.ReadList(null);
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
return View(laborCost.ReadList(null));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateLaborCosts()
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel
|
||||
{
|
||||
StorekeeperId = APIStorekeeper.Storekeeper.Id,
|
||||
});
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateLaborCosts(int hours, string difficulty, int cosmeticId)
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
|
||||
if (hours <= 0 || string.IsNullOrEmpty(difficulty) || cosmeticId <= 0)
|
||||
{
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
laborCost.Create(new LaborCostsBindingModel
|
||||
{
|
||||
NumberHours = hours,
|
||||
Difficulty = difficulty,
|
||||
StorekeeperId = APIStorekeeper.Storekeeper.Id
|
||||
});
|
||||
|
||||
var labor = laborCost.ReadElement(new LaborCostsSearchModel {
|
||||
NumberHours = hours,
|
||||
Difficulty = difficulty,
|
||||
StorekeeperId = APIStorekeeper.Storekeeper.Id
|
||||
});
|
||||
|
||||
var cosm = cosmetic.ReadElement(new CosmeticSearchModel{ Id = cosmeticId });
|
||||
if (cosm != null && labor != null)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка трудозатрат");
|
||||
throw;
|
||||
cosm.LaborCostId = labor.Id; // Присваиваем айди трудозатраты к объекту косметики
|
||||
cosmetic.Update(new CosmeticBindingModel
|
||||
{
|
||||
Id = cosm.Id,
|
||||
CosmeticName = cosm.CosmeticName,
|
||||
Brand = cosm.Brand,
|
||||
CosmeticPrice = cosm.CosmeticPrice,
|
||||
LaborCostId = cosm.LaborCostId
|
||||
});
|
||||
}
|
||||
|
||||
Response.Redirect("/LaborCost/LaborCosts");
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult UpdateLaborCosts(int id)
|
||||
{
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
|
||||
ViewBag.Cosmetics = cosmetic.ReadList(new CosmeticSearchModel
|
||||
{
|
||||
StorekeeperId = APIStorekeeper.Storekeeper.Id,
|
||||
});
|
||||
|
||||
return View(laborCost.ReadElement(new LaborCostsSearchModel
|
||||
{
|
||||
Id = id
|
||||
}));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateLaborCosts(LaborCostsBindingModel model)
|
||||
public void UpdateLaborCosts(int hours, string difficulty)
|
||||
{
|
||||
try
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
_logic.Create(model);
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
if (string.IsNullOrEmpty(difficulty) || hours <= 0)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания трудозатраты");
|
||||
throw;
|
||||
throw new Exception("Введены не все данные!");
|
||||
}
|
||||
|
||||
laborCost.Update(new LaborCostsBindingModel
|
||||
{
|
||||
NumberHours = hours,
|
||||
Difficulty = difficulty,
|
||||
StorekeeperId = APIStorekeeper.Storekeeper.Id
|
||||
});
|
||||
|
||||
Response.Redirect("/LaborCost/LaborCosts");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateLaborCosts(LaborCostsBindingModel model)
|
||||
/// <summary>
|
||||
/// Удалить косметику
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public void DeleteLaborCosts(int id)
|
||||
{
|
||||
try
|
||||
if (APIStorekeeper.Storekeeper == null)
|
||||
{
|
||||
_logic.Update(model);
|
||||
throw new Exception("Необходимо авторизоваться!");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления трудозатраты");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteLaborCosts(LaborCostsBindingModel model)
|
||||
{
|
||||
try
|
||||
laborCost.Delete(new LaborCostsBindingModel
|
||||
{
|
||||
_logic.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления трудозатраты");
|
||||
throw;
|
||||
}
|
||||
Id = id
|
||||
});
|
||||
|
||||
Response.Redirect("/LaborCost/LaborCosts");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,10 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="Views\Shared\UpdateLaborCosts.cshtml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
</ItemGroup>
|
||||
@ -26,12 +30,11 @@
|
||||
<None Include="Views\Home\Register.cshtml" />
|
||||
<None Include="Views\Home\Report.cshtml" />
|
||||
<None Include="Views\Home\Service.cshtml" />
|
||||
<None Include="Views\LaborCosts\Create.cshtml" />
|
||||
<None Include="Views\LaborCosts\Update.cshtml" />
|
||||
<None Include="Views\Service\Bind.cshtml" />
|
||||
<None Include="Views\Service\Create.cshtml" />
|
||||
<None Include="Views\Service\Update.cshtml" />
|
||||
<None Include="Views\Shared\Error.cshtml" />
|
||||
<None Include="Views\Shared\UpdateLaborCosts.cshtml" />
|
||||
<None Include="Views\Shared\_Layout.cshtml" />
|
||||
<None Include="Views\Shared\_ValidationScriptsPartial.cshtml" />
|
||||
<None Include="Views\_ViewImports.cshtml" />
|
||||
|
@ -0,0 +1,38 @@
|
||||
@{
|
||||
ViewData["Title"] = "Создание трудозатраты";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание трудозатраты</h2>
|
||||
</div>
|
||||
|
||||
<form method="post" style="margin-top: 50px">
|
||||
<div class="row">
|
||||
<div class="col-4">Количество часов:</div>
|
||||
<div class="col-8"><input type="text" name="hours" id="hours" /></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4">Сложность:</div>
|
||||
<div class="col-8"><input type="text" name="difficulty" id="difficulty" /></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4">Косметика:</div>
|
||||
<div class="col-8">
|
||||
<select name="cosmeticId" id="cosmeticId" class="form-control">
|
||||
@foreach (var cosmetic in ViewBag.Cosmetics)
|
||||
{
|
||||
<option value="@cosmetic.Id">@cosmetic.Id</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Кнопка "Создать" -->
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -0,0 +1,68 @@
|
||||
@using BeautySalonContracts.ViewModels
|
||||
|
||||
@model List<LaborCostsViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Трудозатраты";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Трудозатраты</h1>
|
||||
</div>
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
|
||||
<p>
|
||||
<a asp-action="CreateLaborCosts">Создать Трудозатрату</a>
|
||||
</p>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Номер</th>
|
||||
<th>Количество часов</th>
|
||||
<th>Сложность</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach (var laborCosts in Model)
|
||||
{
|
||||
<tr>
|
||||
<th>@laborCosts.Id</th>
|
||||
<td>@laborCosts.NumberHours</td>
|
||||
<td>@laborCosts.Difficulty</td>
|
||||
<td>
|
||||
<p><button type="button" class="btn btn-primary" onclick="location.href='@Url.Action("UpdateLaborCosts", "/LaborCost", new { id = laborCosts.Id })'">Изменить</button></p>
|
||||
</td>
|
||||
<td>
|
||||
<p><button type="button" class="btn btn-primary" onclick="deleteLaborCost(@laborCosts.Id)">Удалить</button></p>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
|
||||
@section scripts {
|
||||
<script>
|
||||
function deleteLaborCost(id) {
|
||||
if (confirm("Вы уверены, что хотите удалить трудозатрату?")) {
|
||||
$.post('@Url.Action("DeleteLaborCosts", "/LaborCost")' + '/' + id, function () {
|
||||
window.location.reload();
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
@using BeautySalonContracts.ViewModels
|
||||
|
||||
@model LaborCostsViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Редактирование трудозатраты";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Редактирование трудозатраты</h2>
|
||||
</div>
|
||||
|
||||
<form method="post" style="margin-top: 50px">
|
||||
<div class="row">
|
||||
<div class="col-4">Количество часов:</div>
|
||||
<div class="col-8"><input type="text" name="hours" value="@Model.NumberHours" /></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4">Сложность:</div>
|
||||
<div class="col-8"><input type="text" name="difficulty" value="@Model.Difficulty" /></div>
|
||||
</div>
|
||||
|
||||
<!-- Кнопка "Сохранить" -->
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
@ -1,15 +0,0 @@
|
||||
@{
|
||||
ViewData["Title"] = "Трудозатраты";
|
||||
}
|
||||
|
||||
<h4 class="fw-bold">Создать трудозатрату</h4>
|
||||
|
||||
<form method="post" asp-controller="LaborCosts" asp-action="Create">
|
||||
<p class="mb-0">Количество часов:</p>
|
||||
<input type="number" name="numberHours" class="form-control mb-3" />
|
||||
<p class="mb-0">Количество специалистов:</p>
|
||||
<input type="number" name="numberSpecialists" class="form-control mb-3" />
|
||||
<button type="submit" class="btn button-primary">
|
||||
Создать
|
||||
</button>
|
||||
</form>
|
@ -1,16 +0,0 @@
|
||||
@{
|
||||
ViewData["Title"] = "Трудозатраты";
|
||||
}
|
||||
|
||||
<h4 class="fw-bold">Обновить трудозатраты</h4>
|
||||
|
||||
<form method="post" asp-controller="LaborCosts" asp-action="Update">
|
||||
<input name="id" value="@ViewBag.LaborCosts.Id" style="display: none;" />
|
||||
<p class="mb-0">Количество часов:</p>
|
||||
<input type="number" value="@ViewBag.LaborCosts.NumberHours" name="numberHours" class="form-control mb-3" />
|
||||
<p class="mb-0">Количество специалистов:</p>
|
||||
<input type="number" value="@ViewBag.LaborCosts.NumberSpecialists" name="numberSpecialists" class="form-control mb-3" />
|
||||
<button type="submit" class="btn button-primary">
|
||||
Обновить
|
||||
</button>
|
||||
</form>
|
@ -0,0 +1,29 @@
|
||||
@using BeautySalonContracts.ViewModels
|
||||
|
||||
@model LaborCostsViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Редактирование трудозатраты";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Редактирование трудозатраты</h2>
|
||||
</div>
|
||||
|
||||
<form method="post" style="margin-top: 50px">
|
||||
<div class="row">
|
||||
<div class="col-4">Количество часов:</div>
|
||||
<div class="col-8"><input type="text" name="hours" value="@Model.NumberHours" /></div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-4">Сложность:</div>
|
||||
<div class="col-8"><input type="text" name="difficulty" value="@Model.Difficulty" /></div>
|
||||
</div>
|
||||
|
||||
<!-- Кнопка "Сохранить" -->
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
@ -32,13 +32,13 @@
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Авторизация</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Service" asp-action="GetAllServices">Услуги</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Service" asp-action="Services">Услуги</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Cosmetic" asp-action="Cosmetics">Косметика</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="LaborCost" asp-action="GetAllLaborCosts">Трудозатраты</a>
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="LaborCost" asp-action="LaborCosts">Трудозатраты</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Reports">Отчет</a>
|
||||
|
5
BeautySalonView/StaffMemberWebApp/libman.json
Normal file
5
BeautySalonView/StaffMemberWebApp/libman.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"defaultProvider": "cdnjs",
|
||||
"libraries": []
|
||||
}
|
Loading…
Reference in New Issue
Block a user