заказ...........

This commit is contained in:
Allllen4a 2024-05-31 17:23:58 +04:00
parent 826881c080
commit ae0fd39828

View File

@ -1,164 +1,232 @@
using BeautySalonContracts.BindingModels;
using Azure;
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.ViewModels;
using BeautySalonDatabaseImplement.Models;
using BeautySalonDataModels.Models;
using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.AspNetCore.Mvc;
using WorkerWebApp;
/*
namespace BeautySalonRestApi.Controllers
public class OrderController : Controller
{
public class OrderController : Controller
{
private readonly ILogger logger;
private readonly ILogger _logger;
private readonly IOrderLogic order;
private readonly ILaborCostsLogic laborCost;
private readonly IProcedureLogic procedure;
private readonly IOrderLogic _orderLogic;
public OrderController(ILogger<OrderController> logger, IOrderLogic order, IProcedureLogic procedure, ILaborCostsLogic laborCost)
{
this.logger = logger;
this.order = order;
this.procedure = procedure;
this.laborCost = laborCost;
}
private readonly IServiceLogic _serviceLogic;
[HttpGet]
public OrderViewModel? GetOrder(int id)
{
try
{
return order.ReadElement(new OrderSearchModel
{
Id = id
});
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка получения косметики");
throw;
}
}
/// <summary>
/// Бизнес-логика для сущности "Процедура"
/// </summary>
private readonly IProcedureLogic _procedureLogic;
[HttpGet]
public IActionResult Orders()
{
if (APIWorker.Worker == null)
{
return Redirect("~/Home/Enter");
}
public OrderController(ILogger<OrderController> logger, IOrderLogic orderLogic, IProcedureLogic procedureLogic, IServiceLogic serviceLogic)
{
_logger = logger;
_orderLogic = orderLogic;
_procedureLogic = procedureLogic;
_serviceLogic = serviceLogic;
}
return View(order.ReadList(null));
}
[HttpGet]
public IActionResult Orders()
{
if (APIWorker.Worker == null)
{
return Redirect("~/Home/Enter");
}
[HttpGet]
public IActionResult CreateOrders()
{
if (APIWorker.Worker == null)
{
return Redirect("~/Home/Enter");
}
return View(_orderLogic.ReadList(new OrderSearchModel
{
WorkerId = APIWorker.Worker.Id,
}));
}
/// <summary>
/// Получение заказов по id пользователя (полный список, кот. будет выводиться)
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[HttpGet]
public IActionResult CreateOrder()
{
if (APIWorker.Worker == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.LaborCosts = laborCost.ReadList(new LaborCostsSearchModel
{
WorkerId = APIWorker.Worker.Id,
});
ViewBag.Services = _serviceLogic.ReadList(null);
return View();
}
return View();
}
[HttpPost]
public void CreateOrders(string name, string brand, double price, int laborCost)
{
if (APIWorker.Worker == null)
{
throw new Exception("Необходимо авторизоваться!");
}
[HttpPost]
public void CreateOrder(double amount, DateTime datacreate, DateTime dateimplement, List<int> services)
{
if (APIWorker.Worker == null)
{
throw new Exception("Необходимо авторизоваться!");
}
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(brand) || price <= 0 || laborCost <= 0)
{
throw new Exception("Введены не все данные!");
}
if (amount == 0 || datacreate == DateTime.MinValue || dateimplement == DateTime.MinValue || services == null)
{
throw new Exception("Введены не все данные!");
}
order.Create(new OrderBindingModel
{
OrderName = name,
Brand = brand,
OrderPrice = price,
LaborCostId = laborCost,
WorkerId = APIWorker.Worker.Id
});
Dictionary<int, IServiceModel> orderServices = new Dictionary<int, IServiceModel>();
foreach (var serviceId in services)
{
orderServices.Add(serviceId, _serviceLogic.ReadElement(new ServiceSearchModel { Id = serviceId })!);
}
Response.Redirect("/Order/Orders");
}
_orderLogic.Create(new OrderBindingModel
{
OrderAmount = amount,
DateCreate = datacreate,
DateImplement = dateimplement,
WorkerId = APIWorker.Worker.Id,
//OrderServices = orderServices
});
Response.Redirect("/Order/Orders");
}
[HttpGet]
public IActionResult UpdateOrder(int id)
{
if (APIWorker.Worker == null)
{
return Redirect("~/Home/Enter");
}
[HttpGet]
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
{
Id = id
}));
}
[HttpPost]
public void UpdateOrder(int id, double amount, DateTime datacreate, DateTime dateimplement, List<int> services)
{
if (APIWorker.Worker == null)
{
throw new Exception("Необходимо авторизоваться!");
}
return View(order.ReadElement(new OrderSearchModel
{
Id = id
}));
}
if (amount == 0 || datacreate == DateTime.MinValue || dateimplement == DateTime.MinValue || services == null)
{
throw new Exception("Введены не все данные!");
}
[HttpPost]
public void UpdateOrders(int id, string name, string brand, double price, int laborCost)
{
if (APIWorker.Worker == null)
{
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 })!);
}
if (string.IsNullOrEmpty(name) || laborCost <= 0)
{
throw new Exception("Введены не все данные!");
}
var order = _orderLogic.ReadElement(new OrderSearchModel { Id = id });
_orderLogic.Update(new OrderBindingModel
{
Id = id,
OrderAmount = amount,
DateCreate = datacreate,
DateImplement = dateimplement,
WorkerId = APIWorker.Worker.Id,
OrderProcedures = order!.OrderProcedures,
//OrderServices = orderServices
});
order.Update(new OrderBindingModel
{
Id = id,
OrderName = name,
Brand = brand,
OrderPrice = price,
LaborCostId = laborCost
});
Response.Redirect("/Order/Orders");
}
[HttpPost]
public void DeleteOrder(int id)
{
if (APIWorker.Worker == null)
{
throw new Exception("Необходимо авторизоваться!");
}
Response.Redirect("/Order/Orders");
}
_orderLogic.Delete(new OrderBindingModel
{
Id = id
});
/// <summary>
/// Удалить косметику
/// </summary>
/// <returns></returns>
[HttpPost]
public void DeleteOrders(int id)
{
if (APIWorker.Worker == null)
{
throw new Exception("Необходимо авторизоваться!");
}
Response.Redirect("/Order/Orders");
}
[HttpGet]
public IActionResult CreateOrderProcedure()
{
if (APIWorker.Worker == null)
{
throw new Exception("Необходимо авторизоваться!");
}
order.Delete(new OrderBindingModel
{
Id = id
});
ViewBag.Orders = _orderLogic.ReadList(new OrderSearchModel
{
WorkerId = APIWorker.Worker.Id
});
ViewBag.Procedures = _procedureLogic.ReadList(new ProcedureSearchModel
{
WorkerId = APIWorker.Worker.Id
});
Response.Redirect("/Order/Orders");
}
}
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);
}
}
*/