425 lines
12 KiB
C#
425 lines
12 KiB
C#
using EventVisitorLogic.BindingModels;
|
|
using EventVisitorLogic.Logic;
|
|
using EventVisitorLogic.ViewModels;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace EventVisitorRestApi.Controllers
|
|
{
|
|
[Route("api/[controller]/[action]")]
|
|
[ApiController]
|
|
public class MainController : Controller
|
|
{
|
|
private readonly IOrganizerLogic _organizer;
|
|
private readonly IEventLogic _event;
|
|
private readonly IVisitorLogic _visitor;
|
|
|
|
public MainController(IOrganizerLogic organizer, IEventLogic events, IVisitorLogic visitor)
|
|
{
|
|
_organizer = organizer;
|
|
_event = events;
|
|
_visitor = visitor;
|
|
}
|
|
/// Мероприятия
|
|
[HttpGet]
|
|
public List<EventViewModel>? GetEventList(int organizerId)
|
|
{
|
|
try
|
|
{
|
|
if (organizerId == null)
|
|
{
|
|
return _event.ReadList(null);
|
|
}
|
|
return _event.ReadList(new EventBindingModel
|
|
{
|
|
OrganizerId = organizerId
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
public List<VisitorViewModel>? GetVisitorList(int eventId)
|
|
{
|
|
try
|
|
{
|
|
if (eventId == null)
|
|
{
|
|
return _visitor.ReadList(null);
|
|
}
|
|
return _visitor.ReadList(new VisitorBindingModel
|
|
{
|
|
EventId = eventId
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void CreateEvent(EventBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_event.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void RegistrationOnEvent(VisitorBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_visitor.Create(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//[HttpGet]
|
|
//public List<ProceduresViewModel>? GetProcedures()
|
|
//{
|
|
// try
|
|
// {
|
|
// return _procedure.ReadList(null);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка получения списка процедур");
|
|
// throw;
|
|
// }
|
|
//}
|
|
//[HttpPost]
|
|
//public void CreateProcedure(ProceduresBindingModel model)
|
|
//{
|
|
// try
|
|
// {
|
|
// _procedure.Create(model);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка создания процедуры");
|
|
// throw;
|
|
// }
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//public void UpdateProcedure(ProceduresBindingModel model)
|
|
//{
|
|
// try
|
|
// {
|
|
// model.ProcedureMedicine = null!;
|
|
// _procedure.Update(model);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка обновления процедуры");
|
|
// throw;
|
|
// }
|
|
//}
|
|
//[HttpGet]
|
|
//public Tuple<ProceduresViewModel, List<Tuple<string>>>? GetProcedure(int procedureId)
|
|
//{
|
|
// try
|
|
// {
|
|
// var elem = _procedure.ReadElement(new ProceduresSearchModel { Id = procedureId });
|
|
// if (elem == null)
|
|
// return null;
|
|
// return Tuple.Create(elem, elem.ProcedureMedicine.Select(x => Tuple.Create(x.Value.MedicinesName)).ToList());
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка получения процедуры по id={Id}", procedureId);
|
|
// throw;
|
|
// }
|
|
//}
|
|
|
|
////private ProceduresBindingModel GetModelWithMedicines(ProceduresBindingModel model)
|
|
////{
|
|
//// var medicines = _medicine.ReadList(new MedicinesSearchModel { Ids = model.ProcedureMedicine.Keys.ToArray() });
|
|
//// if (medicines != null)
|
|
//// {
|
|
//// model.ProcedureMedicine = medicines.Where(m => model.ProcedureMedicine.Keys.Contains(m.Id))
|
|
//// .ToDictionary(m => m.Id, m => m as IMedicinesModel);
|
|
//// }
|
|
//// return model;
|
|
////}
|
|
|
|
//[HttpPost]
|
|
//public void DeleteProcedure(ProceduresBindingModel model)
|
|
//{
|
|
// try
|
|
// {
|
|
// _procedure.Delete(model);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка удаления процедуры");
|
|
// throw;
|
|
// }
|
|
//}
|
|
///// <summary>
|
|
///// ЛЕКАРСТВА
|
|
///// </summary>
|
|
///// <returns></returns>
|
|
//[HttpGet]
|
|
//public List<MedicinesViewModel>? GetMedicinesList(int? clientId)
|
|
//{
|
|
// try
|
|
// {
|
|
// if (clientId == null)
|
|
// {
|
|
// return _medicine.ReadList(null);
|
|
// }
|
|
// return _medicine.ReadList(new MedicinesSearchModel
|
|
// {
|
|
// ClientId = clientId
|
|
// });
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка получения списка лекарств");
|
|
// throw;
|
|
// }
|
|
//}
|
|
//[HttpGet]
|
|
//public List<MedicinesViewModel>? GetMedicines()
|
|
//{
|
|
// try
|
|
// {
|
|
// return _medicine.ReadList(null);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка получения списка лекарств");
|
|
// throw;
|
|
// }
|
|
//}
|
|
[HttpGet]
|
|
public EventViewModel? GetEvent(int eventId)
|
|
{
|
|
try
|
|
{
|
|
return _event.ReadElement(new EventBindingModel
|
|
{
|
|
Id = eventId
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
//[HttpPost]
|
|
//public void CreateMedicine(MedicinesBindingModel model)
|
|
//{
|
|
// try
|
|
// {
|
|
// _medicine.Create(model);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка создания лекарства");
|
|
// throw;
|
|
// }
|
|
//}
|
|
[HttpPost]
|
|
public void UpdateEvent(EventBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_event.Update(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
[HttpPost]
|
|
public void DeleteEvent(EventBindingModel model)
|
|
{
|
|
try
|
|
{
|
|
_event.Delete(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
///// <summary>
|
|
///// РЕЦЕПТЫ
|
|
///// </summary>
|
|
///// <returns></returns>
|
|
|
|
//[HttpGet]
|
|
//public List<RecipesViewModel>? GetRecipesList(int clientId)
|
|
//{
|
|
// try
|
|
// {
|
|
// return _recipe.ReadList(new RecipesSearchModel
|
|
// {
|
|
// ClientId = clientId,
|
|
// });
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка получения списка рецептов");
|
|
// throw;
|
|
// }
|
|
//}
|
|
//[HttpPost]
|
|
//public void CreateRecipe(RecipesBindingModel model)
|
|
//{
|
|
// try
|
|
// {
|
|
// _recipe.Create(model);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка создания рецепта");
|
|
// throw;
|
|
// }
|
|
//}
|
|
|
|
//[HttpGet]
|
|
//public List<RecipesViewModel>? GetRecipes()
|
|
//{
|
|
// try
|
|
// {
|
|
// return _recipe.ReadList(null);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка получения списка рецептов");
|
|
// throw;
|
|
// }
|
|
//}
|
|
////[HttpGet]
|
|
////public RecipesViewModel? GetRecipe(int recipeId)
|
|
////{
|
|
//// try
|
|
//// {
|
|
//// return _recipe.ReadElement(new RecipesSearchModel
|
|
//// {
|
|
//// Id = recipeId
|
|
//// });
|
|
//// }
|
|
//// catch (Exception ex)
|
|
//// {
|
|
//// _logger.LogError(ex, "Ошибка получения рецепта по id={Id}", recipeId);
|
|
//// throw;
|
|
//// }
|
|
////}
|
|
|
|
//[HttpPost]
|
|
//public void UpdateRecipe(RecipesBindingModel model)
|
|
//{
|
|
// try
|
|
// {
|
|
// model.RecipeProcedures = null!;
|
|
// _recipe.Update(model);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка обновления данных");
|
|
// throw;
|
|
// }
|
|
//}
|
|
//[HttpGet]
|
|
//public Tuple<RecipesViewModel, List<Tuple<string>>>? GetRecipe(int recipeId)
|
|
//{
|
|
// try
|
|
// {
|
|
// var elem = _recipe.ReadElement(new RecipesSearchModel { Id = recipeId });
|
|
// if (elem == null)
|
|
// return null;
|
|
// return Tuple.Create(elem, elem.RecipeProcedures.Select(x => Tuple.Create(x.Value.ProceduresName)).ToList());
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка получения процедуры по id={Id}", recipeId);
|
|
// throw;
|
|
// }
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//public void AddProcedures(Tuple<RecipesSearchModel, ProceduresViewModel> model)
|
|
//{
|
|
// try
|
|
// {
|
|
// _recipe.AddProcedures(model.Item1, model.Item2);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка добавления процедуры в рецепт.");
|
|
// throw;
|
|
// }
|
|
//}
|
|
//[HttpPost]
|
|
//public void AddMedicineToProcedure(Tuple<ProceduresSearchModel, MedicinesViewModel> model)
|
|
//{
|
|
// try
|
|
// {
|
|
// _procedure.AddMedicineToProcedure(model.Item1, model.Item2);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка добавления лекарства в процедуру.");
|
|
// throw;
|
|
// }
|
|
//}
|
|
//private RecipesBindingModel GetModelWithProcedures(RecipesBindingModel model)
|
|
//{
|
|
// var medicines = _procedure.ReadList(new ProceduresSearchModel { Ids = model.RecipeProcedures.Keys.ToArray() });
|
|
// if (medicines != null)
|
|
// {
|
|
// model.RecipeProcedures = medicines.Where(m => model.RecipeProcedures.Keys.Contains(m.Id))
|
|
// .ToDictionary(m => m.Id, m => m as IProceduresModel);
|
|
// }
|
|
// return model;
|
|
//}
|
|
|
|
//[HttpPost]
|
|
//public void DeleteRecipe(RecipesBindingModel model)
|
|
//{
|
|
// try
|
|
// {
|
|
// _recipe.Delete(model);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// _logger.LogError(ex, "Ошибка удаления рецепта");
|
|
// throw;
|
|
// }
|
|
//}
|
|
//[HttpGet]
|
|
//public List<SymptomsViewModel>? GetSymptoms()
|
|
//{
|
|
// try
|
|
// {
|
|
// return _symptom.ReadList(null);
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw;
|
|
// }
|
|
//}
|
|
}
|
|
}
|