Compare commits

...

2 Commits

Author SHA1 Message Date
f86f0a91e3 Ничего не работает) 2024-04-25 23:52:14 +04:00
gg12 darfren
8d3c75cdf9 Сделали бд 2024-04-24 21:33:21 +04:00
27 changed files with 1770 additions and 932 deletions

View File

@ -1,79 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.BindingModels;
using VetClinicContracts.SearchModels;
using VetClinicContracts.StoragesContracts;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicDataBaseImplement.Implements
{
public class GuidanceStorage : IGuidanceStorage
{
public List<GuidanceViewModel> GetFullList()
{
using var context = new VetClinicDatabase();
return context.Guidances.Include(x => x.Service).Select(x => x.GetViewModel).ToList();
}
public List<GuidanceViewModel> GetFilteredList(GuidanceSearchModel model)
{
using var context = new VetClinicDatabase();
return context.Guidances.Include(x => x.Service).Where(x => (!model.Id.HasValue || model.Id == x.Id)
&& (!model.ServiceId.HasValue || model.ServiceId == x.ServiceId) && (!model.DateFrom.HasValue || model.DateFrom <= x.Date)
&& (!model.DateTo.HasValue || model.DateTo >= x.Date))
.Select(x => x.GetViewModel)
.ToList();
}
public GuidanceViewModel? GetElement(GuidanceSearchModel model)
{
using var context = new VetClinicDatabase();
return context.Guidances.Include(x => x.Service).FirstOrDefault(x => (!model.Id.HasValue || model.Id == x.Id)
&& (!model.ServiceId.HasValue || model.ServiceId == x.ServiceId) && (!model.DateFrom.HasValue || model.DateFrom <= x.Date)
&& (!model.DateTo.HasValue || model.DateTo >= x.Date))?.GetViewModel;
}
public GuidanceViewModel? Insert(GuidanceBindingModel model)
{
using var context = new VetClinicDatabase();
var newGuidance = Guidance.Create(context, model);
if (newGuidance == null)
{
return null;
}
context.Guidances.Add(newGuidance);
context.SaveChanges();
return newGuidance.GetViewModel;
}
public GuidanceViewModel? Update(GuidanceBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Guidances
.Include(x => x.Service)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Guidances.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public GuidanceViewModel? Delete(GuidanceBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Guidances.FirstOrDefault(rec => rec.Id ==
model.Id);
if (element != null)
{
context.Guidances.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -1,105 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.BindingModels;
using VetClinicContracts.SearchModels;
using VetClinicContracts.StoragesContracts;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicDataBaseImplement.Implements
{
public class MedicineStorage : IMedicineStorage
{
public List<MedicineViewModel> GetFullList()
{
using var context = new VetClinicDatabase();
return context.Medicines.Include(x => x.Pharmacist).Include(x => x.Animals)
.ThenInclude(x => x.Animal)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<MedicineViewModel> GetFilteredList(MedicineSearchModel model)
{
using var context = new VetClinicDatabase();
return context.Medicines.Include(x => x.Pharmacist).Include(x => x.Animals)
.ThenInclude(x => x.Animal)
.Where(x => (string.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName)
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId)))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public MedicineViewModel? GetElement(MedicineSearchModel model)
{
if (string.IsNullOrEmpty(model.MedicineName) &&
!model.Id.HasValue)
{
return null;
}
using var context = new VetClinicDatabase();
return context.Medicines.Include(x => x.Pharmacist)
.Include(x => x.Animals)
.ThenInclude(x => x.Animal)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.MedicineName) &&
x.MedicineName == model.MedicineName) ||
(model.Id.HasValue && x.Id ==
model.Id))
?.GetViewModel;
}
public MedicineViewModel? Insert(MedicineBindingModel model)
{
using var context = new VetClinicDatabase();
var newMedicine = Medicine.Create(context, model);
if (newMedicine == null)
{
return null;
}
context.Medicines.Add(newMedicine);
context.SaveChanges();
return newMedicine.GetViewModel;
}
public MedicineViewModel? Update(MedicineBindingModel model)
{
using var context = new VetClinicDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var medicine = context.Medicines.FirstOrDefault(rec =>
rec.Id == model.Id);
if (medicine == null)
{
return null;
}
medicine.Update(model);
context.SaveChanges();
medicine.UpdateAnimals(context, model);
transaction.Commit();
return medicine.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public MedicineViewModel? Delete(MedicineBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Medicines
.Include(x => x.Animals).ThenInclude(x => x.Animal)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Medicines.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -1,89 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.BindingModels;
using VetClinicContracts.SearchModels;
using VetClinicContracts.StoragesContracts;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicDataBaseImplement.Implements
{
public class PharmacistStorage : IPharmacistStorage
{
public List<PharmacistViewModel> GetFullList()
{
using var context = new VetClinicDatabase();
return context.Pharmacists
.Select(x => x.GetViewModel)
.ToList();
}
public List<PharmacistViewModel> GetFilteredList(PharmacistSearchModel model)
{
if (string.IsNullOrEmpty(model.PharmacistFIO) && string.IsNullOrEmpty(model.Email) &&
string.IsNullOrEmpty(model.Password))
{
return new();
}
using var context = new VetClinicDatabase();
return context.Pharmacists
.Where(x => (string.IsNullOrEmpty(model.PharmacistFIO) || x.PharmacistFIO.Contains(model.PharmacistFIO) &&
string.IsNullOrEmpty(model.Email) || x.Email.Contains(model.Email) &&
string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password)))
.Select(x => x.GetViewModel)
.ToList();
}
public PharmacistViewModel? GetElement(PharmacistSearchModel model)
{
if (string.IsNullOrEmpty(model.PharmacistFIO) && string.IsNullOrEmpty(model.Email) &&
!model.Id.HasValue)
{
return null;
}
using var context = new VetClinicDatabase();
return context.Pharmacists
.FirstOrDefault(x => (string.IsNullOrEmpty(model.PharmacistFIO) || x.PharmacistFIO == model.PharmacistFIO) &&
(!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Email) || x.Email == model.Email) &&
(string.IsNullOrEmpty(model.Password) || x.Password == model.Password))
?.GetViewModel;
}
public PharmacistViewModel? Insert(PharmacistBindingModel model)
{
var newPharmacist = Pharmacist.Create(model);
if (newPharmacist == null)
{
return null;
}
using var context = new VetClinicDatabase();
context.Pharmacists.Add(newPharmacist);
context.SaveChanges();
return newPharmacist.GetViewModel;
}
public PharmacistViewModel? Update(PharmacistBindingModel model)
{
using var context = new VetClinicDatabase();
var pharmacist = context.Pharmacists.FirstOrDefault(x => x.Id == model.Id);
if (pharmacist == null)
{
return null;
}
pharmacist.Update(model);
context.SaveChanges();
return pharmacist.GetViewModel;
}
public PharmacistViewModel? Delete(PharmacistBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Pharmacists.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Pharmacists.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -1,110 +0,0 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.BindingModels;
using VetClinicContracts.SearchModels;
using VetClinicContracts.StoragesContracts;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicDataBaseImplement.Implements
{
public class ServiceStorage : IServiceStorage
{
public List<ServiceViewModel> GetFullList()
{
using var context = new VetClinicDatabase();
return context.Services.Include(x => x.Pharmacist)
.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<ServiceViewModel> GetFilteredList(ServiceSearchModel model)
{
using var context = new VetClinicDatabase();
return context.Services.Include(x => x.Pharmacist)
.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.Where(x => (string.IsNullOrEmpty(model.ServiceName) || x.ServiceName.Contains(model.ServiceName)
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId)))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public ServiceViewModel? GetElement(ServiceSearchModel model)
{
if (string.IsNullOrEmpty(model.ServiceName) &&
!model.Id.HasValue)
{
return null;
}
using var context = new VetClinicDatabase();
return context.Services.Include(x => x.Pharmacist)
.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ServiceName) &&
x.ServiceName == model.ServiceName) ||
(model.Id.HasValue && x.Id ==
model.Id))
?.GetViewModel;
}
public ServiceViewModel? Insert(ServiceBindingModel model)
{
using var context = new VetClinicDatabase();
var newService = Service.Create(context, model);
if (newService == null)
{
return null;
}
context.Services.Add(newService);
context.SaveChanges();
return newService.GetViewModel;
}
public ServiceViewModel? Update(ServiceBindingModel model)
{
using var context = new VetClinicDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var iceCream = context.Services.FirstOrDefault(rec =>
rec.Id == model.Id);
if (iceCream == null)
{
return null;
}
iceCream.Update(model);
context.SaveChanges();
iceCream.UpdateMedicines(context, model);
transaction.Commit();
return iceCream.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public ServiceViewModel? Delete(ServiceBindingModel model)
{
using var context = new VetClinicDatabase();
var element = context.Services
.Include(x => x.Medicines)
.ThenInclude(x => x.Medicine)
.ThenInclude(x => x.Animals).ThenInclude(x => x.Animal)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Services.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -1,58 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.BindingModels;
using VetClinicContracts.ViewModels;
using VetClinicDataModels.Models;
namespace VetClinicDataBaseImplement.Models
{
public class Guidance : IGuidanceModel
{
public int Id { get; private set; }
[Required]
public int ServiceId { get; private set; }
public virtual Service Service { get; private set; }
[Required]
public string Text { get; private set; } = string.Empty;
[Required]
public DateTime Date { get; private set; }
public static Guidance? Create(VetClinicDatabase context, GuidanceBindingModel model)
{
if (model == null)
{
return null;
}
return new Guidance()
{
Id = model.Id,
ServiceId = model.ServiceId,
Text = model.Text,
Date = model.Date,
Service = context.Services.FirstOrDefault(x => x.Id == model.ServiceId),
};
}
public void Update(GuidanceBindingModel? model)
{
if (model == null)
{
return;
}
Text = model.Text;
Date = model.Date;
}
public GuidanceViewModel GetViewModel => new()
{
ServiceId = ServiceId,
Text = Text,
Date = Date,
Id = Id,
ServiceName = Service.ServiceName
};
}
}

View File

@ -1,98 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicDataModels.Models;
using VetClinicContracts.BindingModels;
using VetClinicContracts.ViewModels;
namespace VetClinicDataBaseImplement.Models
{
public class Medicine : IMedicineModel
{
public int Id { get; set; }
[Required]
public string MedicineName { get; set; } = string.Empty;
[Required]
public int PharmacistId { get; set; }
public virtual Pharmacist Pharmacist { get; private set; }
[Required]
public double Price { get; set; }
private Dictionary<int, IAnimalModel>? _medicineAnimals =
null;
[NotMapped]
public Dictionary<int, IAnimalModel> MedicineAnimals
{
get
{
if (_medicineAnimals == null)
{
_medicineAnimals = Animals
.ToDictionary(recPC => recPC.AnimalId, recPC =>
recPC.Animal as IAnimalModel);
}
return _medicineAnimals;
}
}
[ForeignKey("MedicineId")]
public virtual List<MedicineAnimal> Animals { get; set; } = new();
[ForeignKey("MedicineId")]
public virtual List<ServiceMedicine> Services { get; set; } = new();
public static Medicine Create(VetClinicDatabase context,
MedicineBindingModel model)
{
return new Medicine()
{
Id = model.Id,
MedicineName = model.MedicineName,
Price = model.Price,
Animals = model.MedicineAnimals.Select(x => new
MedicineAnimal
{
Animal = context.Animals.First(y => y.Id == x.Key),
}).ToList(),
Pharmacist = context.Pharmacists.First(x => x.Id == model.PharmacistId)
};
}
public void Update(MedicineBindingModel model)
{
MedicineName = model.MedicineName;
Price = model.Price;
}
public MedicineViewModel GetViewModel => new()
{
Id = Id,
MedicineName = MedicineName,
Price = Price,
MedicineAnimals = MedicineAnimals,
PharmacistFIO = Pharmacist.PharmacistFIO
};
public void UpdateAnimals(VetClinicDatabase context,
MedicineBindingModel model)
{
var medicineAnimals = context.MedicineAnimals.Where(rec =>
rec.MedicineId == model.Id).ToList();
if (medicineAnimals != null && medicineAnimals.Count > 0)
{
context.MedicineAnimals.RemoveRange(medicineAnimals.Where(rec
=> !model.MedicineAnimals.ContainsKey(rec.AnimalId)));
context.SaveChanges();
}
var medicine = context.Medicines.First(x => x.Id == Id);
foreach (var pc in model.MedicineAnimals)
{
context.MedicineAnimals.Add(new MedicineAnimal
{
Medicine = medicine,
Animal = context.Animals.First(x => x.Id == pc.Key),
});
context.SaveChanges();
}
_medicineAnimals = null;
}
}
}

View File

@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VetClinicDataBaseImplement.Models
{
public class MedicineAnimal
{
public int Id { get; set; }
[Required]
public int MedicineId { get; set; }
[Required]
public int AnimalId { get; set; }
public virtual Medicine Medicine { get; set; } = new();
public virtual Animal Animal { get; set; } = new();
}
}

View File

@ -1,73 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.BindingModels;
using VetClinicContracts.ViewModels;
using VetClinicDataModels.Models;
namespace VetClinicDataBaseImplement.Models
{
public class Pharmacist : IPharmacistModel
{
public int Id { get; private set; }
[Required]
public string PharmacistFIO { get; private set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[ForeignKey("PharmacistId")]
public virtual List<Medicine> Medicines { get; set; } =
new();
[ForeignKey("PharmacistId")]
public virtual List<Service> Services { get; set; } =
new();
public static Pharmacist? Create(PharmacistBindingModel model)
{
if (model == null)
{
return null;
}
return new Pharmacist()
{
Id = model.Id,
PharmacistFIO = model.PharmacistFIO,
Email = model.Email,
Password = model.Password
};
}
public static Pharmacist Create(PharmacistViewModel model)
{
return new Pharmacist()
{
Id = model.Id,
PharmacistFIO = model.PharmacistFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update( PharmacistBindingModel model)
{
if (model == null)
{
return;
}
PharmacistFIO = model.PharmacistFIO;
Email = model.Email;
Password = model.Password;
}
public PharmacistViewModel GetViewModel => new()
{
Id = Id,
PharmacistFIO = PharmacistFIO,
Email = Email,
Password = Password
};
}
}

View File

@ -1,108 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VetClinicDataModels.Models;
using VetClinicContracts.BindingModels;
using VetClinicContracts.ViewModels;
using Microsoft.EntityFrameworkCore;
namespace VetClinicDataBaseImplement.Models
{
public class Service : IServiceModel
{
public int Id { get; set; }
[Required]
public string ServiceName { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
[Required]
public int PharmacistId { get; set; }
public virtual Pharmacist Pharmacist { get; private set; }
private Dictionary<int, (IMedicineModel, int)>? _serviceMedicines =
null;
[NotMapped]
public Dictionary<int, (IMedicineModel, int)> ServiceMedicines
{
get
{
if (_serviceMedicines == null)
{
_serviceMedicines = Medicines
.ToDictionary(recPC => recPC.MedicineId, recPC =>
(recPC.Medicine as IMedicineModel, recPC.Count));
}
return _serviceMedicines;
}
}
[ForeignKey("ServiceId")]
public virtual List<ServiceMedicine> Medicines { get; set; } = new();
[ForeignKey("ServiceId")]
public virtual List<VisitService> Visits { get; set; } = new();
[ForeignKey("ServiceId")]
public virtual List<Guidance> Guidances { get; set; } = new();
public static Service Create(VetClinicDatabase context,
ServiceBindingModel model)
{
return new Service()
{
Id = model.Id,
ServiceName = model.ServiceName,
Price = model.Price,
Medicines = model.ServiceMedicines.Select(x => new
ServiceMedicine
{
Medicine = context.Medicines.First(y => y.Id == x.Key),
Count = x.Value.Item2
}).ToList()
};
}
public void Update(ServiceBindingModel model)
{
ServiceName = model.ServiceName;
Price = model.Price;
}
public ServiceViewModel GetViewModel => new()
{
Id = Id,
ServiceName = ServiceName,
Price = Price,
ServiceMedicines = ServiceMedicines
};
public void UpdateMedicines(VetClinicDatabase context,
ServiceBindingModel model)
{
var serviceMedicines = context.ServiceMedicines.Where(rec =>
rec.ServiceId == model.Id).ToList();
if (serviceMedicines != null && serviceMedicines.Count > 0)
{
context.ServiceMedicines.RemoveRange(serviceMedicines.Where(rec
=> !model.ServiceMedicines.ContainsKey(rec.MedicineId)));
context.SaveChanges();
foreach (var updateComponent in serviceMedicines)
{
updateComponent.Count =
model.ServiceMedicines[updateComponent.MedicineId].Item2;
model.ServiceMedicines.Remove(updateComponent.MedicineId);
}
context.SaveChanges();
}
var service = context.Services.First(x => x.Id == Id);
foreach (var pc in model.ServiceMedicines)
{
context.ServiceMedicines.Add(new ServiceMedicine
{
Service = service,
Medicine = context.Medicines.Include(x => x.Animals).ThenInclude(x => x.Animal).First(x => x.Id == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_serviceMedicines = null;
}
}
}

View File

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VetClinicDataBaseImplement.Models
{
public class ServiceMedicine
{
public int Id { get; set; }
[Required]
public int ServiceId { get; set; }
[Required]
public int MedicineId { get; set; }
[Required]
public int Count { get; set; }
public virtual Service Service { get; set; } = new();
public virtual Medicine Medicine { get; set; } = new();
}
}

View File

@ -1,152 +1,226 @@
using Microsoft.AspNetCore.Mvc;
using VetClinicAdminApp.Models;
using System.Diagnostics;
using VetClinicContracts.BindingModels;
using VetClinicContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
namespace VetClinicAdminApp.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
public IActionResult Index()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
return
View(APIAdmin.GetRequest<List<VisitViewModel>>($"api/visit/getvisits?vistId={APIAdmin.Admin.Id}"));
return View(APIAdmin.GetRequest<List<VisitViewModel>>($"api/main/getorders?clientId={APIAdmin.Admin.Id}"));
}
}
[HttpGet]
public IActionResult Privacy()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
[HttpGet]
public IActionResult Privacy()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
return View(APIAdmin.Admin);
}
return View(APIAdmin.Admin);
}
[HttpPost]
public void Privacy(string login, string password, string fio)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Ââåäèòå email, ïàðîëü è ÔÈÎ");
}
APIAdmin.PostRequest("api/admin/updatedata", new
AdminBindingModel
{
Id = APIAdmin.Admin.Id,
AdminFIO = fio,
Email = login,
Password = password
});
APIAdmin.Admin.AdminFIO = fio;
APIAdmin.Admin.Email = login;
APIAdmin.Admin.Password = password;
Response.Redirect("Index");
}
[HttpPost]
public void Privacy(string login, string password, string fio)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
}
[HttpGet]
public IActionResult Enter()
{
return View();
}
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password))
{
throw new Exception("Ââåäèòå email è ïàðîëü");
}
APIAdmin.Admin =
APIAdmin.GetRequest<AdminViewModel>($"api/admin/login?login={login}&password={password}");
if (APIAdmin.Admin == null)
{
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string password, string fio)
{
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
}
APIAdmin.PostRequest("api/admin/register", new
AdminBindingModel
{
AdminFIO = fio,
Email = login,
Password = password
});
Response.Redirect("Enter");
return;
}
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
}
public IActionResult Create()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
APIAdmin.PostRequest("api/admin/updatedata", new AdminBindingModel
{
AdminId = APIAdmin.Admin.Id,
AdminFIO = fio,
Email = login,
Password = password
});
APIAdmin.Admin.AdminFIO = fio;
APIAdmin.Admin.Email = login;
APIAdmin.Admin.Password = password;
Response.Redirect("Index");
}
[HttpPost]
public void CreateVisit(string name, DateTime visitdate)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(name))
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
APIAdmin.PostRequest("api/visit/createvisit", new VisitBindingModel
{
NameVisit = name,
DateVisit = visitdate,
AdminId = APIAdmin.Admin.Id
});
Response.Redirect("Index");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
});
}
public IActionResult DeleteMedicine()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Visits = APIAdmin.GetRequest<List<VisitViewModel>>("api/visit/getvisits");
return View();
}
[HttpGet]
public IActionResult Enter()
{
return View();
}
[HttpPost]
public void DeleteVisit(int shop)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
APIAdmin.PostRequest("api/visit/deletevisit", new VisitBindingModel
{
Id = shop
});
Response.Redirect("Index");
}
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
throw new Exception("Ââåäèòå ëîãèí è ïàðîëü");
}
public IActionResult Update()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Medicines = APIAdmin.GetRequest<List<MedicineViewModel>>("api/shop/getvisits");
return View();
}
APIAdmin.Admin = APIAdmin.GetRequest<AdminViewModel>($"api/admin/login?login={login}&password={password}");
[HttpPost]
public void Update(int visit, string name, DateTime vistdate)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(name) )
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
APIAdmin.PostRequest("api/visit/updatevisit", new VisitBindingModel
{
Id = visit,
NameVisit = name,
DateVisit = vistdate,
});
Response.Redirect("Index");
}
if (APIAdmin.Admin == null)
{
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string password, string fio)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
}
APIAdmin.PostRequest("api/admin/register", new AdminBindingModel
{
AdminFIO = fio,
Email = login,
Password = password
});
Response.Redirect("Enter");
return;
}
// [HttpGet]
// public IActionResult Create()
// {
// ViewBag.Snacks = APIAdmin.GetRequest<List<AnimalViewModel>>("api/main/getanimallist");
// return View();
// }
[HttpPost]
public void Create(int animal)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
}
//APIAdmin.PostRequest("api/main/createorder", new VisitBindingModel
//{
// AdminId = APIAdmin.Admin.Id,
// AnimalId = animal,
// });
Response.Redirect("Index");
}
}
}
[HttpGet]
public Tuple<VisitViewModel, string>? GetMedicine(int visitId)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
var result = APIAdmin.GetRequest<Tuple<VisitViewModel, List<string>>>($"api/visit/getvisit?visitid={visitId}");
if (result == null)
{
return default;
}
string table = "";
result.Item1.VisitAnimals.Clear();
for (int i = 0; i < result.Item2.Count; i++)
{
var animal = result.Item2[i];
table += "<tr>";
table += $"<td>{animal}</td>";
table += "</tr>";
}
return Tuple.Create(result.Item1, table);
}
}
}

