короче я не знаю не быть мне программистом
This commit is contained in:
parent
0b9c6378ca
commit
1684e57bcc
@ -172,30 +172,40 @@ namespace ClientApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(new List<DoctorVisitViewModel>());
|
||||
return View(APIClient.GetRequest<List<DoctorVisitViewModel>>($"api/doctorvisit/getvisits?clientid={APIClient.Client.Id}"));
|
||||
}
|
||||
public IActionResult CreateDoctorVisit()
|
||||
{
|
||||
var services = new List<ServiceViewModel>();
|
||||
services.Add(new ServiceViewModel
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
Id = 1,
|
||||
ServiceName = "ServiceName example",
|
||||
Price = 228,
|
||||
DcotorFIO = "name example",
|
||||
DoctorId = 1,
|
||||
ServiceMedicines = new Dictionary<int, IMedicineModel>()
|
||||
});
|
||||
services.Add(new ServiceViewModel
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
ViewBag.Animals = APIClient.GetRequest<List<AnimalViewModel>>($"api/animal/getanimals?clientid={APIClient.Client.Id}");
|
||||
ViewBag.Services = APIClient.GetRequest<List<ServiceViewModel>>($"api/service/getservices?doctorid={null}");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateDoctorVisit(string name, int service, List<int> pets, DateTime dateTime)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
Id = 2,
|
||||
ServiceName = "ServiceName example 2",
|
||||
Price = 2282,
|
||||
DcotorFIO = "name example 2",
|
||||
DoctorId = 2,
|
||||
ServiceMedicines = new Dictionary<int, IMedicineModel>()
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
Dictionary<int, IAnimalModel> a = new Dictionary<int, IAnimalModel>();
|
||||
foreach (int pet in pets)
|
||||
{
|
||||
a.Add(pet, new AnimalSearchModel { Id = pet } as IAnimalModel);
|
||||
}
|
||||
APIClient.PostRequest("api/doctorvisit/createvisit", new DoctorVisitBindingModel
|
||||
{
|
||||
ClientId = APIClient.Client.Id,
|
||||
ServiceId = service,
|
||||
VisitAnimals = a,
|
||||
Cost = double.Parse(1000.ToString()) , //TODO: просто цену услуги передать
|
||||
DateVisit= dateTime,
|
||||
VisitName = name
|
||||
});
|
||||
return View(services);
|
||||
Response.Redirect("IndexDoctorVisit");
|
||||
}
|
||||
//=================ПОКУПКИ=================
|
||||
public IActionResult IndexDrugPurchase()
|
||||
|
@ -1,39 +1,76 @@
|
||||
@{
|
||||
@{
|
||||
ViewData["Title"] = "CreateDoctorVisit";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание пещения</h2>
|
||||
<h2 class="display-4">Создание покупки</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="container">
|
||||
<div>services</div>
|
||||
<div class="table-responsive-lg">
|
||||
<table id="servicesTable" class="display">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Выбор</th>
|
||||
<th>Название</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var service in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox" name="services" value="@service.Id" />
|
||||
</td>
|
||||
<td>@service.ServiceName</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Название:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Услуга:</div>
|
||||
<div class="col-8">
|
||||
<select id="service" name="service" class="form-control" asp-items="@(new SelectList(@ViewBag.Services,"Id", "ServiceName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Животные:</div>
|
||||
<div class="col-8">
|
||||
<select name="pets" class="form-control" multiple size="6" id="animals">
|
||||
@foreach (var animal in ViewBag.Animals)
|
||||
{
|
||||
<option value="@animal.Id">@animal.AnimalName</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Дата:</div>
|
||||
<div class="col-8"><input type="text" name="title" id="title" /></div>
|
||||
<div class="col-8">
|
||||
<input type="datetime-local" id="datetime" name="datetime" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Сумма:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" id="cost" name="cost" readonly />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Создать" class="btn btn-primary" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</form>
|
||||
@section Scripts
|
||||
{
|
||||
<script>
|
||||
$('#drug').on('change', function () {
|
||||
check();
|
||||
});
|
||||
$('#count').on('change', function () {
|
||||
check();
|
||||
});
|
||||
|
||||
function check() {
|
||||
var count = $('#count').val();
|
||||
var service = $('#service').val();
|
||||
if (count && service) {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "/Home/Calc",
|
||||
data: { count: count, service: service },
|
||||
success: function (result) {
|
||||
$("#sum").val(result);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
||||
}
|
@ -28,10 +28,13 @@
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Статус
|
||||
Услуга
|
||||
</th>
|
||||
<th>
|
||||
Дата
|
||||
Сумма
|
||||
</th>
|
||||
<th>
|
||||
Дата услуги
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -43,14 +46,14 @@
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Status)
|
||||
@Html.DisplayFor(modelItem => item.ServiceName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Cost)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DateVisit)
|
||||
</td>
|
||||
<td>
|
||||
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Удалить</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
|
@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VetclinicDataModels.Enums
|
||||
{
|
||||
public enum DoctorVisitStatus
|
||||
{
|
||||
Неизвестен = -1,
|
||||
Забронировано = 0,
|
||||
Выполняется = 1,
|
||||
Закончен = 2,
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetclinicDataModels.Enums;
|
||||
|
||||
namespace VetclinicDataModels.Models
|
||||
{
|
||||
@ -11,7 +10,9 @@ namespace VetclinicDataModels.Models
|
||||
{
|
||||
int ClientId { get; }
|
||||
int ServiceId { get; }
|
||||
DoctorVisitStatus Status { get; }
|
||||
string VisitName { get; }
|
||||
double Cost { get; }
|
||||
DateTime DateVisit { get; }
|
||||
Dictionary<int, IAnimalModel> VisitAnimals { get; }
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetclinicDataModels.Enums;
|
||||
|
||||
namespace VetclinicDataModels.Models
|
||||
{
|
||||
|
@ -9,7 +9,6 @@ using VetclinicContracts.BusinessLogicsContracts;
|
||||
using VetclinicContracts.SearchModels;
|
||||
using VetclinicContracts.StoragesContracts;
|
||||
using VetclinicContracts.ViewModels;
|
||||
using VetclinicDataModels.Enums;
|
||||
|
||||
namespace VetclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
@ -54,15 +53,9 @@ namespace VetclinicBusinessLogic.BusinessLogics
|
||||
|
||||
return element;
|
||||
}
|
||||
public bool CreateDoctorVisit(DoctorVisitBindingModel model)
|
||||
public bool Create(DoctorVisitBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (model.Status != DoctorVisitStatus.Неизвестен)
|
||||
{
|
||||
_logger.LogWarning("Wrong DoctorVisit status. Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
model.Status = DoctorVisitStatus.Забронировано;
|
||||
if (_doctorVisitStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
@ -70,44 +63,26 @@ namespace VetclinicBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool ChangeStatus(DoctorVisitBindingModel model, DoctorVisitStatus status)
|
||||
public bool Update(DoctorVisitBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
var element = _doctorVisitStorage.GetElement(new DoctorVisitSearchModel { 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("Текущий статус заказа не может быть переведен в выбранный");
|
||||
}
|
||||
DoctorVisitStatus oldStatus = model.Status;
|
||||
model.Status = status;
|
||||
/* РАЗ УЖ НЕТ ДАТЫ ОКОНЧАНИЯ ТО ЭТО НЕ НАДО?
|
||||
if (model.Status == DoctorVisitStatus.Закончен)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
*/
|
||||
CheckModel(model);
|
||||
if (_doctorVisitStorage.Update(model) == null)
|
||||
{
|
||||
model.Status = oldStatus;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool BeginDoctorVisit(DoctorVisitBindingModel model)
|
||||
public bool Delete(DoctorVisitBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, DoctorVisitStatus.Выполняется);
|
||||
}
|
||||
public bool FinishDoctorVisit(DoctorVisitBindingModel model)
|
||||
{
|
||||
return ChangeStatus(model, DoctorVisitStatus.Закончен);
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_doctorVisitStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(DoctorVisitBindingModel model, bool withParams = true)
|
||||
{
|
||||
@ -119,12 +94,12 @@ namespace VetclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.DateVisit != null)
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArithmeticException("Дата завершения не может быть раньше даты начала");
|
||||
throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("DoctorVisit. Id:{Id}. DateVisit:{DateVisit}. ServiceId:{ServiceId}. AnimalId:{AnimalId}",
|
||||
model.Id, model.DateVisit, model.ServiceId, model.AnimalId);
|
||||
_logger.LogInformation("DoctorVisit. Id:{Id}. DateVisit:{DateVisit}. ServiceId:{ServiceId}. ClientId:{ClientId}",
|
||||
model.Id, model.DateVisit, model.ServiceId, model.ClientId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ using VetclinicContracts.BusinessLogicsContracts;
|
||||
using VetclinicContracts.SearchModels;
|
||||
using VetclinicContracts.StoragesContracts;
|
||||
using VetclinicContracts.ViewModels;
|
||||
using VetclinicDataModels.Enums;
|
||||
|
||||
namespace VetclinicBusinessLogic.BusinessLogics
|
||||
{
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetclinicDataModels.Enums;
|
||||
using VetclinicDataModels.Models;
|
||||
|
||||
namespace VetclinicContracts.BindingModels
|
||||
@ -13,8 +12,9 @@ namespace VetclinicContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int ServiceId { get; set; }
|
||||
public int AnimalId { get; set; }
|
||||
public DoctorVisitStatus Status { get; set; }
|
||||
public double Cost { get; set; }
|
||||
public string VisitName { get; set; } = string.Empty;
|
||||
public DateTime DateVisit { get; set; }
|
||||
public Dictionary<int, IAnimalModel> VisitAnimals { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetclinicDataModels.Enums;
|
||||
using VetclinicDataModels.Models;
|
||||
|
||||
namespace VetclinicContracts.BindingModels
|
||||
|
@ -13,8 +13,8 @@ namespace VetclinicContracts.BusinessLogicsContracts
|
||||
{
|
||||
List<DoctorVisitViewModel>? ReadList(DoctorVisitSearchModel? model);
|
||||
DoctorVisitViewModel? ReadElement(DoctorVisitSearchModel model);
|
||||
bool CreateDoctorVisit(DoctorVisitBindingModel model);
|
||||
bool BeginDoctorVisit(DoctorVisitBindingModel model);
|
||||
bool FinishDoctorVisit(DoctorVisitBindingModel model);
|
||||
bool Create(DoctorVisitBindingModel model);
|
||||
bool Update(DoctorVisitBindingModel model);
|
||||
bool Delete(DoctorVisitBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetclinicDataModels.Enums;
|
||||
|
||||
namespace VetclinicContracts.SearchModels
|
||||
{
|
||||
@ -11,7 +10,8 @@ namespace VetclinicContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public DoctorVisitStatus? Status { get; set; }
|
||||
public int? ServiceId { get; set; }
|
||||
public string? VisitName { get; set; }
|
||||
public DateTime? DateVisit { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetclinicDataModels.Enums;
|
||||
|
||||
namespace VetclinicContracts.SearchModels
|
||||
{
|
||||
|
@ -4,7 +4,6 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetclinicDataModels.Enums;
|
||||
using VetclinicDataModels.Models;
|
||||
|
||||
namespace VetclinicContracts.ViewModels
|
||||
@ -14,13 +13,16 @@ namespace VetclinicContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int ServiceId { get; set; }
|
||||
[DisplayName("Статус приема")]
|
||||
public DoctorVisitStatus Status { get; set; }
|
||||
[DisplayName("Название визита")]
|
||||
public string VisitName { get; set; } = string.Empty;
|
||||
[DisplayName("Дата приема")]
|
||||
public DateTime DateVisit { get; set; }
|
||||
[DisplayName("Название услуги")]
|
||||
public string ServiceName { get; set; } = string.Empty;
|
||||
[DisplayName("Имя клиента")]
|
||||
public string ClientName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена услуги")]
|
||||
public double Cost { get; set; }
|
||||
public Dictionary<int, IAnimalModel> VisitAnimals { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetclinicDataModels.Enums;
|
||||
using VetclinicDataModels.Models;
|
||||
|
||||
namespace VetclinicContracts.ViewModels
|
||||
|
@ -20,13 +20,18 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new VetclinicDatabase();
|
||||
return context.DoctorVisits.Include(x => x.Client).
|
||||
Include(x => x.Service).
|
||||
Include(x => x.Animals).
|
||||
ThenInclude(x => x.Animal).
|
||||
FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
var doctorVisit = context.DoctorVisits
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Service)
|
||||
.Include(x => x.Animals)
|
||||
.ThenInclude(x => x.Animal)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
return doctorVisit?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<DoctorVisitViewModel> GetFilteredList(DoctorVisitSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
@ -41,24 +46,31 @@ namespace VetclinicDatabaseImplement.Implements
|
||||
public List<DoctorVisitViewModel> GetFullList()
|
||||
{
|
||||
using var context = new VetclinicDatabase();
|
||||
return context.DoctorVisits.Include(x => x.Client).Include(x => x.Service).Include(x => x.Animals).ThenInclude(x => x.Animal).ToList().Select(x => x.GetViewModel).ToList();
|
||||
return context.DoctorVisits
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Service)
|
||||
.Include(x => x.Animals)
|
||||
.ThenInclude(x => x.Animal)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public DoctorVisitViewModel? Insert(DoctorVisitBindingModel model)
|
||||
{
|
||||
var newDoctorVisit = DoctorVisit.Create(model);
|
||||
using var context = new VetclinicDatabase();
|
||||
var newDoctorVisit = DoctorVisit.Create(context, model);
|
||||
if (newDoctorVisit == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new VetclinicDatabase();
|
||||
context.DoctorVisits.Add(newDoctorVisit);
|
||||
context.SaveChanges();
|
||||
return context.DoctorVisits.Include(x => x.Client).Include(x => x.Service).Include(x => x.Animals).ThenInclude(x => x.Animal).FirstOrDefault(x => x.Id == newDoctorVisit.Id)?.GetViewModel;
|
||||
return newDoctorVisit.GetViewModel;
|
||||
}
|
||||
public DoctorVisitViewModel? Update(DoctorVisitBindingModel model)
|
||||
{
|
||||
using var context = new VetclinicDatabase();
|
||||
var DoctorVisit = context.DoctorVisits.FirstOrDefault(x => x.Id == model.Id);
|
||||
var DoctorVisit = context.DoctorVisits.Include(x => x.Animals).ThenInclude(x => x.Animal).Include(x => x.Client)
|
||||
.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (DoctorVisit == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -12,8 +12,8 @@ using VetclinicDatabaseImplement;
|
||||
namespace VetclinicDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(VetclinicDatabase))]
|
||||
[Migration("20240528194255_hope2")]
|
||||
partial class hope2
|
||||
[Migration("20240529004732_hope3")]
|
||||
partial class hope3
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -161,14 +161,18 @@ namespace VetclinicDatabaseImplement.Migrations
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<DateTime>("DateVisit")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("ServiceId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
b.Property<string>("VisitName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
namespace VetclinicDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class hope2 : Migration
|
||||
public partial class hope3 : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
@ -187,7 +187,8 @@ namespace VetclinicDatabaseImplement.Migrations
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
VisitName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false),
|
||||
DateVisit = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: false),
|
||||
ServiceId = table.Column<int>(type: "int", nullable: false)
|
@ -158,14 +158,18 @@ namespace VetclinicDatabaseImplement.Migrations
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<DateTime>("DateVisit")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("ServiceId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
b.Property<string>("VisitName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
|
@ -1,65 +1,80 @@
|
||||
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 System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics;
|
||||
using VetclinicContracts.BindingModels;
|
||||
using VetclinicContracts.ViewModels;
|
||||
using VetclinicDataModels.Models;
|
||||
using VetclinicDataModels.Enums;
|
||||
|
||||
namespace VetclinicDatabaseImplement.Models
|
||||
{
|
||||
public class DoctorVisit: IDoctorVisitModel
|
||||
public class DoctorVisit : IDoctorVisitModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public DoctorVisitStatus Status { get; private set; }
|
||||
public string VisitName { get; private set; }
|
||||
[Required]
|
||||
public double Cost { get; private set; }
|
||||
[Required]
|
||||
public DateTime DateVisit { get; private set; }
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
[Required]
|
||||
public int ServiceId { get; set; }
|
||||
public virtual Service Service { get; set; }
|
||||
public virtual Client? Client { get; private set; }
|
||||
|
||||
private Dictionary<int, IAnimalModel>? _visitAnimals = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IAnimalModel> VisitAnimals
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_visitAnimals == null)
|
||||
{
|
||||
_visitAnimals = Animals
|
||||
.ToDictionary(recPC => recPC.AnimalId, recPC =>
|
||||
(recPC.Animal as IAnimalModel));
|
||||
}
|
||||
return _visitAnimals;
|
||||
}
|
||||
}
|
||||
[ForeignKey("DoctorVisitId")]
|
||||
public virtual List<AnimalDoctorVisit> Animals { get; set; } = new();
|
||||
public virtual Client Client { get; set; }
|
||||
public virtual Service Service { get; set; }
|
||||
public static DoctorVisit? Create(DoctorVisitBindingModel model)
|
||||
public static DoctorVisit? Create(VetclinicDatabase context, DoctorVisitBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new DoctorVisit()
|
||||
{
|
||||
Id = model.Id,
|
||||
Status = model.Status,
|
||||
DateVisit = model.DateVisit,
|
||||
ClientId = model.ClientId,
|
||||
ServiceId = model.ServiceId,
|
||||
};
|
||||
}
|
||||
VisitName = model.VisitName,
|
||||
DateVisit = model.DateVisit,
|
||||
Cost = model.Cost,
|
||||
|
||||
public void Update(DoctorVisitBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
Animals = model.VisitAnimals.Select(x => new AnimalDoctorVisit
|
||||
{
|
||||
Animal = context.Animals.First(y => y.Id == x.Key),
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public DoctorVisitViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
DateVisit = DateVisit,
|
||||
ClientId = ClientId,
|
||||
ServiceId = ServiceId,
|
||||
ClientName = Client.ClientName,
|
||||
ServiceName = Service.ServiceName,
|
||||
VisitName = VisitName,
|
||||
DateVisit = DateVisit,
|
||||
Cost = Cost,
|
||||
ClientId = ClientId,
|
||||
ServiceName = Service?.ServiceName ?? string.Empty,
|
||||
VisitAnimals = VisitAnimals
|
||||
};
|
||||
|
||||
public void Update(DoctorVisitBindingModel model)
|
||||
{
|
||||
VisitName = model.VisitName;
|
||||
DateVisit = model.DateVisit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VetclinicContracts.BindingModels;
|
||||
using VetclinicContracts.ViewModels;
|
||||
using VetclinicDataModels.Enums;
|
||||
using VetclinicDataModels.Models;
|
||||
|
||||
namespace VetclinicDatabaseImplement.Models
|
||||
@ -26,7 +25,6 @@ namespace VetclinicDatabaseImplement.Models
|
||||
public int ClientId { get; set; }
|
||||
[Required]
|
||||
public int DrugId { get; set; }
|
||||
//public virtual List<AnimalDrugPurchase> AnimalDrugPurchase { get; set; } = new();
|
||||
public virtual Drug Drug { get; set; }
|
||||
public virtual Client? Client { get; private set; }
|
||||
|
||||
|
@ -4,7 +4,6 @@ using VetclinicContracts.BusinessLogicsContracts;
|
||||
using VetclinicContracts.SearchModels;
|
||||
using VetclinicContracts.ViewModels;
|
||||
using VetclinicDatabaseImplement.Models;
|
||||
using VetclinicDataModels.Enums;
|
||||
|
||||
namespace VetclinicRestApi.Controllers
|
||||
{
|
||||
@ -20,7 +19,7 @@ namespace VetclinicRestApi.Controllers
|
||||
_doctorVisit = doctorVisit;
|
||||
}
|
||||
[HttpGet]
|
||||
public Tuple<DoctorVisitViewModel>? GetVisit(int visitId)
|
||||
public Tuple<DoctorVisitViewModel, List<string>>? GetVisit(int visitId)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -29,7 +28,7 @@ namespace VetclinicRestApi.Controllers
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var res = Tuple.Create(elem);
|
||||
var res = Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.AnimalName).ToList());
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -71,7 +70,7 @@ namespace VetclinicRestApi.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
return _doctorVisit.CreateDoctorVisit(model);
|
||||
return _doctorVisit.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -85,15 +84,7 @@ namespace VetclinicRestApi.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
if (model.Status == DoctorVisitStatus.Забронировано)
|
||||
{
|
||||
return _doctorVisit.BeginDoctorVisit(model);
|
||||
}
|
||||
if (model.Status == DoctorVisitStatus.Выполняется)
|
||||
{
|
||||
return _doctorVisit.FinishDoctorVisit(model);
|
||||
}
|
||||
throw new InvalidOperationException();
|
||||
return _doctorVisit.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -101,18 +92,18 @@ namespace VetclinicRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
//[HttpPost]
|
||||
//public bool DeleteVisit(DoctorVisitBindingModel model)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// return _doctorVisit.FinishDoctorVisit(model);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// _logger.LogError(ex, "Ошибка удаления лекарства");
|
||||
// throw;
|
||||
// }
|
||||
//}
|
||||
[HttpPost]
|
||||
public bool DeleteVisit(DoctorVisitBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _doctorVisit.Delete(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления лекарства");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user