diff --git a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/PurchaseLogic.cs b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/PurchaseLogic.cs index 38aebd6..7894ace 100644 --- a/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/PurchaseLogic.cs +++ b/VeterinaryView/VeterinaryBusinessLogic/BusinessLogic/PurchaseLogic.cs @@ -58,7 +58,23 @@ namespace VeterinaryBusinessLogic.BusinessLogic } return true; } - // dateImplement + public bool ChangeDateImplement(PurchaseBindingModel model) + { + CheckModel(model); + var element = _purchaseStorage.GetElement(new PurchaseSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if(element.DateCreate > DateTime.Now) + { + _logger.LogWarning("DateImplement change operation failed"); + } + model.DateImplement = DateTime.Now; + _purchaseStorage.Update(model); + return true; + } private void CheckModel(PurchaseBindingModel model, bool withParams = true) { if (model == null) diff --git a/VeterinaryView/VeterinaryContracts/BindingModels/PurchaseBindingModel.cs b/VeterinaryView/VeterinaryContracts/BindingModels/PurchaseBindingModel.cs index 3fee9c2..e0ed857 100644 --- a/VeterinaryView/VeterinaryContracts/BindingModels/PurchaseBindingModel.cs +++ b/VeterinaryView/VeterinaryContracts/BindingModels/PurchaseBindingModel.cs @@ -10,7 +10,7 @@ namespace VeterinaryContracts.BindingModels public int Count { get; set; } public double Sum { get; set; } public DateTime DateCreate { get; set; } - public DateTime DateImplement { get; set; } + public DateTime? DateImplement { get; set; } public Dictionary PurchasePet { get; set; } = new(); } } diff --git a/VeterinaryView/VeterinaryContracts/BindingModels/VisitBindingModel.cs b/VeterinaryView/VeterinaryContracts/BindingModels/VisitBindingModel.cs index e1cc943..accead9 100644 --- a/VeterinaryView/VeterinaryContracts/BindingModels/VisitBindingModel.cs +++ b/VeterinaryView/VeterinaryContracts/BindingModels/VisitBindingModel.cs @@ -6,7 +6,7 @@ namespace VeterinaryContracts.BindingModels { public int Id { get; set; } public int OwnerId { get; set; } - public int? DoctorId { get; set; } = null; + public int DoctorId { get; set; } public string VisitName { get; set; } = string.Empty; public DateTime DateVisit { get; set; } public Dictionary VisitPet { get; set; } = new(); diff --git a/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IPurchaseLogic.cs b/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IPurchaseLogic.cs index 9066477..575cb4b 100644 --- a/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IPurchaseLogic.cs +++ b/VeterinaryView/VeterinaryContracts/BusinessLogicContracts/IPurchaseLogic.cs @@ -9,5 +9,6 @@ namespace VeterinaryContracts.BusinessLogicContracts List? ReadList(PurchaseSearchModel? model); PurchaseViewModel? ReadElement(PurchaseSearchModel model); bool CreatePurchase(PurchaseBindingModel model); + bool ChangeDateImplement(PurchaseBindingModel model); } } diff --git a/VeterinaryView/VeterinaryDataModels/Models/IPurchaseModel.cs b/VeterinaryView/VeterinaryDataModels/Models/IPurchaseModel.cs index 39bb826..beaa5bf 100644 --- a/VeterinaryView/VeterinaryDataModels/Models/IPurchaseModel.cs +++ b/VeterinaryView/VeterinaryDataModels/Models/IPurchaseModel.cs @@ -7,7 +7,7 @@ int Count { get; } double Sum { get; } DateTime DateCreate { get; } - DateTime DateImplement { get; } + DateTime? DateImplement { get; } Dictionary PurchasePet { get; } } } diff --git a/VeterinaryView/VeterinaryDataModels/Models/IVisitModel.cs b/VeterinaryView/VeterinaryDataModels/Models/IVisitModel.cs index 42bc64c..63066bd 100644 --- a/VeterinaryView/VeterinaryDataModels/Models/IVisitModel.cs +++ b/VeterinaryView/VeterinaryDataModels/Models/IVisitModel.cs @@ -3,7 +3,7 @@ public interface IVisitModel : IId { int OwnerId { get; } - int? DoctorId { get; } + int DoctorId { get; } string VisitName { get; } DateTime DateVisit { get; } Dictionary VisitPet { get; } diff --git a/VeterinaryView/VeterinaryRestApi/Controllers/PurchaseController.cs b/VeterinaryView/VeterinaryRestApi/Controllers/PurchaseController.cs index 33aafb9..2fd05c0 100644 --- a/VeterinaryView/VeterinaryRestApi/Controllers/PurchaseController.cs +++ b/VeterinaryView/VeterinaryRestApi/Controllers/PurchaseController.cs @@ -3,6 +3,7 @@ using VeterinaryContracts.BindingModels; using VeterinaryContracts.BusinessLogicContracts; using VeterinaryContracts.SearchModels; using VeterinaryContracts.ViewModels; +using VeterinaryDatabaseImplement.Models; namespace VeterinaryRestApi.Controllers { @@ -59,5 +60,19 @@ namespace VeterinaryRestApi.Controllers throw; } } + [HttpPost] + public bool ChangeDateImplement(PurchaseBindingModel model) + { + try + { + _purchase.ChangeDateImplement(model); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Не удалось обновить покупку"); + throw; + } + } } } diff --git a/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/Purchases.cshtml b/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/Purchases.cshtml index bb56de6..4edc322 100644 --- a/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/Purchases.cshtml +++ b/VeterinaryView/VeterinaryShowOwnerApp/Views/Home/Purchases.cshtml @@ -39,6 +39,7 @@ + }