View File

@ -7,6 +7,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

View File

@ -21,16 +21,18 @@ namespace VetClinicBusinessLogic.BusinessLogics
_logger = logger;
_visitStorage = visitStorage;
}
public List<VisitViewModel>? ReadList(VisitSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _visitStorage.GetFullList() : _visitStorage.GetFilteredList(model);
_logger.LogInformation("ReadList. NameVisit:{NameVisit}. Id:{ Id}", model?.NameVisit, model?.Id);
var list = model == null ? _visitStorage.GetFullList() :
_visitStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
return list;
}
public VisitViewModel? ReadElement(VisitSearchModel model)
@ -39,8 +41,7 @@ namespace VetClinicBusinessLogic.BusinessLogics
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadList. NameVisit:{NameVisit}. DateVisit {DateVisit}. Id:{Id}", model.NameVisit, model.DateVisit, model?.Id);
_logger.LogInformation("ReadElement. NameVisit:{NameVisit}.Id:{ Id}", model.NameVisit, model.Id);
var element = _visitStorage.GetElement(model);
if (element == null)
{
@ -54,7 +55,6 @@ namespace VetClinicBusinessLogic.BusinessLogics
public bool Create(VisitBindingModel model)
{
CheckModel(model);
if (_visitStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
@ -73,7 +73,6 @@ namespace VetClinicBusinessLogic.BusinessLogics
}
return true;
}
public bool Delete(VisitBindingModel model)
{
CheckModel(model, false);
@ -85,7 +84,9 @@ namespace VetClinicBusinessLogic.BusinessLogics
}
return true;
}
private void CheckModel(VisitBindingModel model, bool withParams = true)
private void CheckModel(VisitBindingModel model, bool withParams =
true)
{
if (model == null)
{
@ -95,24 +96,21 @@ namespace VetClinicBusinessLogic.BusinessLogics
{
return;
}
if (model.NameVisit == "")
if (string.IsNullOrEmpty(model.NameVisit))
{
throw new ArgumentNullException("Имя не должно быть пустым", nameof(model.NameVisit));
throw new ArgumentNullException("Нет названия визита",
nameof(model.NameVisit));
}
if (model.AdminId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.AdminId));
}
if (model.DateVisit == new DateTime())
{
throw new ArgumentNullException("Укажите Время", nameof(model.DateVisit));
}
_logger.LogInformation("Medicine. Medicine:{NameVisit}. Id: { Id}", model.NameVisit, model.Id);
var element = _visitStorage.GetElement(new VisitSearchModel
{
Id = model.Id
NameVisit = model.NameVisit
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Визит с таким названием уже есть");
}
}
}
}

