129 lines
4.5 KiB
C#
129 lines
4.5 KiB
C#
namespace NetinaShop.Domain.Entities.Orders;
|
|
|
|
public partial class Order
|
|
{
|
|
public static Order Create(Guid userId)
|
|
{
|
|
var factorNumber = StringExtensions.GetId(10).ToUpper();
|
|
return new Order(factorNumber, 0, 0, 0, 0, 0, 0, 0, false, OrderStatus.OrderBag, DateTime.MinValue, DateTime.Now, 0, string.Empty, userId, OrderPaymentMethod.OnlinePayment);
|
|
|
|
}
|
|
|
|
public void AddToOrderBag(Guid productId,double cost,double costWithDiscount,bool hasDiscount,double packingCost ,Guid categoryId , int count)
|
|
{
|
|
var orderProduct = OrderProducts.FirstOrDefault(op => op.ProductId == productId);
|
|
if (orderProduct == null)
|
|
{
|
|
orderProduct = OrderProduct.Create(count,
|
|
cost,
|
|
costWithDiscount,
|
|
hasDiscount,
|
|
packingCost,
|
|
OrderStatus.OrderBag,
|
|
productId,
|
|
categoryId,
|
|
this.Id);
|
|
OrderProducts.Add(orderProduct);
|
|
}
|
|
else
|
|
{
|
|
orderProduct.SetCount(count);
|
|
}
|
|
}
|
|
public void RemoveFromOrderBag(Guid productId, int count)
|
|
{
|
|
var orderProduct = OrderProducts.FirstOrDefault(op => op.ProductId == productId);
|
|
if (orderProduct != null)
|
|
{
|
|
orderProduct.SetCount(count);
|
|
if (orderProduct.Count == 0)
|
|
OrderProducts.Remove(orderProduct);
|
|
}
|
|
}
|
|
|
|
public void SetDiscount(string discountCode)
|
|
=> DiscountCode = discountCode;
|
|
public void AddOrderProduct(OrderProduct orderProduct)
|
|
=> OrderProducts.Add(orderProduct);
|
|
|
|
public void SetSubmitOrder(OrderPaymentMethod paymentMethod)
|
|
{
|
|
switch (paymentMethod)
|
|
{
|
|
case OrderPaymentMethod.OnlinePayment:
|
|
OrderStatus = OrderStatus.Paid;
|
|
IsPayed = true;
|
|
PayedAt = DateTime.Now;
|
|
OrderAt = DateTime.Now;
|
|
PaymentMethod = paymentMethod;
|
|
break;
|
|
case OrderPaymentMethod.CardTransfer:
|
|
OrderStatus = OrderStatus.Submitted;
|
|
IsPayed = false;
|
|
OrderAt = DateTime.Now;
|
|
PaymentMethod = paymentMethod;
|
|
break;
|
|
case OrderPaymentMethod.PayOnDoor:
|
|
OrderStatus = OrderStatus.Submitted;
|
|
IsPayed = false;
|
|
OrderAt = DateTime.Now;
|
|
PaymentMethod = paymentMethod;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void AddOrderDelivery(string address, string postalCode, string receiverPhoneNumber, string receiverFullName, double deliveryCost, Guid shippingId, Guid orderId)
|
|
{
|
|
var orderDelivery = OrderDelivery.Create(address, postalCode, receiverPhoneNumber, receiverFullName, deliveryCost, shippingId, orderId);
|
|
OrderDeliveries.Add(orderDelivery);
|
|
}
|
|
|
|
public void SetTotalPrice(double totalProductPrice,
|
|
double packingPrice,
|
|
double servicePrice,
|
|
double deliveryPrice,
|
|
double discountPrice,
|
|
double taxesPrice)
|
|
{
|
|
TotalProductsPrice = totalProductPrice;
|
|
PackingPrice = packingPrice;
|
|
ServicePrice = servicePrice;
|
|
DeliveryPrice = deliveryPrice;
|
|
TaxesPrice = taxesPrice;
|
|
DiscountPrice = discountPrice;
|
|
TotalPrice = (totalProductPrice + packingPrice + servicePrice + deliveryPrice + taxesPrice) - discountPrice;
|
|
}
|
|
|
|
}
|
|
|
|
public partial class OrderProduct
|
|
{
|
|
public static OrderProduct Create(int count,
|
|
double productFee,
|
|
double productFeeWithDiscount,
|
|
bool hasDiscount,
|
|
double packingFee,
|
|
OrderStatus orderProductStatus,
|
|
Guid productId,
|
|
Guid productCategoryId,
|
|
Guid orderId)
|
|
{
|
|
var productCost = count * productFeeWithDiscount;
|
|
var packingCost = count * packingFee;
|
|
return new OrderProduct(count, productFee, productFeeWithDiscount, hasDiscount, productCost, packingFee, packingCost, orderProductStatus, productId, productCategoryId, orderId);
|
|
}
|
|
|
|
public void SetCount(int count)
|
|
{
|
|
Count = count;
|
|
var productCost = ProductFeeWithDiscount * Count;
|
|
}
|
|
}
|
|
|
|
public partial class OrderDelivery
|
|
{
|
|
public static OrderDelivery Create(string address, string postalCode, string receiverPhoneNumber, string receiverFullName, double deliveryCost, Guid shippingId, Guid orderId)
|
|
{
|
|
return new OrderDelivery(address, postalCode, receiverPhoneNumber, receiverFullName, deliveryCost, shippingId, orderId);
|
|
}
|
|
} |