diff --git a/BusinessLogic/BusinessLogic.csproj b/BusinessLogic/BusinessLogic.csproj
index ceab2d9..62335f6 100644
--- a/BusinessLogic/BusinessLogic.csproj
+++ b/BusinessLogic/BusinessLogic.csproj
@@ -18,6 +18,7 @@
+
diff --git a/BusinessLogic/BusinessLogic/PurchaseLogic.cs b/BusinessLogic/BusinessLogic/PurchaseLogic.cs
new file mode 100644
index 0000000..1d46e64
--- /dev/null
+++ b/BusinessLogic/BusinessLogic/PurchaseLogic.cs
@@ -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 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);
+ }
+ }
+}
diff --git a/Contracts/BindingModels/PurchaseBindingModel.cs b/Contracts/BindingModels/PurchaseBindingModel.cs
index c0e577d..14433e7 100644
--- a/Contracts/BindingModels/PurchaseBindingModel.cs
+++ b/Contracts/BindingModels/PurchaseBindingModel.cs
@@ -1,4 +1,6 @@
-using System;
+using DataModels.Enums;
+using DataModels.Models;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -10,5 +12,8 @@ namespace Contracts.BindingModels
{
public Guid Id { get; set; }
public DateTime DatePurchase { get; set; }
+ public required IUser User { get; set; }
+ public required List Products { get; set; }
+ public PurchaseStatus Status { get; set; }
}
}
diff --git a/Contracts/Converters/PurchaseConverter.cs b/Contracts/Converters/PurchaseConverter.cs
new file mode 100644
index 0000000..1b181f5
--- /dev/null
+++ b/Contracts/Converters/PurchaseConverter.cs
@@ -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,
+ };
+ }
+}
diff --git a/DatabaseImplement/Database.cs b/DatabaseImplement/Database.cs
index f17e76a..7cfb7f0 100644
--- a/DatabaseImplement/Database.cs
+++ b/DatabaseImplement/Database.cs
@@ -28,7 +28,6 @@ namespace DatabaseImplement
public virtual DbSet SupplyProducts { get; set; } = null!;
public virtual DbSet Suppliers { get; set; } = null!;
public virtual DbSet SupplierProducts { get; set; } = null!;
-
public virtual DbSet MediaFiles { get; set; } = null!;
}
}
\ No newline at end of file