antoc0der 2024-05-01 14:22:27 +04:00
commit 47f06fcd3a
17 changed files with 47 additions and 133 deletions

View File

@ -4,7 +4,6 @@ using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
using VeterinaryDataModels.Enums;
namespace VeterinaryBusinessLogic.BusinessLogic
{
@ -59,40 +58,7 @@ namespace VeterinaryBusinessLogic.BusinessLogic
}
return true;
}
public bool ChangeStatus(PurchaseBindingModel model, PurchaseStatus status)
{
CheckModel(model);
var element = _purchaseStorage.GetElement(new PurchaseSearchModel { Id = model.Id });
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if (element.Status != status - 1)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
}
model.Status = status;
if (model.Status == PurchaseStatus.Выдан) model.DateImplement = DateTime.Now;
_purchaseStorage.Update(model);
return true;
}
public bool BeginPurchase(PurchaseBindingModel model)
{
return ChangeStatus(model, PurchaseStatus.Собирается);
}
public bool FinishPurchase(PurchaseBindingModel model)
{
return ChangeStatus(model, PurchaseStatus.Готов);
}
public bool DeliveryPurchase(PurchaseBindingModel model)
{
return ChangeStatus(model, PurchaseStatus.Выдан);
}
// dateImplement
private void CheckModel(PurchaseBindingModel model, bool withParams = true)
{
if (model == null)

View File

@ -4,7 +4,6 @@ using VeterinaryContracts.BusinessLogicContracts;
using VeterinaryContracts.SearchModels;
using VeterinaryContracts.StorageContracts;
using VeterinaryContracts.ViewModels;
using VeterinaryDataModels.Enums;
namespace VeterinaryBusinessLogic.BusinessLogic
{
@ -50,7 +49,7 @@ namespace VeterinaryBusinessLogic.BusinessLogic
return list;
}
public bool CreateVisit(VisitBindingModel model)
public bool Create(VisitBindingModel model)
{
CheckModel(model);
if (_visitStorage.Insert(model) == null)
@ -60,34 +59,26 @@ namespace VeterinaryBusinessLogic.BusinessLogic
}
return true;
}
public bool ChangeStatus(VisitBindingModel model, VisitStatus status)
public bool Update(VisitBindingModel model)
{
CheckModel(model);
var element = _visitStorage.GetElement(new VisitSearchModel { Id = model.Id });
if (element == null)
if (_visitStorage.Update(model) == null)
{
_logger.LogWarning("Read operation failed");
_logger.LogWarning("Update operation failed");
return false;
}
if (element.Status != status - 1)
{
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
}
model.Status = status;
if (model.Status == VisitStatus.Закончен) model.DateVisit = DateTime.Now;
_visitStorage.Update(model);
return true;
}
public bool BeginVisit(VisitBindingModel model)
public bool Delete(VisitBindingModel model)
{
return ChangeStatus(model, VisitStatus.Выполняется);
}
public bool FinishVisit(VisitBindingModel model)
{
return ChangeStatus(model, VisitStatus.Закончен);
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_visitStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(VisitBindingModel model, bool withParams = true)
{
@ -103,11 +94,24 @@ namespace VeterinaryBusinessLogic.BusinessLogic
{
throw new ArgumentNullException("Нет названия визита", nameof(model.VisitName));
}
if (model.DateVisit != null)
{
throw new ArgumentNullException("Нет времени визита",
nameof(model.DateVisit));
}
if (model.DateVisit >= DateTime.Now)
{
throw new ArgumentNullException("Дата посещения не должна быть в прошлом", nameof(model.DateVisit));
}
_logger.LogInformation("Visit. Visit:{NameVisit}. DateVisit:{ DateVisit}. Id: { Id}", model.VisitName, model.DateVisit, model.Id);
var element = _visitStorage.GetElement(new VisitSearchModel
{
VisitName = model.VisitName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Визит с таким названием уже есть");
}
}
}
}

View File