View File

@ -7,8 +7,15 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.1.30" />
<PackageReference Include="NPOI" Version="2.7.0" />
</ItemGroup>
<ItemGroup>

View File

@ -15,7 +15,7 @@ namespace VetClinicBaseImplement.Implements
using var context = new VetClinicDatabase();
return context.Animals
.Include(x => x.Vaccination)
.Include(x => x.Vaccinations)
.Include(x => x.Admin)
.Include(x => x.Visits)
.ThenInclude(x => x.Visit)
@ -32,7 +32,7 @@ namespace VetClinicBaseImplement.Implements
using var context = new VetClinicDatabase();
return context.Animals
.Include(x => x.Admin)
.Include(x => x.Vaccination)
.Include(x => x.Vaccinations)
.Include(x => x.Visits)
.ThenInclude(x => x.Visit)
.Where(x => x.AnimalName.Contains(model.AnimalName))
@ -48,10 +48,10 @@ namespace VetClinicBaseImplement.Implements
using var context = new VetClinicDatabase();
return context.Animals
.Include(x => x.Admin)
.Include(x => x.Vaccination)
.Include(x => x.Vaccinations)
.Include(x => x.Visits)
.ThenInclude(x => x.Visit)
.Include(x => x.Vaccination)
.Include(x => x.Vaccinations)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.AnimalName) && x.AnimalName == model.AnimalName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public AnimalViewModel? Insert(AnimalBindingModel model)

