Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Доработка сущностей #10

Merged
merged 5 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Src/ApplicationCore/ApplicationCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
<None Remove="Specifications\**" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Ardalis.Specification" Version="6.1.0" />
</ItemGroup>

</Project>
6 changes: 0 additions & 6 deletions Src/ApplicationCore/Entities/BaseEntity.cs

This file was deleted.

30 changes: 24 additions & 6 deletions Src/ApplicationCore/Entities/BasketAggregate/Basket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,38 @@

namespace ProgGym.CoffeeShop.ApplicationCore.Entities.BasketAggregate;

public class Basket : BaseEntity
public class Basket
{
private readonly ICollection<BasketItem> _items;
public int Id { get; set; }
public List<BasketItem> Items { get; private set; }

public int TotalItems => Items.Sum(i => i.Quantity);

public Basket()
{
_items = new List<BasketItem>();
Items = new List<BasketItem>();
}

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);
}
}
15 changes: 14 additions & 1 deletion Src/ApplicationCore/Entities/BasketAggregate/BasketItem.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
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;
AmountPrice = amountPrice;
Quantity = quantity;
}

public void AddQuantity(int quantity)
{
Quantity += quantity;
}

public void DeleteQuantity()
{
Quantity -= 1;
}

}
37 changes: 37 additions & 0 deletions Src/ApplicationCore/Entities/CatalogClassDiagram.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Class Name="ProgGym.CoffeeShop.ApplicationCore.Entities.CatalogItem">
<Position X="4.75" Y="1" Width="1.5" />
<Members>
<Method Name="CatalogItem" Hidden="true" />
</Members>
<TypeIdentifier>
<HashCode>AAACAAAAAwAgAgAAAAAAAAQAAAAAAAAAAAAAAAAACAA=</HashCode>
<FileName>Entities\CatalogItem.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="CatalogType" />
</ShowAsAssociation>
</Class>
<Class Name="ProgGym.CoffeeShop.ApplicationCore.Entities.CatalogType">
<Position X="7.75" Y="1" Width="1.5" />
<Members>
<Method Name="CatalogType" Hidden="true" />
</Members>
<TypeIdentifier>
<HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAA=</HashCode>
<FileName>Entities\CatalogType.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="ProgGym.CoffeeShop.ApplicationCore.Entities.BasketAggregate.BasketItem">
<Position X="2.25" Y="0.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAICAAAAAKAAEAAAAAgAAAAAAAAAAAAAAAAAgAAAAAA=</HashCode>
<FileName>Entities\BasketAggregate\BasketItem.cs</FileName>
</TypeIdentifier>
<ShowAsAssociation>
<Property Name="CatalogItem" />
</ShowAsAssociation>
</Class>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
7 changes: 4 additions & 3 deletions Src/ApplicationCore/Entities/CatalogItem.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
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; }
public string PictureUri { get; private set; }
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;
Expand Down
3 changes: 2 additions & 1 deletion Src/ApplicationCore/Entities/CatalogType.cs
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions Src/ApplicationCore/Interfaces/IAppLogger.cs
Original file line number Diff line number Diff line change
@@ -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);
}
8 changes: 8 additions & 0 deletions Src/ApplicationCore/Interfaces/IRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Ardalis.Specification;

namespace ProgGym.CoffeeShop.ApplicationCore.Interfaces;

interface IRepository<T> : IRepositoryBase<T> where T : class
{

}