Исполнитель: добавил название посещения

This commit is contained in:
Yunusov_Niyaz 2024-04-30 17:18:31 +04:00
parent 4b15da7812
commit c2a498f562
16 changed files with 111 additions and 41 deletions

View File

@ -99,11 +99,15 @@ namespace VeterinaryBusinessLogic.BusinessLogic
{
return;
}
if (string.IsNullOrEmpty(model.VisitName))
{
throw new ArgumentNullException("Нет названия визита", nameof(model.VisitName));
}
if (model.DateVisit >= DateTime.Now)
{
throw new ArgumentNullException("Дата посещения не должна быть в прошлом", nameof(model.DateVisit));
}
_logger.LogInformation("Visit. DateVisit:{ DateVisit}. Id: { Id}", model.DateVisit);
_logger.LogInformation("Visit. Visit:{NameVisit}. DateVisit:{ DateVisit}. Id: { Id}", model.VisitName, model.DateVisit, model.Id);
}
}
}

View File

@ -10,6 +10,7 @@ namespace VeterinaryContracts.BindingModels
public string PetType { get; set;} = string.Empty;
public string PetBreed { get; set; } = string.Empty;
public string PetGender { get; set; } = string.Empty;
public Dictionary<int, IVisitModel> VisitPets { get; set; } = new();
public Dictionary<int, IPurchaseModel> PurchasePets { get; set; } = new();
}
}

View File

@ -8,6 +8,7 @@ namespace VeterinaryContracts.BindingModels
public int Id { get; set; }
public int OwnerId { get; set; }
public int? DoctorId { get; set; } = null;
public string VisitName { get; set; } = string.Empty;
public VisitStatus Status { get; set; }
public DateTime DateVisit { get; set; }
public Dictionary<int, IPetModel> VisitPet { get; set; } = new();

View File

@ -3,6 +3,7 @@
public class PetSearchModel
{
public int? Id { get; set; }
public int? OwnerId { get; set; }
public string? PetName { get; set; }
}
}

View File

@ -7,6 +7,7 @@ namespace VeterinaryContracts.SearchModels
public int? Id { get; set; }
public int? OwnerId { get; set; }
public int? DoctorId { get; set; }
public string? VisitName { get; set; }
public VisitStatus? Status { get; set; }
public DateTime? DateVisit { get; set; }
}

View File

@ -16,5 +16,7 @@ namespace VeterinaryContracts.ViewModels
public string PetBreed { get; set; } = string.Empty;
[DisplayName("Пол")]
public string PetGender { get; set; } = string.Empty;
public Dictionary<int, IVisitModel> VisitPets { get; set; } = new();
public Dictionary<int, IPurchaseModel> PurchasePets { get; set; } = new();
}
}

View File

@ -11,6 +11,8 @@ namespace VeterinaryContracts.ViewModels
public int OwnerId { get; set; }
[DisplayName("Врач")]
public int? DoctorId { get; set; } = null;
[DisplayName("Название визита")]
public string VisitName { get; set; } = string.Empty;
[DisplayName("Статус")]
public VisitStatus Status { get; set; }
[DisplayName("Дата посещения")]

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryDataModels
{
public interface IDrugModel :IId
{
string DrugName { get; }
int Count { get; }
double Price { get; }
Dictionary<int, IMedicationModel> DrugMedications { get; }
}
}

View File

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VeterinaryDataModels
{
public interface IServiceModel : IId
{
String ServiceName { get;}
int VisitId { get; }
int DoctorId { get; }
Dictionary<int, IMedicationModel> ServiceMedications { get; }
}
}

View File

@ -11,6 +11,6 @@ namespace VeterinaryDataModels.Models
string DrugName { get; }
int Count { get; }
double Price { get; }
Dictionary<int, (IMedicationModel, int)> DrugMedications { get; }
Dictionary<int, IMedicationModel> DrugMedications { get; }
}
}

View File

