Добавлена возможность захватывать небольшие европейские государства
This commit is contained in:
parent
c113e8f1a7
commit
cb37c8ab52
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||||
|
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
99
BusinessLogic/BusinessLogic/PurchaseLogic.cs
Normal file
99
BusinessLogic/BusinessLogic/PurchaseLogic.cs
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
using Contracts.BindingModels;
|
||||||
|
using Contracts.BusinessLogicContracts;
|
||||||
|
using Contracts.Converters;
|
||||||
|
using Contracts.Exceptions;
|
||||||
|
using Contracts.SearchModels;
|
||||||
|
using Contracts.StorageContracts;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using DatabaseImplement.Implements;
|
||||||
|
using DatabaseImplement.Models;
|
||||||
|
using DataModels.Enums;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BusinessLogic.BusinessLogic
|
||||||
|
{
|
||||||
|
public class PurchaseLogic : IPurchaseLogic
|
||||||
|
{
|
||||||
|
private readonly IPurchaseStorage _purchaseStorage;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public PurchaseLogic(IPurchaseStorage purchaseStorage, ILogger logger)
|
||||||
|
{
|
||||||
|
_purchaseStorage = purchaseStorage;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PurchaseViewModel Create(PurchaseBindingModel model)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
|
var purchase = _purchaseStorage.Insert(model);
|
||||||
|
if (purchase is null)
|
||||||
|
{
|
||||||
|
throw new Exception("Insert operation failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return PurchaseConverter.ToView(purchase);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PurchaseViewModel Delete(PurchaseSearchModel model)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
|
_logger.LogInformation("Delete purchase. Id: {0}", model.Id);
|
||||||
|
var purchase = _purchaseStorage.Delete(model);
|
||||||
|
if (purchase is null)
|
||||||
|
{
|
||||||
|
throw new Exception("Delete operation failed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return PurchaseConverter.ToView(purchase);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PurchaseViewModel ReadElement(PurchaseSearchModel model)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
|
_logger.LogInformation("ReadElement. Id: {0}", model.Id);
|
||||||
|
var purchase = _purchaseStorage.GetElement(model);
|
||||||
|
if (purchase is null)
|
||||||
|
{
|
||||||
|
throw new ElementNotFoundException();
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id: {0}", purchase.Id);
|
||||||
|
|
||||||
|
return PurchaseConverter.ToView(purchase);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<PurchaseViewModel> ReadElements(PurchaseSearchModel? model)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("ReadList. Id: {Id}", model?.Id);
|
||||||
|
var purchase_list = _purchaseStorage.GetList(model);
|
||||||
|
if (purchase_list is null || purchase_list.Count() == 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadList. Count: {Count}", purchase_list.Count());
|
||||||
|
|
||||||
|
return purchase_list.Select(PurchaseConverter.ToView);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PurchaseViewModel Update(PurchaseBindingModel model)
|
||||||
|
{
|
||||||
|
ArgumentNullException.ThrowIfNull(model);
|
||||||
|
|
||||||
|
var purchase = _purchaseStorage.Update(model);
|
||||||
|
if (purchase is null)
|
||||||
|
{
|
||||||
|
throw new Exception("Update operation failed.");
|
||||||
|
}
|
||||||
|
return PurchaseConverter.ToView(purchase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using DataModels.Enums;
|
||||||
|
using DataModels.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -10,5 +12,8 @@ namespace Contracts.BindingModels
|
|||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public DateTime DatePurchase { get; set; }
|
public DateTime DatePurchase { get; set; }
|
||||||
|
public required IUser User { get; set; }
|
||||||
|
public required List<IProduct> Products { get; set; }
|
||||||
|
public PurchaseStatus Status { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
29
Contracts/Converters/PurchaseConverter.cs
Normal file
29
Contracts/Converters/PurchaseConverter.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using Contracts.BindingModels;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Contracts.Converters
|
||||||
|
{
|
||||||
|
public class PurchaseConverter
|
||||||
|
{
|
||||||
|
public static PurchaseViewModel ToView(PurchaseBindingModel model) => new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
DatePurchase = model.DatePurchase,
|
||||||
|
User = model.User,
|
||||||
|
Products = model.Products,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static PurchaseBindingModel ToBinding(PurchaseViewModel model) => new()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
DatePurchase = model.DatePurchase,
|
||||||
|
User = model.User,
|
||||||
|
Products = model.Products,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,6 @@ namespace DatabaseImplement
|
|||||||
public virtual DbSet<SupplyProduct> SupplyProducts { get; set; } = null!;
|
public virtual DbSet<SupplyProduct> SupplyProducts { get; set; } = null!;
|
||||||
public virtual DbSet<Supplier> Suppliers { get; set; } = null!;
|
public virtual DbSet<Supplier> Suppliers { get; set; } = null!;
|
||||||
public virtual DbSet<SupplierProduct> SupplierProducts { get; set; } = null!;
|
public virtual DbSet<SupplierProduct> SupplierProducts { get; set; } = null!;
|
||||||
|
|
||||||
public virtual DbSet<MediaFile> MediaFiles { get; set; } = null!;
|
public virtual DbSet<MediaFile> MediaFiles { get; set; } = null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user