diff --git a/Src/ApplicationCore/ApplicationCore.csproj b/Src/ApplicationCore/ApplicationCore.csproj index 8d9f427..0de61d9 100644 --- a/Src/ApplicationCore/ApplicationCore.csproj +++ b/Src/ApplicationCore/ApplicationCore.csproj @@ -20,4 +20,8 @@ + + + + diff --git a/Src/ApplicationCore/Entities/BaseEntity.cs b/Src/ApplicationCore/Entities/BaseEntity.cs deleted file mode 100644 index c3d8aec..0000000 --- a/Src/ApplicationCore/Entities/BaseEntity.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace ProgGym.CoffeeShop.ApplicationCore.Entities; - -public abstract class BaseEntity -{ - public virtual int Id { get; set; } -} \ No newline at end of file diff --git a/Src/ApplicationCore/Entities/BasketAggregate/Basket.cs b/Src/ApplicationCore/Entities/BasketAggregate/Basket.cs index d92f73a..058292d 100644 --- a/Src/ApplicationCore/Entities/BasketAggregate/Basket.cs +++ b/Src/ApplicationCore/Entities/BasketAggregate/Basket.cs @@ -3,20 +3,38 @@ namespace ProgGym.CoffeeShop.ApplicationCore.Entities.BasketAggregate; -public class Basket : BaseEntity +public class Basket { - private readonly ICollection _items; + public int Id { get; set; } + public List Items { get; private set; } + + public int TotalItems => Items.Sum(i => i.Quantity); + public Basket() { - _items = new List(); + Items = new List(); } public void AddItem(int catalogItemId, decimal amountPrice, int quantity = 1) { - var basket = new BasketItem(catalogItemId,amountPrice,quantity); - if(_items.Any(i => i.CatalogItemId == catalogItemId)) + if(Items.Any(i => i.CatalogItemId == catalogItemId)) + { + var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); + existingItem.AddQuantity(quantity); + } + else { - + var newBasketItem = new BasketItem(catalogItemId,amountPrice,quantity); + Items.Add(newBasketItem); } } + public void DeleteItem(int catalogItemId) + { + var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId); + existingItem.DeleteQuantity(); + } + public void RemoveEmptyItems() + { + Items.RemoveAll(i => i.Quantity == 0); + } } \ No newline at end of file diff --git a/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs b/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs index 7e9fe7c..7c2ea7d 100644 --- a/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs +++ b/Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs @@ -1,10 +1,13 @@ namespace ProgGym.CoffeeShop.ApplicationCore.Entities.BasketAggregate; -public class BasketItem : BaseEntity +public class BasketItem { + public int Id { get; set; } public decimal AmountPrice { get; private set; } public int Quantity { get; private set; } public int CatalogItemId { get; private set; } + public CatalogItem CatalogItem { get; private set; } + public BasketItem(int catalogItemId, decimal amountPrice, int quantity) { CatalogItemId = catalogItemId; @@ -12,4 +15,14 @@ public BasketItem(int catalogItemId, decimal amountPrice, int quantity) Quantity = quantity; } + public void AddQuantity(int quantity) + { + Quantity += quantity; + } + + public void DeleteQuantity() + { + Quantity -= 1; + } + } \ No newline at end of file diff --git a/Src/ApplicationCore/Entities/CatalogClassDiagram.cd b/Src/ApplicationCore/Entities/CatalogClassDiagram.cd new file mode 100644 index 0000000..d3acfbc --- /dev/null +++ b/Src/ApplicationCore/Entities/CatalogClassDiagram.cd @@ -0,0 +1,37 @@ + + + + + + + + AAACAAAAAwAgAgAAAAAAAAQAAAAAAAAAAAAAAAAACAA= + Entities\CatalogItem.cs + + + + + + + + + + + AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAA= + Entities\CatalogType.cs + + + + + + AAICAAAAAKAAEAAAAAgAAAAAAAAAAAAAAAAAgAAAAAA= + Entities\BasketAggregate\BasketItem.cs + + + + + + + \ No newline at end of file diff --git a/Src/ApplicationCore/Entities/CatalogItem.cs b/Src/ApplicationCore/Entities/CatalogItem.cs index 531b216..f9c9569 100644 --- a/Src/ApplicationCore/Entities/CatalogItem.cs +++ b/Src/ApplicationCore/Entities/CatalogItem.cs @@ -1,7 +1,8 @@ namespace ProgGym.CoffeeShop.ApplicationCore.Entities; -public class CatalogItem : BaseEntity +public class CatalogItem { + public int Id { get; set; } public string Name { get; private set; } public string Description { get; private set; } public decimal Price { get; private set; } @@ -9,9 +10,9 @@ public class CatalogItem : BaseEntity public int CatalogTypeId { get; private set; } public CatalogType CatalogType { get; private set; } - public CatalogItem(int id,string name, string description, decimal price,string pictureUri, int catalogItemId) + + public CatalogItem(string name, string description, decimal price,string pictureUri, int catalogItemId) { - Id = id; Name = name; Description = description; Price = price; diff --git a/Src/ApplicationCore/Entities/CatalogType.cs b/Src/ApplicationCore/Entities/CatalogType.cs index 0aab9ec..aca783a 100644 --- a/Src/ApplicationCore/Entities/CatalogType.cs +++ b/Src/ApplicationCore/Entities/CatalogType.cs @@ -1,7 +1,8 @@ namespace ProgGym.CoffeeShop.ApplicationCore.Entities; -public class CatalogType : BaseEntity +public class CatalogType { + public int Id { get; set; } public string Type { get; private set; } public CatalogType(string type) { diff --git a/Src/ApplicationCore/Interfaces/IAppLogger.cs b/Src/ApplicationCore/Interfaces/IAppLogger.cs new file mode 100644 index 0000000..44d7382 --- /dev/null +++ b/Src/ApplicationCore/Interfaces/IAppLogger.cs @@ -0,0 +1,7 @@ +namespace ProgGym.CoffeeShop.ApplicationCore.Interfaces; +interface IAppLogger +{ + void LogInformation(string messange, params object[] args); + void LogWarning(string messange, params object[] args); + void LogError(string messange, params object[] args); +} \ No newline at end of file diff --git a/Src/ApplicationCore/Interfaces/IRepository.cs b/Src/ApplicationCore/Interfaces/IRepository.cs new file mode 100644 index 0000000..03aed4e --- /dev/null +++ b/Src/ApplicationCore/Interfaces/IRepository.cs @@ -0,0 +1,8 @@ +using Ardalis.Specification; + +namespace ProgGym.CoffeeShop.ApplicationCore.Interfaces; + +interface IRepository : IRepositoryBase where T : class +{ + +} \ No newline at end of file