Исправленна бизнес логика для удаления и изменения покупки. Также добавлен ещё один способ фильтрации для покупки

This commit is contained in:
Николай 2023-04-03 18:23:22 +04:00
parent ff8041fe1a
commit 998e352d2d
4 changed files with 39 additions and 5 deletions

View File

@ -30,9 +30,21 @@ namespace HardwareShopContracts.BusinessLogicsContracts
return list;
}
public CommentViewModel? ReadElement(CommentSearchModel model)
public PurchaseSearchModel? ReadElement(PurchaseSearchModel model)
{
throw new NotImplementedException();
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{Id}", model.Id);
var element = _purchaseStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public bool DeliveryPurchase(PurchaseBindingModel model)
@ -78,6 +90,11 @@ namespace HardwareShopContracts.BusinessLogicsContracts
public bool Update(PurchaseBindingModel model)
{
if (model.PurchaseStatus == PurchaseStatus.Выдан)
{
_logger.LogWarning("Update status operation failed");
return false;
}
CheckModel(model);
if (_purchaseStorage.Update(model) == null)
{
@ -89,6 +106,11 @@ namespace HardwareShopContracts.BusinessLogicsContracts
public bool Delete(PurchaseBindingModel model)
{
if (model.PurchaseStatus == PurchaseStatus.Выдан)
{
_logger.LogWarning("Delete status operation failed");
return false;
}
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_purchaseStorage.Delete(model) == null)

View File

@ -7,7 +7,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts
public interface IPurchaseLogic
{
List<PurchaseViewModel>? ReadList(PurchaseSearchModel? model);
CommentViewModel? ReadElement(CommentSearchModel model);
PurchaseSearchModel? ReadElement(PurchaseSearchModel model);
bool Create(PurchaseBindingModel model);
bool Update(PurchaseBindingModel model);
bool Delete(PurchaseBindingModel model);

View File

@ -7,5 +7,7 @@ namespace HardwareShopContracts.SearchModels
public int? Id { get; set; }
public int? UserId { get; set; }
public DateTime? DatePurchase { get; set; }
}
}

View File

@ -25,10 +25,12 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
{
using var context = new HardwareShopDatabase();
if (!model.UserId.HasValue)
if (!model.UserId.HasValue && !model.DatePurchase.HasValue)
{
return new();
}
if (model.UserId.HasValue)
{
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
@ -37,6 +39,14 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.Select(x => x.GetViewModel)
.ToList();
}
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Include(x => x.User)
.Where(x => x.DatePurchase == model.DatePurchase)
.Select(x => x.GetViewModel)
.ToList();
}
public PurchaseViewModel? GetElement(PurchaseSearchModel model)
{