начало контроллеров

This commit is contained in:
Allllen4a 2024-04-30 19:25:36 +04:00
parent 15cac11e0f
commit d9033b8a7e
7 changed files with 280 additions and 155 deletions

View File

@ -15,10 +15,13 @@ namespace BeautySalonRestApi.Controllers
private readonly IClientLogic _logic;
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
{
_logger = logger;
_logic = logic;
}
[HttpGet]
@ -66,5 +69,6 @@ namespace BeautySalonRestApi.Controllers
throw;
}
}
}
}

View File

@ -1,82 +1,122 @@
using Microsoft.AspNetCore.Http;
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BeatySalonRestApi.Controllers
namespace BeautySalonRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class EvaluationController : Controller
{
// GET: EvaluationController
public ActionResult Index()
private readonly ILogger logger;
private readonly IEvaluationLogic evaluation;
public EvaluationController(ILogger<EvaluationController> logger, IEvaluationLogic evaluation)
{
return View();
this.logger = logger;
this.evaluation = evaluation;
}
// GET: EvaluationController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: EvaluationController/Create
public ActionResult Create()
{
return View();
}
// POST: EvaluationController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
[HttpGet]
public EvaluationViewModel? Get(int id)
{
try
{
return RedirectToAction(nameof(Index));
return evaluation.ReadElement(new EvaluationSearchModel { Id = id });
}
catch
catch (Exception ex)
{
return View();
logger.LogError(ex, "Ошибка получения заказа с id = {Id}", id);
throw;
}
}
// GET: EvaluationController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: EvaluationController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
[HttpGet]
public List<EvaluationViewModel>? GetAll()
{
try
{
return RedirectToAction(nameof(Index));
return evaluation.ReadList(null);
}
catch
catch (Exception ex)
{
return View();
logger.LogError(ex, "Ошибка получения списка заказа");
throw;
}
}
// GET: EvaluationController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: EvaluationController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
[HttpGet]
public List<EvaluationViewModel>? GetAllByUser(int userId)
{
try
{
return RedirectToAction(nameof(Index));
return evaluation.ReadList(new EvaluationSearchModel { ClientId = userId });
}
catch
catch (Exception ex)
{
return View();
logger.LogError(ex, "Ошибка получения списка заказа пользователя");
throw;
}
}
[HttpGet]
public List<EvaluationViewModel>? GetMany(int userId, int page)
{
try
{
return evaluation.ReadList(new EvaluationSearchModel { ClientId = userId, PageNumber = page, PageSize = 10 });
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка получения списка заказа клиента id = {Id}", userId);
throw;
}
}
[HttpPost]
public void Create(EvaluationBindingModel model)
{
try
{
evaluation.Create(model);
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
[HttpPost]
public void Update(EvaluationBindingModel model)
{
try
{
evaluation.Update(model);
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка обновления заказа");
throw;
}
}
[HttpPost]
public void Delete(EvaluationBindingModel model)
{
try
{
evaluation.Delete(new() { Id = model.Id });
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка удаления заказа");
throw;
}
}
}

View File

@ -1,82 +1,120 @@
using Microsoft.AspNetCore.Http;
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BeatySalonRestApi.Controllers
namespace BeautySalonRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class OrderController : Controller
{
// GET: OrderController
public ActionResult Index()
private readonly ILogger logger;
private readonly IOrderLogic order;
public OrderController(ILogger<OrderController> logger, IOrderLogic order)
{
return View();
this.logger = logger;
this.order = order;
}
// GET: OrderController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: OrderController/Create
public ActionResult Create()
{
return View();
}
// POST: OrderController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
[HttpGet]
public OrderViewModel? Get(int id)
{
try
{
return RedirectToAction(nameof(Index));
return order.ReadElement(new OrderSearchModel { Id = id });
}
catch
catch (Exception ex)
{
return View();
logger.LogError(ex, "Ошибка получения заказа с id = {Id}", id);
throw;
}
}
// GET: OrderController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: OrderController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
[HttpGet]
public List<OrderViewModel>? GetAll()
{
try
{
return RedirectToAction(nameof(Index));
return order.ReadList(null);
}
catch
catch (Exception ex)
{
return View();
logger.LogError(ex, "Ошибка получения списка заказа");
throw;
}
}
// GET: OrderController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: OrderController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
[HttpGet]
public List<OrderViewModel>? GetAllByUser(int userId)
{
try
{
return RedirectToAction(nameof(Index));
return order.ReadList(new OrderSearchModel { ClientId = userId });
}
catch
catch (Exception ex)
{
return View();
logger.LogError(ex, "Ошибка получения списка заказа пользователя");
throw;
}
}
[HttpGet]
public List<OrderViewModel>? GetMany(int userId, int page)
{
try
{
return order.ReadList(new OrderSearchModel { ClientId = userId});
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка получения списка заказа клиента id = {Id}", userId);
throw;
}
}
[HttpPost]
public void Create(OrderBindingModel model)
{
try
{
order.Create(model);
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка создания заказа");
throw;
}
}
[HttpPost]
public void Update(OrderBindingModel model)
{
try
{
order.Update(model);
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка обновления заказа");
throw;
}
}
[HttpPost]
public void Delete(OrderBindingModel model)
{
try
{
order.Delete(new() { Id = model.Id });
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка удаления заказа");
throw;
}
}
}

View File

@ -1,83 +1,124 @@
using Microsoft.AspNetCore.Http;
using BeautySalonContracts.BindingModels;
using BeautySalonContracts.BusinessLogicContracts;
using BeautySalonContracts.SearchModels;
using BeautySalonContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace BeatySalonRestApi.Controllers
namespace BeutySalonClientApp.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ProcedureController : Controller
{
// GET: ProcedureController
public ActionResult Index()
private readonly ILogger logger;
private readonly IProcedureLogic procedure;
public ProcedureController(ILogger<ProcedureController> logger, IProcedureLogic procedure)
{
return View();
this.logger = logger;
this.procedure = procedure;
}
// GET: ProcedureController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: ProcedureController/Create
public ActionResult Create()
{
return View();
}
// POST: ProcedureController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
[HttpGet]
public ProcedureViewModel? Get(int id)
{
try
{
return RedirectToAction(nameof(Index));
return procedure.ReadElement(new ProcedureSearchModel { Id = id });
}
catch
catch (Exception ex)
{
return View();
logger.LogError(ex, "Ошибка получения процедуры с id = {Id}", id);
throw;
}
}
// GET: ProcedureController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: ProcedureController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
[HttpGet]
public List<ProcedureViewModel>? GetAll()
{
try
{
return RedirectToAction(nameof(Index));
return procedure.ReadList(null);
}
catch
catch (Exception ex)
{
return View();
logger.LogError(ex, "Ошибка получения списка процедур");
throw;
}
}
// GET: ProcedureController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: ProcedureController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
[HttpGet]
public List<ProcedureViewModel>? GetAllByUser(int userId)
{
try
{
return RedirectToAction(nameof(Index));
return procedure.ReadList(new ProcedureSearchModel { ClientId = userId });
}
catch
catch (Exception ex)
{
return View();
logger.LogError(ex, "Ошибка получения списка процедур пользователя");
throw;
}
}
[HttpGet]
public List<ProcedureViewModel>? GetMany(int userId, int page)
{
try
{
return procedure.ReadList(new ProcedureSearchModel { ClientId = userId, PageNumber = page, PageSize = 10 });
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка получения списка процедур клиента id = {Id}", userId);
throw;
}
}
[HttpPost]
public void Create(ProcedureBindingModel model)
{
try
{
procedure.Create(model);
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка создания процедуры");
throw;
}
}
[HttpPost]
public void Update(ProcedureBindingModel model)
{
try
{
procedure.Update(model);
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка обновления процедуры");
throw;
}
}
[HttpPost]
public void Delete(ProcedureBindingModel model)
{
try
{
procedure.Delete(new() { Id = model.Id });
}
catch (Exception ex)
{
logger.LogError(ex, "Ошибка удаления процедуры");
throw;
}
}
}
}

View File

@ -18,9 +18,7 @@ namespace BeautySalonContracts.ViewModels
[DisplayName("Баллы за косметику")]
public double PointsCosmetics { get; set; }
public int ClientId { get; set; }
public string Client_Name { get; set; } = string.Empty;
public string Client_Name { get; set; } = string.Empty;
public int ProcedureId { get; set; }
public string Procedure_Name { get; set; } = string.Empty;
}

View File

@ -18,7 +18,7 @@ namespace BeautySalonDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=PRETTYNAME;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=ALYONA;Initial Catalog=BeautySalonDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -4,6 +4,7 @@ using BeautySalonDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -21,9 +22,12 @@ namespace BeautySalonDatabaseImplement.Models
public double PointsCosmetics { get; set; }
[Required]
public int ProcedureId { get; set; }
[ForeignKey("ProcedureId")]
public virtual Procedure Procedure { get; set; } = new();
[Required]
public int ProcedureId { get; set; }
[Required]
public int ClientId { get; set; }
public virtual Client Client { get; set; } = new();