@ -1,5 +1,4 @@
using VeterinaryDataModels.Enums;
using VeterinaryDataModels.Models;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
@ -10,10 +9,8 @@ namespace VeterinaryContracts.BindingModels
public int DrugId { get; set; }
public int Count { get; set; }
public double Sum { get; set; }
public PurchaseStatus Status { get; set; }
public DateTime DateCreate { get; set; }
public DateTime DateImplement { get; set; }
public DateTime DateImplement { get; set; }
public Dictionary<int, IPetModel> PurchasePet { get; set; } = new();
}
}

View File

@ -1,5 +1,4 @@
using VeterinaryDataModels.Enums;
using VeterinaryDataModels.Models;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.BindingModels
{
@ -9,7 +8,6 @@ namespace VeterinaryContracts.BindingModels
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

@ -9,8 +9,5 @@ namespace VeterinaryContracts.BusinessLogicContracts
List<PurchaseViewModel>? ReadList(PurchaseSearchModel? model);
PurchaseViewModel? ReadElement(PurchaseSearchModel model);
bool CreatePurchase(PurchaseBindingModel model);
bool BeginPurchase(PurchaseBindingModel model);
bool FinishPurchase(PurchaseBindingModel model);
bool DeliveryPurchase(PurchaseBindingModel model);
}
}

View File

@ -8,8 +8,8 @@ namespace VeterinaryContracts.BusinessLogicContracts
{
List<VisitViewModel>? ReadList(VisitSearchModel? model);
VisitViewModel? ReadElement(VisitSearchModel model);
bool CreateVisit(VisitBindingModel model);
bool BeginVisit(VisitBindingModel model);
bool FinishVisit(VisitBindingModel model);
bool Create(VisitBindingModel model);
bool Update(VisitBindingModel model);
bool Delete(VisitBindingModel model);
}
}

View File

@ -1,14 +1,11 @@
using VeterinaryDataModels.Enums;
namespace VeterinaryContracts.SearchModels
namespace VeterinaryContracts.SearchModels
{
public class PurchaseSearchModel
{
public int? Id { get; set; }
public int? OwnerId { get; set; }
public int? DrugId { get; set; }
public PurchaseStatus? Status { get; set; }
public DateTime? DateCreate { get; set; }
public DateTime? DateImplement { get; set; }
public DateTime? DateImplement { get; set;}
}
}

View File

