сделала MainController
This commit is contained in:
@@ -17,5 +17,6 @@ namespace CarCenterContracts.BusinessLogicsContracts
|
||||
bool Create(EquipmentBindingModel model);
|
||||
bool Update(EquipmentBindingModel model);
|
||||
bool Delete(EquipmentBindingModel model);
|
||||
bool AddCarToEquipment(EquipmentSearchModel model, ICarModel car);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CarCenterDataModels.Models;
|
||||
|
||||
namespace CarCenterContracts.BusinessLogicsContracts
|
||||
{
|
||||
@@ -16,5 +17,6 @@ namespace CarCenterContracts.BusinessLogicsContracts
|
||||
bool Create(InspectionBindingModel model);
|
||||
bool Update(InspectionBindingModel model);
|
||||
bool Delete(InspectionBindingModel model);
|
||||
bool AddCarToInspection(InspectionSearchModel model, ICarModel car);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using CarCenterBusinessLogic.BusinessLogics;
|
||||
using CarCenterContracts.BusinessLogicsContracts;
|
||||
using CarCenterContracts.SearchModels;
|
||||
using CarCenterDataBaseImplement.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using CarCenterContracts.ViewModels;
|
||||
using CarCenterContracts.BindingModels;
|
||||
|
||||
namespace CarCenterRestApi.Controllers
|
||||
{
|
||||
@@ -6,6 +12,603 @@ namespace CarCenterRestApi.Controllers
|
||||
[ApiController]
|
||||
public class MainController : Controller
|
||||
{
|
||||
|
||||
private readonly ILogger _logger;
|
||||
private readonly IEmployeeLogic _employee;
|
||||
private readonly ISaleLogic _sale;
|
||||
private readonly IPreSaleWorkLogic _preSaleWork;
|
||||
private readonly ICarLogic _car;
|
||||
private readonly IInspectionLogic _inspection;
|
||||
private readonly IEquipmentLogic _equipment;
|
||||
|
||||
public MainController(ILogger<MainController> logger, IConferenceLogic conference, IMemberLogic member, IMealPlanLogic mealPlan, ICarLogic car, IInspectionLogic inspection, IEquipmentLogic equipment)
|
||||
{
|
||||
_logger = logger;
|
||||
_conference = conference;
|
||||
_member = member;
|
||||
_mealPlan = mealPlan;
|
||||
_car = car;
|
||||
_inspection = inspection;
|
||||
_equipment = equipment;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ConferenceViewModel>? GetConferenceList(int organiserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _conference.ReadList(new ConferenceSearchModel
|
||||
{
|
||||
OrganiserId = organiserId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка конференций");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<MemberViewModel>? GetMemberList(int organiserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _member.ReadList(new MemberSearchModel
|
||||
{
|
||||
OrganiserId = organiserId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка участников");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<MealPlanViewModel>? GetMealPlanList(int organiserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mealPlan.ReadList(new MealPlanSearchModel
|
||||
{
|
||||
OrganiserId = organiserId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка планов питания");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<CarViewModel>? GetCarList(int administratorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _car.ReadList(new CarSearchModel
|
||||
{
|
||||
AdministratorId = administratorId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка машин");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<InspectionViewModel>? GetInspectionList(int administratorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _inspection.ReadList(new InspectionSearchModel
|
||||
{
|
||||
AdministratorId = administratorId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка осмотров");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<EquipmentViewModel>? GetEquipments()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _equipment.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка комплектаций");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<EquipmentViewModel>? GetEquipmentList(int administratorId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _equipment.ReadList(new EquipmentSearchModel
|
||||
{
|
||||
AdministratorId = administratorId,
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка комплектаций");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateMember(MemberBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_member.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public MemberViewModel? GetMember(int memberId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _member.ReadElement(new MemberSearchModel
|
||||
{
|
||||
Id = memberId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения участника по id={Id}", memberId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateMember(MemberBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_member.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания участника");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteMember(MemberBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_member.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления участника");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateCar(CarBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_car.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных о машинах");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public CarViewModel? GetCar(int carId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _car.ReadElement(new CarSearchModel
|
||||
{
|
||||
Id = carId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения машины по id={Id}", carId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateCar(CarBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_car.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания машины");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteCar(CarBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_car.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления машины");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateConference(ConferenceBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_conference.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания конференции");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateConference(ConferenceBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
model.ConferenceMembers = null!;
|
||||
_conference.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<ConferenceViewModel, List<Tuple<string, string>>>? GetConference(int conferenceId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _conference.ReadElement(new ConferenceSearchModel { Id = conferenceId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
return Tuple.Create(elem, elem.ConferenceMembers.Select(x => Tuple.Create(x.Value.MemberFIO, x.Value.Citizenship)).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения конференции по id={Id}", conferenceId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteConference(ConferenceBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_conference.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления конференции");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddMemberToConference(Tuple<ConferenceSearchModel, MemberViewModel> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_conference.AddMemberToConference(model.Item1, model.Item2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления участника в конференцию.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateMealPlan(MealPlanBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mealPlan.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания плана питания");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateMealPlan(MealPlanBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
model.MealPlanMembers = null!;
|
||||
_mealPlan.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<MealPlanViewModel, List<Tuple<string, string>>, List<Tuple<string, string>>>? GetMealPlan(int mealPlanId)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var context = new HotelDataBase();
|
||||
var elem = _mealPlan.ReadElement(new MealPlanSearchModel { Id = mealPlanId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
return Tuple.Create(elem, elem.MealPlanMembers.Select(x => Tuple.Create(x.Value.MemberFIO, x.Value.Citizenship)).ToList(), context.Rooms.Where(x => x.MealPlanId == elem.Id).Select(x => Tuple.Create(x.RoomName, x.RoomFrame)).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения плана питания по id={Id}", mealPlanId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteMealPlan(MealPlanBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mealPlan.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления плана питания");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddMemberToMealPlan(Tuple<MealPlanSearchModel, MemberViewModel> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_mealPlan.AddMemberToMealPlan(model.Item1, model.Item2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления участника в план питания.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateEquipment(EquipmentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_equipment.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания комплектации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateInspection(InspectionBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_inspection.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания осмотра");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateEquipment(EquipmentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
model.EquipmentCars = null!;
|
||||
_equipment.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public EquipmentViewModel GetEquipmentById(int equipmentId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _equipment.ReadElement(new EquipmentSearchModel { Id = equipmentId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
return elem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения комплектации по id={Id}", equipmentId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<EquipmentViewModel, List<Tuple<string, string>>>? GetEquipment(int equipmentId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _equipment.ReadElement(new EquipmentSearchModel { Id = equipmentId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
return Tuple.Create(elem, elem.EquipmentCars.Select(x => Tuple.Create(x.Value.BrandCar, x.Value.Model)).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения комплектации по id={Id}", equipmentId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteEquipment(EquipmentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_equipment.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления комплектации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddCarToEquipment(Tuple<EquipmentSearchModel, CarViewModel> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_equipment.AddCarToEquipment(model.Item1, model.Item2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления машины в комплектацию.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateInspection(InspectionBindingModel model)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
model.InspectionCars = null!;
|
||||
_inspection.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<InspectionViewModel, List<Tuple<string, string>>>? GetInspection(int inspectionId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _inspection.ReadElement(new InspectionSearchModel { Id = inspectionId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
return Tuple.Create(elem, elem.InspectionCars.Select(x => Tuple.Create(x.Value.BrandCar, x.Value.Model)).ToList());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения по id={Id}", inspectionId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteInspection(InspectionBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_inspection.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления осмотра");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddCarToInspection(Tuple<InspectionSearchModel, CarViewModel> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_inspection.AddCarToInspection(model.Item1, model.Item2);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка добавления машины в план питания.");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<ConferenceViewModel>? GetConferences()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _conference.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка конференций");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public InspectionViewModel GetInspectionById(int inspectionId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var elem = _inspection.ReadElement(new InspectionSearchModel { Id = inspectionId });
|
||||
if (elem == null)
|
||||
return null;
|
||||
return elem;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения по id={Id}", inspectionId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user