View File

@ -28,7 +28,7 @@ namespace VetClinicDataBaseImplement.Implements
using var context = new VetClinicDatabase();
return context.Medicines.Include(x => x.Pharmacist).Include(x => x.Animals)
.ThenInclude(x => x.Animal)
.Where(x => (string.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName)
.Where(x => (string.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName)
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId)))
.ToList()
.Select(x => x.GetViewModel)

View File

@ -6,12 +6,13 @@ using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.BindingModels;
using VetClinicContracts.SearchModels;
using VetClinicContracts.StoragesContracts;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicDataBaseImplement.Implements
{
public class VaccinationStorage
public class VaccinationStorage : IVaccinationStorage
{
public List<VaccinationViewModel> GetFullList()
{

View File

@ -6,12 +6,13 @@ using System.Text;
using System.Threading.Tasks;
using VetClinicContracts.BindingModels;
using VetClinicContracts.SearchModels;
using VetClinicContracts.StoragesContracts;
using VetClinicContracts.ViewModels;
using VetClinicDataBaseImplement.Models;
namespace VetClinicDataBaseImplement.Implements
{
public class VisitStorage
public class VisitStorage : IVisitStorage
{
public List<VisitViewModel> GetFullList()
{

View File

@ -0,0 +1,521 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using VetClinicDataBaseImplement;
#nullable disable
namespace VetClinicDataBaseImplement.Migrations
{
[DbContext(typeof(VetClinicDatabase))]
[Migration("20240424171203_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Admin", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AdminFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Admins");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Animal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AdminId")
.HasColumnType("int");
b.Property<string>("AnimalName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Family")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("VaccinationId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AdminId");
b.ToTable("Animals");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Guidance", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ServiceId");
b.ToTable("Guidances");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Medicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("MedicineName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("PharmacistId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("PharmacistId");
b.ToTable("Medicines");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.MedicineAnimal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AnimalId")
.HasColumnType("int");
b.Property<int>("MedicineId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AnimalId");
b.HasIndex("MedicineId");
b.ToTable("MedicineAnimals");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Pharmacist", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PharmacistFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Pharmacists");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PharmacistId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("PharmacistId");
b.ToTable("Services");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.ServiceMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("ServiceId");
b.ToTable("ServiceMedicines");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Vaccination", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AnimalId")
.HasColumnType("int");
b.Property<double>("CostVaccination")
.HasColumnType("float");
b.Property<DateTime?>("DateStamp")
.IsRequired()
.HasColumnType("datetime2");
b.Property<string>("NameVaccination")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("AnimalId");
b.ToTable("Vaccinations");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Visit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AdminId")
.HasColumnType("int");
b.Property<DateTime>("DateVisit")
.HasColumnType("datetime2");
b.Property<string>("NameVisit")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("AdminId");
b.ToTable("Visits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.VisitAnimal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AnimalId")
.HasColumnType("int");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AnimalId");
b.HasIndex("VisitId");
b.ToTable("VisitAnimals");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.VisitService", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ServiceId");
b.HasIndex("VisitId");
b.ToTable("ServiceVisits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Animal", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Admin", "Admin")
.WithMany("Animals")
.HasForeignKey("AdminId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Admin");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Guidance", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Service", "Service")
.WithMany("Guidances")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Service");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Medicine", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Pharmacist", "Pharmacist")
.WithMany("Medicines")
.HasForeignKey("PharmacistId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Pharmacist");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.MedicineAnimal", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Animal", "Animal")
.WithMany("Medicines")
.HasForeignKey("AnimalId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetClinicDataBaseImplement.Models.Medicine", "Medicine")
.WithMany("Animals")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Animal");
b.Navigation("Medicine");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Service", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Pharmacist", "Pharmacist")
.WithMany("Services")
.HasForeignKey("PharmacistId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Pharmacist");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.ServiceMedicine", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Medicine", "Medicine")
.WithMany("Services")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetClinicDataBaseImplement.Models.Service", "Service")
.WithMany("Medicines")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Medicine");
b.Navigation("Service");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Vaccination", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Animal", "Animal")
.WithMany("Vaccinations")
.HasForeignKey("AnimalId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Animal");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Visit", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Admin", "Admin")
.WithMany("Visits")
.HasForeignKey("AdminId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Admin");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.VisitAnimal", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Animal", "Animal")
.WithMany("Visits")
.HasForeignKey("AnimalId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetClinicDataBaseImplement.Models.Visit", "Visit")
.WithMany("Animals")
.HasForeignKey("VisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Animal");
b.Navigation("Visit");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.VisitService", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Service", "Service")
.WithMany("Visits")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetClinicDataBaseImplement.Models.Visit", "Visit")
.WithMany("Services")
.HasForeignKey("VisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Service");
b.Navigation("Visit");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Admin", b =>
{
b.Navigation("Animals");
b.Navigation("Visits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Animal", b =>
{
b.Navigation("Medicines");
b.Navigation("Vaccinations");
b.Navigation("Visits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Medicine", b =>
{
b.Navigation("Animals");
b.Navigation("Services");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Pharmacist", b =>
{
b.Navigation("Medicines");
b.Navigation("Services");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Service", b =>
{
b.Navigation("Guidances");
b.Navigation("Medicines");
b.Navigation("Visits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Visit", b =>
{
b.Navigation("Animals");
b.Navigation("Services");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,388 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace VetClinicDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Admins",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AdminFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Admins", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Pharmacists",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PharmacistFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Pharmacists", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Animals",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AdminId = table.Column<int>(type: "int", nullable: false),
VaccinationId = table.Column<int>(type: "int", nullable: false),
AnimalName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Family = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Animals", x => x.Id);
table.ForeignKey(
name: "FK_Animals_Admins_AdminId",
column: x => x.AdminId,
principalTable: "Admins",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Visits",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AdminId = table.Column<int>(type: "int", nullable: false),
NameVisit = table.Column<string>(type: "nvarchar(max)", nullable: false),
DateVisit = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Visits", x => x.Id);
table.ForeignKey(
name: "FK_Visits_Admins_AdminId",
column: x => x.AdminId,
principalTable: "Admins",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Medicines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
MedicineName = table.Column<string>(type: "nvarchar(max)", nullable: false),
PharmacistId = table.Column<int>(type: "int", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Medicines", x => x.Id);
table.ForeignKey(
name: "FK_Medicines_Pharmacists_PharmacistId",
column: x => x.PharmacistId,
principalTable: "Pharmacists",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Services",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ServiceName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
PharmacistId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Services", x => x.Id);
table.ForeignKey(
name: "FK_Services_Pharmacists_PharmacistId",
column: x => x.PharmacistId,
principalTable: "Pharmacists",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Vaccinations",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AnimalId = table.Column<int>(type: "int", nullable: false),
NameVaccination = table.Column<string>(type: "nvarchar(max)", nullable: false),
CostVaccination = table.Column<double>(type: "float", nullable: false),
DateStamp = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Vaccinations", x => x.Id);
table.ForeignKey(
name: "FK_Vaccinations_Animals_AnimalId",
column: x => x.AnimalId,
principalTable: "Animals",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "VisitAnimals",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AnimalId = table.Column<int>(type: "int", nullable: false),
VisitId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_VisitAnimals", x => x.Id);
table.ForeignKey(
name: "FK_VisitAnimals_Animals_AnimalId",
column: x => x.AnimalId,
principalTable: "Animals",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_VisitAnimals_Visits_VisitId",
column: x => x.VisitId,
principalTable: "Visits",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "MedicineAnimals",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
MedicineId = table.Column<int>(type: "int", nullable: false),
AnimalId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_MedicineAnimals", x => x.Id);
table.ForeignKey(
name: "FK_MedicineAnimals_Animals_AnimalId",
column: x => x.AnimalId,
principalTable: "Animals",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_MedicineAnimals_Medicines_MedicineId",
column: x => x.MedicineId,
principalTable: "Medicines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Guidances",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ServiceId = table.Column<int>(type: "int", nullable: false),
Text = table.Column<string>(type: "nvarchar(max)", nullable: false),
Date = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Guidances", x => x.Id);
table.ForeignKey(
name: "FK_Guidances_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ServiceMedicines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ServiceId = table.Column<int>(type: "int", nullable: false),
MedicineId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ServiceMedicines", x => x.Id);
table.ForeignKey(
name: "FK_ServiceMedicines_Medicines_MedicineId",
column: x => x.MedicineId,
principalTable: "Medicines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ServiceMedicines_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "ServiceVisits",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ServiceId = table.Column<int>(type: "int", nullable: false),
VisitId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ServiceVisits", x => x.Id);
table.ForeignKey(
name: "FK_ServiceVisits_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ServiceVisits_Visits_VisitId",
column: x => x.VisitId,
principalTable: "Visits",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Animals_AdminId",
table: "Animals",
column: "AdminId");
migrationBuilder.CreateIndex(
name: "IX_Guidances_ServiceId",
table: "Guidances",
column: "ServiceId");
migrationBuilder.CreateIndex(
name: "IX_MedicineAnimals_AnimalId",
table: "MedicineAnimals",
column: "AnimalId");
migrationBuilder.CreateIndex(
name: "IX_MedicineAnimals_MedicineId",
table: "MedicineAnimals",
column: "MedicineId");
migrationBuilder.CreateIndex(
name: "IX_Medicines_PharmacistId",
table: "Medicines",
column: "PharmacistId");
migrationBuilder.CreateIndex(
name: "IX_ServiceMedicines_MedicineId",
table: "ServiceMedicines",
column: "MedicineId");
migrationBuilder.CreateIndex(
name: "IX_ServiceMedicines_ServiceId",
table: "ServiceMedicines",
column: "ServiceId");
migrationBuilder.CreateIndex(
name: "IX_Services_PharmacistId",
table: "Services",
column: "PharmacistId");
migrationBuilder.CreateIndex(
name: "IX_ServiceVisits_ServiceId",
table: "ServiceVisits",
column: "ServiceId");
migrationBuilder.CreateIndex(
name: "IX_ServiceVisits_VisitId",
table: "ServiceVisits",
column: "VisitId");
migrationBuilder.CreateIndex(
name: "IX_Vaccinations_AnimalId",
table: "Vaccinations",
column: "AnimalId");
migrationBuilder.CreateIndex(
name: "IX_VisitAnimals_AnimalId",
table: "VisitAnimals",
column: "AnimalId");
migrationBuilder.CreateIndex(
name: "IX_VisitAnimals_VisitId",
table: "VisitAnimals",
column: "VisitId");
migrationBuilder.CreateIndex(
name: "IX_Visits_AdminId",
table: "Visits",
column: "AdminId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Guidances");
migrationBuilder.DropTable(
name: "MedicineAnimals");
migrationBuilder.DropTable(
name: "ServiceMedicines");
migrationBuilder.DropTable(
name: "ServiceVisits");
migrationBuilder.DropTable(
name: "Vaccinations");
migrationBuilder.DropTable(
name: "VisitAnimals");
migrationBuilder.DropTable(
name: "Medicines");
migrationBuilder.DropTable(
name: "Services");
migrationBuilder.DropTable(
name: "Animals");
migrationBuilder.DropTable(
name: "Visits");
migrationBuilder.DropTable(
name: "Pharmacists");
migrationBuilder.DropTable(
name: "Admins");
}
}
}

View File

@ -0,0 +1,518 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using VetClinicDataBaseImplement;
#nullable disable
namespace VetClinicDataBaseImplement.Migrations
{
[DbContext(typeof(VetClinicDatabase))]
partial class VetClinicDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Admin", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AdminFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Admins");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Animal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AdminId")
.HasColumnType("int");
b.Property<string>("AnimalName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Family")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("VaccinationId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AdminId");
b.ToTable("Animals");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Guidance", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("ServiceId");
b.ToTable("Guidances");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Medicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("MedicineName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("PharmacistId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.HasIndex("PharmacistId");
b.ToTable("Medicines");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.MedicineAnimal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AnimalId")
.HasColumnType("int");
b.Property<int>("MedicineId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AnimalId");
b.HasIndex("MedicineId");
b.ToTable("MedicineAnimals");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Pharmacist", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PharmacistFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Pharmacists");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PharmacistId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("PharmacistId");
b.ToTable("Services");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.ServiceMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("ServiceId");
b.ToTable("ServiceMedicines");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Vaccination", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AnimalId")
.HasColumnType("int");
b.Property<double>("CostVaccination")
.HasColumnType("float");
b.Property<DateTime?>("DateStamp")
.IsRequired()
.HasColumnType("datetime2");
b.Property<string>("NameVaccination")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("AnimalId");
b.ToTable("Vaccinations");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Visit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AdminId")
.HasColumnType("int");
b.Property<DateTime>("DateVisit")
.HasColumnType("datetime2");
b.Property<string>("NameVisit")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("AdminId");
b.ToTable("Visits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.VisitAnimal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("AnimalId")
.HasColumnType("int");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AnimalId");
b.HasIndex("VisitId");
b.ToTable("VisitAnimals");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.VisitService", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<int>("VisitId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ServiceId");
b.HasIndex("VisitId");
b.ToTable("ServiceVisits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Animal", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Admin", "Admin")
.WithMany("Animals")
.HasForeignKey("AdminId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Admin");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Guidance", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Service", "Service")
.WithMany("Guidances")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Service");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Medicine", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Pharmacist", "Pharmacist")
.WithMany("Medicines")
.HasForeignKey("PharmacistId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Pharmacist");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.MedicineAnimal", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Animal", "Animal")
.WithMany("Medicines")
.HasForeignKey("AnimalId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetClinicDataBaseImplement.Models.Medicine", "Medicine")
.WithMany("Animals")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Animal");
b.Navigation("Medicine");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Service", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Pharmacist", "Pharmacist")
.WithMany("Services")
.HasForeignKey("PharmacistId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Pharmacist");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.ServiceMedicine", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Medicine", "Medicine")
.WithMany("Services")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetClinicDataBaseImplement.Models.Service", "Service")
.WithMany("Medicines")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Medicine");
b.Navigation("Service");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Vaccination", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Animal", "Animal")
.WithMany("Vaccinations")
.HasForeignKey("AnimalId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Animal");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Visit", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Admin", "Admin")
.WithMany("Visits")
.HasForeignKey("AdminId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Admin");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.VisitAnimal", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Animal", "Animal")
.WithMany("Visits")
.HasForeignKey("AnimalId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetClinicDataBaseImplement.Models.Visit", "Visit")
.WithMany("Animals")
.HasForeignKey("VisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Animal");
b.Navigation("Visit");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.VisitService", b =>
{
b.HasOne("VetClinicDataBaseImplement.Models.Service", "Service")
.WithMany("Visits")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("VetClinicDataBaseImplement.Models.Visit", "Visit")
.WithMany("Services")
.HasForeignKey("VisitId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Service");
b.Navigation("Visit");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Admin", b =>
{
b.Navigation("Animals");
b.Navigation("Visits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Animal", b =>
{
b.Navigation("Medicines");
b.Navigation("Vaccinations");
b.Navigation("Visits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Medicine", b =>
{
b.Navigation("Animals");
b.Navigation("Services");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Pharmacist", b =>
{
b.Navigation("Medicines");
b.Navigation("Services");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Service", b =>
{
b.Navigation("Guidances");
b.Navigation("Medicines");
b.Navigation("Visits");
});
modelBuilder.Entity("VetClinicDataBaseImplement.Models.Visit", b =>
{
b.Navigation("Animals");
b.Navigation("Services");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -24,8 +24,8 @@ namespace VetClinicDataBaseImplement.Models
[Required]
public string Password { get; set; } = string.Empty;
// [ForeignKey("AdminId")]
//public virtual List<Visit> Visits { get; set; } = new();
[ForeignKey("AdminId")]
public virtual List<Visit> Visits { get; set; } = new();
[ForeignKey("AdminId")]
public virtual List<Animal> Animals { get; set; } = new();
public static Admin? Create(AdminBindingModel model)
@ -36,7 +36,7 @@ namespace VetClinicDataBaseImplement.Models
}
return new Admin()
{
Id = model.AdminId,
Id = model.Id,
AdminFIO = model.AdminFIO,
Email = model.Email,
Password = model.Password

View File

@ -36,7 +36,6 @@ namespace VetClinicDataBaseImplement.Models
public virtual List<Vaccination> Vaccinations { get; set; } = new();
public virtual Admin Admin { get; set; }
public virtual Vaccination Vaccination { get; set; }
[ForeignKey("AnimalId")]
public virtual List<VisitAnimal> Visits { get; set; } = new();
@ -57,6 +56,7 @@ namespace VetClinicDataBaseImplement.Models
return _visitAnimals;
}
}
[NotMapped]
public Dictionary<int, IMedicineModel> MedicineAnimals
{
get

View File

@ -35,7 +35,7 @@ namespace VetClinicDataBaseImplement.Models
public virtual List<VisitService> Services { get; set; } = new();
public virtual Admin Admin { get; set; }
[NotMapped]
public Dictionary<int, IAnimalModel> VisitAnimals
{
get
@ -48,6 +48,7 @@ namespace VetClinicDataBaseImplement.Models
return _visitAnimals;
}
}
[NotMapped]
public Dictionary<int, IServiceModel> ServiceVisits
{
get

View File

@ -11,7 +11,7 @@ namespace VetClinicDataBaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS02;Initial Catalog=DinerDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=VetClinicDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -0,0 +1,94 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;
namespace VetClinicRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class VisitController : Controller
{
private readonly ILogger _logger;
private readonly IVisitLogic _visit;
public VisitController(ILogger<VisitController> logger, IVisitLogic visit)
{
_logger = logger;
_visit = visit;
}
[HttpGet]
public Tuple<VisitViewModel, List<string>>? GetVisit(int VisitId)
{
try
{
var elem = _visit.ReadElement(new VisitSearchModel { Id = VisitId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.AnimalName).ToList());
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения визита по id={Id}", VisitId);
throw;
}
}
[HttpGet]
public List<VisitViewModel> GetVisits(int adminId)
{
try
{
return _visit.ReadList(new VisitSearchModel { AdminId = adminId});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка визитовв");
throw;
}
}
[HttpPost]
public bool CreateVisit(VisitBindingModel model)
{
try
{
return _visit.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать визит");
throw;
}
}
[HttpPost]
public bool UpdateVisit(VisitBindingModel model)
{
try
{
model.VisitAnimals = null!;
return _visit.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить визит");
throw;
}
}
[HttpPost]
public bool DeleteVisit(VisitBindingModel model)
{
try
{
return _visit.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления визита");
throw;
}
}
}
}

View File

@ -7,16 +7,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DinerDataBaseImplement\VetClinicDataBaseImplement.csproj" />
<ProjectReference Include="..\VetClinicBusinessLogic\VetClinicBusinessLogic.csproj" />
<ProjectReference Include="..\VetClinicContracts\VetClinicContracts.csproj" />
<ProjectReference Include="..\VetClinicDataBaseImplement\VetClinicDataBaseImplement.csproj" />