@ -7,5 +7,7 @@
string PetType { get; }
string PetBreed { get; }
string PetGender { get; }
}
Dictionary<int, IVisitModel> VisitPets { get; }
Dictionary<int, IPurchaseModel> PurchasePets { get; }
}
}

View File

@ -11,7 +11,6 @@ namespace VeterinaryDataModels.Models
string ServiceName { get; }
int VisitId { get; }
int DoctorId { get; }
Dictionary<int, (IMedicationModel, int)> ServiceMedications { get; }
Dictionary<int, IMedicationModel> ServiceMedications { get; }
}
}

View File

@ -6,6 +6,7 @@ namespace VeterinaryDataModels.Models
{
int OwnerId { get; }
int? DoctorId { get; }
string VisitName { get; }
DateTime DateVisit { get; }
VisitStatus Status { get; }
Dictionary<int, IPetModel> VisitPet { get; }

View File

@ -18,9 +18,14 @@ namespace VeterinaryDatabaseImplement.Implements
}
public List<VisitViewModel> GetFilteredList(VisitSearchModel model)
{
if (string.IsNullOrEmpty(model.VisitName))
{
return null;
}
using var context = new VeterinaryDatabase();
return context.Visits.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Doctor)
.Where(x => ((!model.Id.HasValue || x.Id == model.Id) &&
(string.IsNullOrEmpty(model.VisitName) || x.VisitName.Contains(model.VisitName)) &&
(!model.DateVisit.HasValue || x.DateVisit >= model.DateVisit) &&
(!model.OwnerId.HasValue || x.OwnerId <= model.OwnerId) &&
(!model.DoctorId.HasValue || x.DoctorId == model.DoctorId)))
@ -29,13 +34,13 @@ namespace VeterinaryDatabaseImplement.Implements
}
public VisitViewModel? GetElement(VisitSearchModel model)
{
if (!model.Id.HasValue)
if (string.IsNullOrEmpty(model.VisitName) && !model.Id.HasValue)
{
return null;
}
using var context = new VeterinaryDatabase();
return context.Visits.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Doctor)
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.VisitName) && x.VisitName == model.VisitName) || (x.Id == model.Id))?.GetViewModel;
}
public VisitViewModel? Insert(VisitBindingModel model)
{

View File

@ -17,6 +17,8 @@ namespace VeterinaryDatabaseImplement.Models
public int? DoctorId { get; private set; }
public virtual Doctor? Doctor { get; private set; }
[Required]
public string VisitName { get; private set; }
[Required]
public VisitStatus Status { get; private set; }
[Required]
public DateTime DateVisit { get; private set; }

View File

@ -1,4 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.ViewModels;
namespace VeterinaryRestApi.Controllers
{
@ -6,5 +10,83 @@ namespace VeterinaryRestApi.Controllers
[ApiController]
public class PetController : Controller
{
private readonly ILogger _logger;
private readonly IPetLogic _pet;
public PetController(ILogger<PetController> logger, IPetLogic pet)
{
_logger = logger;
_pet = pet;
}
[HttpGet]
public Tuple<PetViewModel, List<string>>? GetPet(int petId)
{
try
{
var elem = _pet.ReadElement(new PetSearchModel { Id = petId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.VisitPets.Select(x => x.Value.Name).ToList());
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения услуги по id={Id}", petId);
throw;
}
}
[HttpGet]
public List<PetViewModel> GetPets(int ownerId)
{
try
{
return _pet.ReadList(new PetSearchModel { OwnerId = ownerId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка услуг");
throw;
}
}
[HttpPost]
public bool CreatePet(PetBindingModel model)
{
try
{
return _pet.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать услугу");
throw;
}
}
[HttpPost]
public bool UpdatePet(PetBindingModel model)
{
try
{
model.Pets = null!;
return _pet.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить услугу");
throw;
}
}
[HttpPost]
public bool DeletePet(PetBindingModel model)
{
try
{
return _pet.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления услуги");
throw;
}
}
}
}