Исполнитель: добавил статусы
This commit is contained in:
parent
1e139daa5f
commit
e3f5e6b290
@ -4,6 +4,7 @@ using VeterinaryContracts.BusinessLogicContracts;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels.Enums;
|
||||
|
||||
namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
@ -58,6 +59,40 @@ 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.Выдан);
|
||||
}
|
||||
private void CheckModel(PurchaseBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
@ -72,15 +107,15 @@ namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
if (model.DatePurchase <= DateTime.Now)
|
||||
if (model.DateCreate <= DateTime.Now)
|
||||
{
|
||||
throw new ArgumentNullException("Дата покупки не должна быть в прошлом", nameof(model.DatePurchase));
|
||||
throw new ArgumentNullException("Дата покупки не должна быть в прошлом", nameof(model.DateCreate));
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count));
|
||||
}
|
||||
_logger.LogInformation("Purchase. DatePuchase: { DatePurchase}. Count:{ Count}. Id: { Id}", model.DatePurchase, model.Count, model.Id);
|
||||
_logger.LogInformation("Purchase. DatePuchase: { DatePurchase}. Count:{ Count}. Id: { Id}", model.DateCreate, model.Count, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using VeterinaryContracts.BusinessLogicContracts;
|
||||
using VeterinaryContracts.SearchModels;
|
||||
using VeterinaryContracts.StorageContracts;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels.Enums;
|
||||
|
||||
namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
{
|
||||
@ -59,6 +60,35 @@ namespace VeterinaryBusinessLogic.BusinessLogic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool ChangeStatus(VisitBindingModel model, VisitStatus status)
|
||||
{
|
||||
CheckModel(model);
|
||||
var element = _visitStorage.GetElement(new VisitSearchModel { 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 == VisitStatus.Закончен) model.DateVisit = DateTime.Now;
|
||||
_visitStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool BeginVisit(VisitBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, VisitStatus.Выполняется);
|
||||
}
|
||||
|
||||
public bool FinishVisit(VisitBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, VisitStatus.Закончен);
|
||||
}
|
||||
private void CheckModel(VisitBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
|
@ -3,11 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class DoctorBindingModel : IDoctorModel
|
||||
public class DoctorBindingModel : IDoctorModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string DoctorFIO { get; set; } = string.Empty;
|
||||
|
@ -3,11 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class DrugBindingModel : IDrugModel
|
||||
public class DrugBindingModel : IDrugModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string DrugName { get; set; } = string.Empty;
|
||||
|
@ -3,11 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class MedicationBindingModel : IMedicationModel
|
||||
public class MedicationBindingModel : IMedicationModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string MedicationName { get; set; } = string.Empty;
|
||||
|
@ -1,8 +1,8 @@
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class OwnerBindingModel : IOwnerModel
|
||||
public class OwnerBindingModel : IOwnerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string OwnerFIO { get; set; } = string.Empty;
|
||||
|
@ -1,8 +1,8 @@
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class PetBindingModel : IPetModel
|
||||
public class PetBindingModel : IPetModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int OwnerId { get; set; }
|
||||
|
@ -1,15 +1,19 @@
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Enums;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class PurchaseBindingModel : IPurchaseModel
|
||||
public class PurchaseBindingModel : IPurchaseModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int OwnerId { get; set; }
|
||||
public int DrugId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public DateTime DatePurchase { get; set; }
|
||||
public PurchaseStatus Status { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
public DateTime DateImplement { get; set; }
|
||||
|
||||
public Dictionary<int, IPetModel> PurchasePet { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -3,11 +3,11 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class ServiceBindingModel : IServiceModel
|
||||
public class ServiceBindingModel : IServiceModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
|
@ -1,12 +1,14 @@
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Enums;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.BindingModels
|
||||
{
|
||||
public class VisitBindingModel : IVisitModel
|
||||
public class VisitBindingModel : IVisitModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int OwnerId { get; set; }
|
||||
public int? DoctorId { get; set; } = null;
|
||||
public VisitStatus Status { get; set; }
|
||||
public DateTime DateVisit { get; set; }
|
||||
public Dictionary<int, IPetModel> VisitPet { get; set; } = new();
|
||||
}
|
||||
|
@ -9,5 +9,8 @@ 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);
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,7 @@ namespace VeterinaryContracts.BusinessLogicContracts
|
||||
List<VisitViewModel>? ReadList(VisitSearchModel? model);
|
||||
VisitViewModel? ReadElement(VisitSearchModel model);
|
||||
bool CreateVisit(VisitBindingModel model);
|
||||
bool BeginVisit(VisitBindingModel model);
|
||||
bool FinishVisit(VisitBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
namespace VeterinaryContracts.SearchModels
|
||||
using VeterinaryDataModels.Enums;
|
||||
|
||||
namespace VeterinaryContracts.SearchModels
|
||||
{
|
||||
public class PurchaseSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? OwnerId { get; set; }
|
||||
public int? DrugId { get; set; }
|
||||
public DateTime? DatePurchase { get; set; }
|
||||
public PurchaseStatus? Status { get; set; }
|
||||
public DateTime? DateCreate { get; set; }
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
namespace VeterinaryContracts.SearchModels
|
||||
using VeterinaryDataModels.Enums;
|
||||
|
||||
namespace VeterinaryContracts.SearchModels
|
||||
{
|
||||
public class VisitSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? OwnerId { get; set; }
|
||||
public int? DoctorId { get; set; }
|
||||
public VisitStatus? Status { get; set; }
|
||||
public DateTime? DateVisit { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace VeterinaryContracts.StorageContracts
|
||||
List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model);
|
||||
PurchaseViewModel? GetElement(PurchaseSearchModel model);
|
||||
PurchaseViewModel? Insert(PurchaseBindingModel model);
|
||||
PurchaseViewModel? Update(PurchaseBindingModel model);
|
||||
PurchaseViewModel? Delete(PurchaseBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace VeterinaryContracts.StorageContracts
|
||||
List<VisitViewModel> GetFilteredList(VisitSearchModel model);
|
||||
VisitViewModel? GetElement(VisitSearchModel model);
|
||||
VisitViewModel? Insert(VisitBindingModel model);
|
||||
VisitViewModel? Update(VisitBindingModel model);
|
||||
VisitViewModel? Delete(VisitBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class DoctorViewModel : IDoctorModel
|
||||
public class DoctorViewModel : IDoctorModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("ФИО доктора")]
|
||||
|
@ -4,11 +4,11 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class DrugViewModel : IDrugModel
|
||||
public class DrugViewModel : IDrugModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название лекарства")]
|
||||
|
@ -4,11 +4,11 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class MedicationViewModel : IMedicationModel
|
||||
public class MedicationViewModel : IMedicationModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название медикамента")]
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System.ComponentModel;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class OwnerViewModel : IOwnerModel
|
||||
public class OwnerViewModel : IOwnerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("ФИО хозяина")]
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System.ComponentModel;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class PetViewModel : IPetModel
|
||||
public class PetViewModel : IPetModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Хозяин")]
|
||||
|
@ -1,9 +1,10 @@
|
||||
using System.ComponentModel;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Enums;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class PurchaseViewModel : IPurchaseModel
|
||||
public class PurchaseViewModel : IPurchaseModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Хозяин")]
|
||||
@ -14,8 +15,12 @@ namespace VeterinaryContracts.ViewModels
|
||||
public int Count { get; set; }
|
||||
[DisplayName("Сумма")]
|
||||
public double Sum { get; set; }
|
||||
[DisplayName("Статус")]
|
||||
public PurchaseStatus Status { get; set; }
|
||||
[DisplayName("Дата покупки")]
|
||||
public DateTime DatePurchase { get; set; }
|
||||
public DateTime DateCreate { get; set; }
|
||||
[DisplayName("Дата завершения покупки")]
|
||||
public DateTime DateImplement { get; set; }
|
||||
public Dictionary<int, IPetModel> PurchasePet { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,11 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class ServiceViewModel : IServiceModel
|
||||
public class ServiceViewModel : IServiceModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название услуги")]
|
||||
|
@ -1,15 +1,18 @@
|
||||
using System.ComponentModel;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Enums;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryContracts.ViewModels
|
||||
{
|
||||
public class VisitViewModel : IVisitModel
|
||||
public class VisitViewModel : IVisitModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Хозяин")]
|
||||
public int OwnerId { get; set; }
|
||||
[DisplayName("Врач")]
|
||||
public int? DoctorId { get; set; } = null;
|
||||
[DisplayName("Статус")]
|
||||
public VisitStatus Status { get; set; }
|
||||
[DisplayName("Дата посещения")]
|
||||
public DateTime DateVisit { get; set; }
|
||||
public Dictionary<int, IPetModel> VisitPet { get; set; } = new();
|
||||
|
11
VeterinaryView/VeterinaryDataModels/Enums/PurchaseStatus.cs
Normal file
11
VeterinaryView/VeterinaryDataModels/Enums/PurchaseStatus.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace VeterinaryDataModels.Enums
|
||||
{
|
||||
public enum PurchaseStatus
|
||||
{
|
||||
Неизвестен = -1,
|
||||
Принят = 0,
|
||||
Собирается = 1,
|
||||
Готов = 2,
|
||||
Выдан = 3
|
||||
}
|
||||
}
|
10
VeterinaryView/VeterinaryDataModels/Enums/VisitStatus.cs
Normal file
10
VeterinaryView/VeterinaryDataModels/Enums/VisitStatus.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace VeterinaryDataModels.Enums
|
||||
{
|
||||
public enum VisitStatus
|
||||
{
|
||||
Неизвестен = -1,
|
||||
Забронировано = 0,
|
||||
Выполняется = 1,
|
||||
Закончен = 2,
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryDataModels
|
||||
{
|
||||
public interface IDoctorModel : IId
|
||||
{
|
||||
string DoctorFIO { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
|
||||
}
|
||||
}
|
@ -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, int)> DrugMedications { get; }
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryDataModels
|
||||
{
|
||||
public interface IMedicationModel : IId
|
||||
{
|
||||
string MedicationName { get;}
|
||||
double Price { get;}
|
||||
int DoctorId { get;}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
namespace VeterinaryDataModels
|
||||
{
|
||||
public interface IOwnerModel : IId
|
||||
{
|
||||
string OwnerFIO { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
namespace VeterinaryDataModels
|
||||
{
|
||||
public interface IPetModel : IId
|
||||
{
|
||||
int OwnerId { get; }
|
||||
string PetName { get; }
|
||||
string PetType { get; }
|
||||
string PetBreed { get; }
|
||||
string PetGender { get; }
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
namespace VeterinaryDataModels
|
||||
{
|
||||
public interface IPurchaseModel : IId
|
||||
{
|
||||
int OwnerId { get; }
|
||||
int DrugId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
DateTime DatePurchase { get; }
|
||||
Dictionary<int, IPetModel> PurchasePet { get; }
|
||||
}
|
||||
}
|
@ -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, int)> ServiceMedications { get; }
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace VeterinaryDataModels
|
||||
{
|
||||
public interface IVisitModel : IId
|
||||
{
|
||||
int OwnerId { get; }
|
||||
int? DoctorId { get; }
|
||||
DateTime DateVisit { get; }
|
||||
Dictionary<int, IPetModel> VisitPet { get; }
|
||||
}
|
||||
}
|
16
VeterinaryView/VeterinaryDataModels/Models/IDoctorModel.cs
Normal file
16
VeterinaryView/VeterinaryDataModels/Models/IDoctorModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryDataModels.Models
|
||||
{
|
||||
public interface IDoctorModel : IId
|
||||
{
|
||||
string DoctorFIO { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
|
||||
}
|
||||
}
|
16
VeterinaryView/VeterinaryDataModels/Models/IDrugModel.cs
Normal file
16
VeterinaryView/VeterinaryDataModels/Models/IDrugModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryDataModels.Models
|
||||
{
|
||||
public interface IDrugModel : IId
|
||||
{
|
||||
string DrugName { get; }
|
||||
int Count { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IMedicationModel, int)> DrugMedications { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryDataModels.Models
|
||||
{
|
||||
public interface IMedicationModel : IId
|
||||
{
|
||||
string MedicationName { get; }
|
||||
double Price { get; }
|
||||
int DoctorId { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace VeterinaryDataModels.Models
|
||||
{
|
||||
public interface IOwnerModel : IId
|
||||
{
|
||||
string OwnerFIO { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
11
VeterinaryView/VeterinaryDataModels/Models/IPetModel.cs
Normal file
11
VeterinaryView/VeterinaryDataModels/Models/IPetModel.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace VeterinaryDataModels.Models
|
||||
{
|
||||
public interface IPetModel : IId
|
||||
{
|
||||
int OwnerId { get; }
|
||||
string PetName { get; }
|
||||
string PetType { get; }
|
||||
string PetBreed { get; }
|
||||
string PetGender { get; }
|
||||
}
|
||||
}
|
16
VeterinaryView/VeterinaryDataModels/Models/IPurchaseModel.cs
Normal file
16
VeterinaryView/VeterinaryDataModels/Models/IPurchaseModel.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using VeterinaryDataModels.Enums;
|
||||
|
||||
namespace VeterinaryDataModels.Models
|
||||
{
|
||||
public interface IPurchaseModel : IId
|
||||
{
|
||||
int OwnerId { get; }
|
||||
int DrugId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
PurchaseStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime DateImplement { get; }
|
||||
Dictionary<int, IPetModel> PurchasePet { get; }
|
||||
}
|
||||
}
|
17
VeterinaryView/VeterinaryDataModels/Models/IServiceModel.cs
Normal file
17
VeterinaryView/VeterinaryDataModels/Models/IServiceModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VeterinaryDataModels.Models
|
||||
{
|
||||
public interface IServiceModel : IId
|
||||
{
|
||||
string ServiceName { get; }
|
||||
int VisitId { get; }
|
||||
int DoctorId { get; }
|
||||
Dictionary<int, (IMedicationModel, int)> ServiceMedications { get; }
|
||||
|
||||
}
|
||||
}
|
13
VeterinaryView/VeterinaryDataModels/Models/IVisitModel.cs
Normal file
13
VeterinaryView/VeterinaryDataModels/Models/IVisitModel.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using VeterinaryDataModels.Enums;
|
||||
|
||||
namespace VeterinaryDataModels.Models
|
||||
{
|
||||
public interface IVisitModel : IId
|
||||
{
|
||||
int OwnerId { get; }
|
||||
int? DoctorId { get; }
|
||||
DateTime DateVisit { get; }
|
||||
VisitStatus Status { get; }
|
||||
Dictionary<int, IPetModel> VisitPet { get; }
|
||||
}
|
||||
}
|
@ -21,7 +21,8 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Purchases.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Drug)
|
||||
.Where(x => ((!model.Id.HasValue || x.Id == model.Id) &&
|
||||
(!model.DatePurchase.HasValue || x.DatePurchase >= model.DatePurchase) &&
|
||||
(!model.DateCreate.HasValue || x.DateCreate >= model.DateCreate) &&
|
||||
(!model.DateImplement.HasValue || x.DateImplement >= model.DateImplement) &&
|
||||
(!model.OwnerId.HasValue || x.OwnerId <= model.OwnerId) &&
|
||||
(!model.DrugId.HasValue || x.DrugId == model.DrugId)))
|
||||
.Select(x => x.GetViewModel)
|
||||
@ -29,11 +30,13 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
}
|
||||
public PurchaseViewModel? GetElement(PurchaseSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new VeterinaryDatabase();
|
||||
return context.Purchases.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Drug).FirstOrDefault(
|
||||
x => ((model.Id.HasValue && x.Id == model.Id) ||
|
||||
(model.OwnerId.HasValue && model.DrugId.HasValue &&
|
||||
x.OwnerId == model.OwnerId && x.DrugId == model.DrugId)))?.GetViewModel;
|
||||
return context.Purchases.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Drug)
|
||||
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
public PurchaseViewModel? Insert(PurchaseBindingModel model)
|
||||
{
|
||||
@ -47,6 +50,18 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
context.SaveChanges();
|
||||
return newPurchase.GetViewModel;
|
||||
}
|
||||
public PurchaseViewModel? Update(PurchaseBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var purchase = context.Purchases.Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Owner).FirstOrDefault(x => x.Id == model.Id);
|
||||
if (purchase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
purchase.Update(model);
|
||||
context.SaveChanges();
|
||||
return purchase.GetViewModel;
|
||||
}
|
||||
public PurchaseViewModel? Delete(PurchaseBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
|
@ -29,11 +29,13 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
}
|
||||
public VisitViewModel? GetElement(VisitSearchModel model)
|
||||
{
|
||||
if (!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 => ((model.Id.HasValue && x.Id == model.Id) ||
|
||||
(model.OwnerId.HasValue && model.DoctorId.HasValue &&
|
||||
x.OwnerId == model.OwnerId && x.DoctorId == model.DoctorId)))?.GetViewModel;
|
||||
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;
|
||||
}
|
||||
public VisitViewModel? Insert(VisitBindingModel model)
|
||||
{
|
||||
@ -47,6 +49,19 @@ namespace VeterinaryDatabaseImplement.Implements
|
||||
context.SaveChanges();
|
||||
return newVisit.GetViewModel;
|
||||
}
|
||||
public VisitViewModel? Update(VisitBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
var visit = context.Visits.Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Owner)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (visit == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
visit.Update(model);
|
||||
context.SaveChanges();
|
||||
return visit.GetViewModel;
|
||||
}
|
||||
public VisitViewModel? Delete(VisitBindingModel model)
|
||||
{
|
||||
using var context = new VeterinaryDatabase();
|
||||
|
@ -5,13 +5,13 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Doctor : IDoctorModel
|
||||
public class Doctor : IDoctorModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
|
@ -5,13 +5,13 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Drug : IDrugModel
|
||||
public class Drug : IDrugModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
|
@ -6,13 +6,13 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Medication : IMedicationModel
|
||||
public class Medication : IMedicationModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
|
@ -1,12 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Owner : IOwnerModel
|
||||
public class Owner : IOwnerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
|
@ -1,12 +1,12 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Pet : IPetModel
|
||||
public class Pet : IPetModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
|
@ -2,11 +2,12 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Enums;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Purchase : IPurchaseModel
|
||||
public class Purchase : IPurchaseModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
@ -20,7 +21,10 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
[Required]
|
||||
public DateTime DatePurchase { get; private set; }
|
||||
public PurchaseStatus Status { get; private set; }
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; }
|
||||
public DateTime DateImplement { get; private set; }
|
||||
private Dictionary<int, IPetModel>? _purchasePet = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IPetModel> PurchasePet
|
||||
@ -47,7 +51,9 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
Sum = model.Sum,
|
||||
OwnerId = model.OwnerId,
|
||||
DrugId = model.DrugId,
|
||||
DatePurchase = model.DatePurchase,
|
||||
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),
|
||||
@ -55,6 +61,15 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(PurchaseBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
public PurchaseViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
@ -62,7 +77,9 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
Sum = Sum,
|
||||
OwnerId = OwnerId,
|
||||
DrugId = DrugId,
|
||||
DatePurchase = DatePurchase
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Service : IServiceModel
|
||||
public class Service : IServiceModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
|
@ -2,11 +2,12 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using VeterinaryContracts.BindingModels;
|
||||
using VeterinaryContracts.ViewModels;
|
||||
using VeterinaryDataModels;
|
||||
using VeterinaryDataModels.Models;
|
||||
using VeterinaryDataModels.Enums;
|
||||
|
||||
namespace VeterinaryDatabaseImplement.Models
|
||||
{
|
||||
public class Visit : IVisitModel
|
||||
public class Visit : IVisitModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
@ -16,6 +17,8 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
public int? DoctorId { get; private set; }
|
||||
public virtual Doctor? Doctor { get; private set; }
|
||||
[Required]
|
||||
public VisitStatus Status { get; private set; }
|
||||
[Required]
|
||||
public DateTime DateVisit { get; private set; }
|
||||
private Dictionary<int, IPetModel>? _visitPet = null;
|
||||
[NotMapped]
|
||||
@ -43,6 +46,7 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
Id = model.Id,
|
||||
OwnerId = model.OwnerId,
|
||||
DoctorId = model.DoctorId,
|
||||
Status = model.Status,
|
||||
DateVisit = model.DateVisit,
|
||||
Pets = model.VisitPet.Select(x => new VisitPet
|
||||
{
|
||||
@ -51,11 +55,20 @@ namespace VeterinaryDatabaseImplement.Models
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(VisitBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
}
|
||||
public VisitViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
OwnerId = OwnerId,
|
||||
DoctorId = DoctorId,
|
||||
Status = Status,
|
||||
DateVisit = DateVisit
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user