Исполнитель: готовимся к понедельнику

This commit is contained in:
Yunusov_Niyaz 2024-05-25 19:33:02 +04:00
parent 39a06e6150
commit 6f310f50d7
19 changed files with 32 additions and 112 deletions

View File

@ -58,23 +58,6 @@ namespace VeterinaryBusinessLogic.BusinessLogic
}
return true;
}
public bool ChangeDateImplement(PurchaseBindingModel model)
{
CheckModel(model);
var element = _purchaseStorage.GetElement(new PurchaseSearchModel { Id = model.Id });
if (element == null)
{
_logger.LogWarning("Read operation failed");
return false;
}
if(element.DateCreate > DateTime.Now)
{
_logger.LogWarning("DateImplement change operation failed");
}
model.DateImplement = DateTime.Now;
_purchaseStorage.Update(model);
return true;
}
private void CheckModel(PurchaseBindingModel model, bool withParams = true)
{
if (model == null)
@ -89,10 +72,10 @@ namespace VeterinaryBusinessLogic.BusinessLogic
{
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
}
//if (model.DateCreate < DateTime.Now)
//{
// throw new ArgumentNullException("Дата покупки не должна быть в прошлом", nameof(model.DateCreate));
//}
if (model.DateCreate < DateTime.Now)
{
throw new ArgumentNullException("Дата покупки не должна быть в прошлом", nameof(model.DateCreate));
}
if (model.Count <= 0)
{
throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count));

View File

@ -10,7 +10,6 @@ namespace VeterinaryContracts.BindingModels
public int Count { get; set; }
public double Sum { get; set; }
public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; }
public Dictionary<int, IPetModel> PurchasePet { get; set; } = new();
}
}

View File

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

View File

@ -6,7 +6,5 @@
public int? OwnerId { get; set; }
public int? DrugId { get; set; }
public DateTime? DateCreate { get; set; }
public DateTime? DateImplement { get; set;}
}
}

View File

@ -10,7 +10,5 @@ namespace VeterinaryContracts.StorageContracts
List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model);
PurchaseViewModel? GetElement(PurchaseSearchModel model);
PurchaseViewModel? Insert(PurchaseBindingModel model);
PurchaseViewModel? Update(PurchaseBindingModel model);
PurchaseViewModel? Delete(PurchaseBindingModel model);
}
}

View File

@ -16,8 +16,6 @@ namespace VeterinaryContracts.ViewModels
public double Sum { get; set; }
[DisplayName("Дата покупки")]
public DateTime DateCreate { get; set; }
[DisplayName("Дата завершения покупки")]
public DateTime? DateImplement { get; set; }
public Dictionary<int, IPetModel> PurchasePet { get; set; } = new();
}
}

View File

@ -7,7 +7,6 @@
int Count { get; }
double Sum { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
Dictionary<int, IPetModel> PurchasePet { get; }
}
}

View File

@ -100,14 +100,14 @@ namespace VeterinaryDatabaseImplement.Implements
public PetViewModel? Update(PetBindingModel model)
{
using var context = new VeterinaryDatabase();
var component = context.Pets.FirstOrDefault(x => x.Id ==model.Id);
if (component == null)
var pet = context.Pets.FirstOrDefault(x => x.Id ==model.Id);
if (pet == null)
{
return null;
}
component.Update(model);
pet.Update(model);
context.SaveChanges();
return component.GetViewModel;
return pet.GetViewModel;
}
public PetViewModel? Delete(PetBindingModel model)
{

View File

@ -22,7 +22,6 @@ namespace VeterinaryDatabaseImplement.Implements
return context.Purchases.Include(x => x.Owner).Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Drug)
.Where(x => ((!model.Id.HasValue || x.Id == model.Id) &&
(!model.DateCreate.HasValue || x.DateCreate >= model.DateCreate) &&
(!model.DateImplement.HasValue || x.DateImplement >= model.DateImplement) &&
(!model.OwnerId.HasValue || x.OwnerId <= model.OwnerId) &&
(!model.DrugId.HasValue || x.DrugId == model.DrugId)))
.Select(x => x.GetViewModel)
@ -50,30 +49,5 @@ namespace VeterinaryDatabaseImplement.Implements
context.SaveChanges();
return newPurchase.GetViewModel;
}
public PurchaseViewModel? Update(PurchaseBindingModel model)
{
using var context = new VeterinaryDatabase();
var purchase = context.Purchases.Include(x => x.Pets).ThenInclude(x => x.Pet).Include(x => x.Owner).FirstOrDefault(x => x.Id == model.Id);
if (purchase == null)
{
return null;
}
purchase.Update(model);
context.SaveChanges();
return purchase.GetViewModel;
}
public PurchaseViewModel? Delete(PurchaseBindingModel model)
{
using var context = new VeterinaryDatabase();
var element = context.Purchases.Include(x => x.Owner).Include(x => x.Pets).Include(x => x.Drug).FirstOrDefault
(rec => rec.Id == model.Id);
if (element != null)
{
context.Purchases.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -202,10 +202,6 @@ namespace VeterinaryDatabaseImplement.Migrations
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.IsRequired()
.HasColumnType("datetime2");
b.Property<int>("DrugId")
.HasColumnType("int");

View File

@ -146,8 +146,7 @@ namespace VeterinaryDatabaseImplement.Migrations
DrugId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: false)
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{

View File

@ -199,10 +199,6 @@ namespace VeterinaryDatabaseImplement.Migrations
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.IsRequired()
.HasColumnType("datetime2");
b.Property<int>("DrugId")
.HasColumnType("int");

View File

@ -69,7 +69,7 @@ namespace VeterinaryDatabaseImplement.Models
OwnerId = model.OwnerId,
};
}
public void Update(PetBindingModel model)
public void Update(PetBindingModel? model)
{
if (model == null)
{

View File

@ -21,8 +21,6 @@ namespace VeterinaryDatabaseImplement.Models
public double Sum { get; private set; }
[Required]
public DateTime DateCreate { get; private set; }
[Required]
public DateTime? DateImplement { get; private set; }
private Dictionary<int, IPetModel>? _purchasePet = null;
[NotMapped]
public Dictionary<int, IPetModel> PurchasePet
@ -50,7 +48,6 @@ namespace VeterinaryDatabaseImplement.Models
OwnerId = model.OwnerId,
DrugId = model.DrugId,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement,
Pets = model.PurchasePet.Select(x => new PurchasePet
{
Pet = context.Pets.First(y => y.Id == x.Key),
@ -58,14 +55,6 @@ namespace VeterinaryDatabaseImplement.Models
}).ToList()
};
}
public void Update(PurchaseBindingModel? model)
{
if (model == null)
{
return;
}
DateImplement = model.DateImplement;
}
public PurchaseViewModel GetViewModel => new()
{
Id = Id,
@ -73,8 +62,7 @@ namespace VeterinaryDatabaseImplement.Models
Sum = Sum,
OwnerId = OwnerId,
DrugId = DrugId,
DateCreate = DateCreate,
DateImplement = DateImplement
DateCreate = DateCreate
};
}
}