@ -1,6 +1,4 @@
using VeterinaryDataModels.Enums;
namespace VeterinaryContracts.SearchModels
namespace VeterinaryContracts.SearchModels
{
public class VisitSearchModel
{
@ -8,7 +6,6 @@ namespace VeterinaryContracts.SearchModels
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

@ -1,5 +1,4 @@
using System.ComponentModel;
using VeterinaryDataModels.Enums;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
@ -15,8 +14,6 @@ namespace VeterinaryContracts.ViewModels
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Статус")]
public PurchaseStatus Status { get; set; }
[DisplayName("Дата покупки")]
public DateTime DateCreate { get; set; }
[DisplayName("Дата завершения покупки")]

View File

@ -1,5 +1,4 @@
using System.ComponentModel;
using VeterinaryDataModels.Enums;
using VeterinaryDataModels.Models;
namespace VeterinaryContracts.ViewModels
@ -13,8 +12,6 @@ namespace VeterinaryContracts.ViewModels
public int? DoctorId { get; set; } = null;
[DisplayName("Название визита")]
public string VisitName { get; set; } = string.Empty;
[DisplayName("Статус")]
public VisitStatus Status { get; set; }
[DisplayName("Дата посещения")]
public DateTime DateVisit { get; set; }
public Dictionary<int, IPetModel> VisitPet { get; set; } = new();

View File

@ -1,11 +0,0 @@
namespace VeterinaryDataModels.Enums
{
public enum PurchaseStatus
{
Неизвестен = -1,
Принят = 0,
Собирается = 1,
Готов = 2,
Выдан = 3
}
}

View File

@ -1,10 +0,0 @@
namespace VeterinaryDataModels.Enums
{
public enum VisitStatus
{
Неизвестен = -1,
Забронировано = 0,
Выполняется = 1,
Закончен = 2,
}
}

View File

@ -1,6 +1,4 @@
using VeterinaryDataModels.Enums;
namespace VeterinaryDataModels.Models
namespace VeterinaryDataModels.Models
{
public interface IPurchaseModel : IId
{
@ -8,9 +6,8 @@ namespace VeterinaryDataModels.Models
int DrugId { get; }
int Count { get; }
double Sum { get; }
PurchaseStatus Status { get; }
DateTime DateCreate { get; }
DateTime DateImplement { get; }
Dictionary<int, IPetModel> PurchasePet { get; }
DateTime DateImplement { get; }
Dictionary<int, IPetModel> PurchasePet { get; }
}
}

View File

@ -1,6 +1,4 @@
using VeterinaryDataModels.Enums;
namespace VeterinaryDataModels.Models
namespace VeterinaryDataModels.Models
{
public interface IVisitModel : IId
{
@ -8,7 +6,6 @@ namespace VeterinaryDataModels.Models
int? DoctorId { get; }
string VisitName { get; }
DateTime DateVisit { get; }
VisitStatus Status { get; }
Dictionary<int, IPetModel> VisitPet { get; }
}
}

View File

@ -2,7 +2,6 @@
using System.ComponentModel.DataAnnotations.Schema;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryDataModels.Enums;
using VeterinaryDataModels.Models;
namespace VeterinaryDatabaseImplement.Models
@ -21,10 +20,9 @@ namespace VeterinaryDatabaseImplement.Models
[Required]
public double Sum { get; private set; }
[Required]
public PurchaseStatus Status { get; private set; }
[Required]
public DateTime DateCreate { get; private set; }
public DateTime DateImplement { get; private set; }
[Required]
public DateTime DateImplement { get; private set; }
private Dictionary<int, IPetModel>? _purchasePet = null;
[NotMapped]
public Dictionary<int, IPetModel> PurchasePet
@ -51,9 +49,7 @@ namespace VeterinaryDatabaseImplement.Models
Sum = model.Sum,
OwnerId = model.OwnerId,
DrugId = model.DrugId,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
Pets = model.PurchasePet.Select(x => new PurchasePet
{
Pet = context.Pets.First(y => y.Id == x.Key),
@ -67,7 +63,6 @@ namespace VeterinaryDatabaseImplement.Models
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public PurchaseViewModel GetViewModel => new()
@ -77,7 +72,6 @@ namespace VeterinaryDatabaseImplement.Models
Sum = Sum,
OwnerId = OwnerId,
DrugId = DrugId,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};

View File

@ -3,7 +3,6 @@ using System.ComponentModel.DataAnnotations;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryDataModels.Models;
using VeterinaryDataModels.Enums;
namespace VeterinaryDatabaseImplement.Models
{
@ -17,9 +16,7 @@ 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; }
public string VisitName { get; private set; } = string.Empty;
[Required]
public DateTime DateVisit { get; private set; }
private Dictionary<int, IPetModel>? _visitPet = null;
@ -48,7 +45,7 @@ namespace VeterinaryDatabaseImplement.Models
Id = model.Id,
OwnerId = model.OwnerId,
DoctorId = model.DoctorId,
Status = model.Status,
VisitName = model.VisitName,
DateVisit = model.DateVisit,
Pets = model.VisitPet.Select(x => new VisitPet
{
@ -63,14 +60,14 @@ namespace VeterinaryDatabaseImplement.Models
{
return;
}
Status = model.Status;
VisitName = model.VisitName;
}
public VisitViewModel GetViewModel => new()
{
Id = Id,
OwnerId = OwnerId,
VisitName = VisitName,
DoctorId = DoctorId,
Status = Status,
DateVisit = DateVisit
};
}

View File

@ -52,7 +52,7 @@ namespace VeterinaryRestApi.Controllers
{
try
{
return _visit.CreateVisit(model);
return _visit.Create(model);
}
catch (Exception ex)
{