View File

@ -32,15 +32,18 @@ namespace VeterinaryRestApi.Controllers
}
}
[HttpGet]
public PetViewModel? GetPet(int ownerId)
public Tuple<PetViewModel>? GetPet(int petId)
{
try
{
return _pet.ReadElement(new PetSearchModel { Id = ownerId });
var elem = _pet.ReadElement(new PetSearchModel { Id = petId });
if (elem == null)
return null;
return Tuple.Create(elem);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения животного по id={Id}", ownerId);
_logger.LogError(ex, "Ошибка получения животного по id={Id}", petId);
throw;
}
}

View File

@ -35,7 +35,7 @@ namespace VeterinaryRestApi.Controllers
}
}
[HttpGet]
public List<PurchaseViewModel> GetPurchases()
public List<PurchaseViewModel>? GetPurchases()
{
try
{
@ -60,19 +60,5 @@ namespace VeterinaryRestApi.Controllers
throw;
}
}
[HttpPost]
public bool ChangeDateImplement(PurchaseBindingModel model)
{
try
{
_purchase.ChangeDateImplement(model);
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить покупку");
throw;
}
}
}
}

View File

@ -19,14 +19,14 @@ namespace VeterinaryRestApi.Controllers
_visit = visit;
}
[HttpGet]
public Tuple<VisitViewModel, List<string>>? GetVisit(int visitId)
public Tuple<VisitViewModel>? GetVisit(int visitId)
{
try
{
var elem = _visit.ReadElement(new VisitSearchModel { Id = visitId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.VisitPet.Select(x => x.Value.PetName).ToList());
return Tuple.Create(elem);
}
catch (Exception ex)
{

View File

@ -110,6 +110,15 @@ namespace VeterinaryShowOwnerApp.Controllers
Response.Redirect("Enter");
return;
}
[HttpGet]
public IActionResult Pets()
{
if (APIOwner.Owner == null)
{
return Redirect("~/Home/Enter");
}
return View(APIOwner.GetRequest<List<PetViewModel>>($"api/pet/getpets?ownerid={APIOwner.Owner.Id}"));
}
public IActionResult CreatePet()
{
if (APIOwner.Owner == null)
@ -281,7 +290,6 @@ namespace VeterinaryShowOwnerApp.Controllers
return Redirect("~/Home/Enter");
}
ViewBag.Visits = APIOwner.GetRequest<List<VisitViewModel>>($"api/visit/getvisits?ownerid={APIOwner.Owner.Id}");
ViewBag.Pets = APIOwner.GetRequest<List<PetViewModel>>($"api/pet/getpets?ownerid={APIOwner.Owner.Id}");
return View();
}
@ -368,9 +376,9 @@ namespace VeterinaryShowOwnerApp.Controllers
[HttpPost]
public double Calc(int count, int drug)
{
var dru = APIOwner.GetRequest<DrugViewModel>($"api/drug/getonedrug?drugId={drug}");
//return count * (dru?.Price ?? 1);
return Math.Round(count * (dru?.Price ?? 1), 2);
var price = APIOwner.GetRequest<DrugViewModel>($"api/drug/getonedrug?drugId={drug}");
return count * (price?.Price ?? 1);
//return Math.Round(count * (price?.Price ?? 1), 2);
}
[HttpGet]

View File

@ -63,10 +63,6 @@
@Html.DisplayFor(modelItem =>
item.DateCreate)
</td>
<td>
@Html.DisplayFor(modelItem =>
item.DateImplement)
</td>
</tr>
}
</tbody>