fix : product name , order bag services , ver 0.5.4.13
parent
707fc19b7f
commit
6d35c18e01
|
@ -33,7 +33,7 @@ public class FileController : ICarterModule
|
|||
await uploadRequest.ImageResize(originalMedFileStream, mediumFileStream, 1280);
|
||||
await uploadRequest.ImageResize(originalThumbFileStream, thumbnailFileStream, 200);
|
||||
var medFileName = await storageService.UploadObjectFromFileAsync(uploadRequest.FileName, $"{uploadRequest.FileUploadType.ToDisplay()}/Med", uploadRequest.ContentType, mediumFileStream);
|
||||
await storageService.UploadObjectFromFileAsync(uploadRequest.FileName, $"{uploadRequest.FileUploadType.ToDisplay()}/Thumb", uploadRequest.ContentType, thumbnailFileStream);
|
||||
await storageService.UploadObjectFromFileAsync(uploadRequest.FileName, $"{uploadRequest.FileUploadType.ToDisplay()}/Thumb", uploadRequest.ContentType, thumbnailFileStream, false);
|
||||
var response = new FileUploadResponse
|
||||
{
|
||||
FileName = medFileName,
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<AssemblyVersion>0.4.3.12</AssemblyVersion>
|
||||
<FileVersion>0.4.3.12</FileVersion>
|
||||
<AssemblyVersion>0.5.4.13</AssemblyVersion>
|
||||
<FileVersion>0.5.4.13</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
public interface IStorageService : IScopedDependency
|
||||
{
|
||||
Task<string> UploadObjectFromFileAsync(string fileName, string filePath, string contentType, byte[] fileBytes);
|
||||
Task<string> UploadObjectFromFileAsync(string fileName, string filePath, string contentType, Stream fileStream);
|
||||
Task<string> UploadObjectFromFileAsync(string fileName, string filePath, string contentType, Stream fileStream, bool fixName = true);
|
||||
|
||||
Task<List<StorageFileSDto>> GetStorageFiles(StorageFileType fileType);
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
namespace NetinaShop.Core.EntityServices.DiscountHandlers;
|
||||
|
||||
public class CalculateDiscountCommandHandler : IRequestHandler<CalculateDiscountCommand , double>
|
||||
public class CalculateOrderDiscountCommandHandler : IRequestHandler<CalculateOrderDiscountCommand , double>
|
||||
{
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
|
||||
public CalculateDiscountCommandHandler(IRepositoryWrapper repositoryWrapper)
|
||||
public CalculateOrderDiscountCommandHandler(IRepositoryWrapper repositoryWrapper)
|
||||
{
|
||||
_repositoryWrapper = repositoryWrapper;
|
||||
}
|
||||
public async Task<double> Handle(CalculateDiscountCommand request, CancellationToken cancellationToken)
|
||||
public async Task<double> Handle(CalculateOrderDiscountCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.Order == null)
|
||||
throw new AppException("Order is null", ApiResultStatusCode.BadRequest);
|
||||
|
@ -22,38 +22,6 @@ public class CalculateDiscountCommandHandler : IRequestHandler<CalculateDiscount
|
|||
|
||||
double discountPrice = 0;
|
||||
|
||||
foreach (var orderProductGrouped in request.Order.OrderProducts.GroupBy(o=>o.ProductCategoryId))
|
||||
{
|
||||
var categoryDiscount = await _repositoryWrapper.SetRepository<CategoryDiscount>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(d => d.CategoryId == orderProductGrouped.Key && d.HasCode == false && d.ExpireDate.Date > DateTime.Today.Date , cancellationToken);
|
||||
|
||||
if (categoryDiscount != null && !categoryDiscount.IsExpired())
|
||||
{
|
||||
var totalPrice = request.Order.OrderProducts.Where(op => op.ProductCategoryId == categoryDiscount.CategoryId)
|
||||
.Sum(op => op.ProductCost);
|
||||
discountPrice = categoryDiscount.AmountType == DiscountAmountType.Amount
|
||||
? totalPrice - categoryDiscount.DiscountAmount
|
||||
: totalPrice - ((totalPrice / 100) * categoryDiscount.DiscountAmount);
|
||||
}
|
||||
|
||||
foreach (var orderProduct in orderProductGrouped)
|
||||
{
|
||||
|
||||
var productDiscount = await _repositoryWrapper.SetRepository<ProductDiscount>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(d => d.HasCode == false && d.ProductId == orderProduct.ProductId && d.ExpireDate.Date > DateTime.Today.Date, cancellationToken);
|
||||
|
||||
if (productDiscount != null && !productDiscount.IsExpired())
|
||||
{
|
||||
var totalPrice = request.Order.OrderProducts.Where(op => op.ProductId == productDiscount.ProductId).Sum(op => op.ProductCost);
|
||||
discountPrice = productDiscount.AmountType == DiscountAmountType.Amount
|
||||
? totalPrice - productDiscount.DiscountAmount
|
||||
: totalPrice - ((totalPrice / 100) * productDiscount.DiscountAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (discount.Type == DiscountType.All)
|
||||
{
|
||||
if (!discount.IsExpired())
|
|
@ -0,0 +1,66 @@
|
|||
using NetinaShop.Domain.Dtos.SmallDtos;
|
||||
|
||||
namespace NetinaShop.Core.EntityServices.DiscountHandlers;
|
||||
|
||||
public class CalculateProductDiscountCommandHandler : IRequestHandler<CalculateProductDiscountCommand, ProductSDto>
|
||||
{
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
|
||||
public CalculateProductDiscountCommandHandler(IRepositoryWrapper repositoryWrapper)
|
||||
{
|
||||
_repositoryWrapper = repositoryWrapper;
|
||||
}
|
||||
public async Task<ProductSDto> Handle(CalculateProductDiscountCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
double discountPrice = 0;
|
||||
request.ProductSDto.CostWithDiscount = request.ProductSDto.Cost;
|
||||
double totalPrice = request.ProductSDto.Cost;
|
||||
|
||||
var allDiscount = await _repositoryWrapper.SetRepository<Discount>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(d => d.Type == DiscountType.All && d.HasCode == false && d.ExpireDate.Date >= DateTime.Today.Date, cancellationToken);
|
||||
|
||||
if (allDiscount != null && !allDiscount.IsExpired())
|
||||
{
|
||||
|
||||
discountPrice = allDiscount.AmountType == DiscountAmountType.Amount ? totalPrice - allDiscount.DiscountAmount :
|
||||
totalPrice - totalPrice / 100 * allDiscount.DiscountPercent;
|
||||
request.ProductSDto.HasDiscount = true;
|
||||
}
|
||||
|
||||
var categoryDiscount = await _repositoryWrapper.SetRepository<CategoryDiscount>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(d => d.CategoryId == request.ProductSDto.CategoryId && d.HasCode == false && d.ExpireDate.Date >= DateTime.Today.Date, cancellationToken);
|
||||
|
||||
if (categoryDiscount != null && !categoryDiscount.IsExpired())
|
||||
{
|
||||
discountPrice = categoryDiscount.AmountType == DiscountAmountType.Amount
|
||||
? totalPrice - categoryDiscount.DiscountAmount : totalPrice - totalPrice / 100 * categoryDiscount.DiscountPercent;
|
||||
request.ProductSDto.HasDiscount = true;
|
||||
}
|
||||
|
||||
var productDiscount = await _repositoryWrapper.SetRepository<ProductDiscount>()
|
||||
.TableNoTracking
|
||||
.Where(d => d.HasCode == false && d.ProductId == request.ProductSDto.Id && d.ExpireDate.Date >= DateTime.Today.Date)
|
||||
.OrderByDescending(d => d.CreatedAt)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (productDiscount != null && !productDiscount.IsExpired())
|
||||
{
|
||||
discountPrice = productDiscount.AmountType == DiscountAmountType.Amount ? totalPrice - productDiscount.DiscountAmount
|
||||
: totalPrice - totalPrice / 100 * productDiscount.DiscountPercent;
|
||||
|
||||
request.ProductSDto.HasDiscount = true;
|
||||
if (productDiscount.IsSpecialOffer)
|
||||
request.ProductSDto.IsSpecial = true;
|
||||
}
|
||||
|
||||
if (request.ProductSDto.HasDiscount)
|
||||
{
|
||||
request.ProductSDto.CostWithDiscount = discountPrice;
|
||||
request.ProductSDto.DiscountPercent = request.ProductSDto.Cost == 0 ? 0 : 100 - 100 * request.ProductSDto.CostWithDiscount / request.ProductSDto.Cost;
|
||||
}
|
||||
|
||||
return request.ProductSDto;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
namespace NetinaShop.Core.EntityServices.OrderBagHandlers;
|
||||
|
||||
public class AddToOrderBagCommandHandler : IRequestHandler<AddToOrderBagCommand,bool>
|
||||
public class AddToOrderBagCommandHandler : IRequestHandler<AddToOrderBagCommand, OrderSDto>
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
|
@ -13,7 +13,7 @@ public class AddToOrderBagCommandHandler : IRequestHandler<AddToOrderBagCommand,
|
|||
_currentUserService = currentUserService;
|
||||
}
|
||||
|
||||
public async Task<bool> Handle(AddToOrderBagCommand request, CancellationToken cancellationToken)
|
||||
public async Task<OrderSDto> Handle(AddToOrderBagCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_currentUserService.UserId == null)
|
||||
throw new AppException("User id notfound", ApiResultStatusCode.BadRequest);
|
||||
|
@ -28,21 +28,24 @@ public class AddToOrderBagCommandHandler : IRequestHandler<AddToOrderBagCommand,
|
|||
var product = await _repositoryWrapper.SetRepository<Product>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(p => p.Id == requestDto.ProductId, cancellationToken);
|
||||
|
||||
|
||||
if (product == null)
|
||||
throw new AppException("Product not found ", ApiResultStatusCode.NotFound);
|
||||
if (!product.IsEnable)
|
||||
throw new AppException("Product is not enable", ApiResultStatusCode.BadRequest);
|
||||
|
||||
var productSDto = product.AdaptToSDto();
|
||||
await _mediator.Send(new CalculateProductDiscountCommand(productSDto), cancellationToken);
|
||||
|
||||
orderBag.AddToOrderBag(product, requestDto.Count);
|
||||
orderBag.AddToOrderBag(productSDto.Id, productSDto.Cost, productSDto.CostWithDiscount,
|
||||
productSDto.HasDiscount, productSDto.PackingCost, productSDto.CategoryId, requestDto.Count);
|
||||
}
|
||||
|
||||
_repositoryWrapper.SetRepository<Order>().Update(orderBag);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
|
||||
await _mediator.Send(new CalculateOrderCommand(orderBag.Id), cancellationToken);
|
||||
var order = await _mediator.Send(new CalculateOrderCommand(orderBag.Id), cancellationToken);
|
||||
|
||||
return true;
|
||||
return order.AdaptToSDto();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
namespace NetinaShop.Core.EntityServices.OrderBagHandlers;
|
||||
|
||||
public class RemoveFromOrderBagCommandHandler : IRequestHandler<RemoveFromOrderBagCommand,bool>
|
||||
public class RemoveFromOrderBagCommandHandler : IRequestHandler<RemoveFromOrderBagCommand, OrderSDto>
|
||||
{
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
|
@ -12,7 +12,7 @@ public class RemoveFromOrderBagCommandHandler : IRequestHandler<RemoveFromOrderB
|
|||
_repositoryWrapper = repositoryWrapper;
|
||||
_mediator = mediator;
|
||||
}
|
||||
public async Task<bool> Handle(RemoveFromOrderBagCommand request, CancellationToken cancellationToken)
|
||||
public async Task<OrderSDto> Handle(RemoveFromOrderBagCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (_currentUserService.UserId == null)
|
||||
throw new AppException("User id notfound", ApiResultStatusCode.BadRequest);
|
||||
|
@ -33,14 +33,14 @@ public class RemoveFromOrderBagCommandHandler : IRequestHandler<RemoveFromOrderB
|
|||
throw new AppException("Product is not enable", ApiResultStatusCode.BadRequest);
|
||||
|
||||
|
||||
orderBag.RemoveFromOrderBag(product, requestDto.Count);
|
||||
orderBag.RemoveFromOrderBag(product.Id, requestDto.Count);
|
||||
}
|
||||
|
||||
|
||||
_repositoryWrapper.SetRepository<Order>().Update(orderBag);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
await _mediator.Send(new CalculateOrderCommand(orderBag.Id), cancellationToken);
|
||||
var order = await _mediator.Send(new CalculateOrderCommand(orderBag.Id), cancellationToken);
|
||||
|
||||
return true;
|
||||
return order.AdaptToSDto();
|
||||
}
|
||||
}
|
|
@ -6,30 +6,33 @@ public class CalculateOrderCommandHandler : IRequestHandler<CalculateOrderComman
|
|||
private readonly IMediator _mediator;
|
||||
private readonly ShopSettings _shopSettings;
|
||||
|
||||
public CalculateOrderCommandHandler(IRepositoryWrapper repositoryWrapper,IMediator mediator,IOptionsSnapshot<ShopSettings> snapshot)
|
||||
public CalculateOrderCommandHandler(IRepositoryWrapper repositoryWrapper, IMediator mediator, IOptionsSnapshot<ShopSettings> snapshot)
|
||||
{
|
||||
_repositoryWrapper = repositoryWrapper;
|
||||
_mediator = mediator;
|
||||
_shopSettings = snapshot.Value;
|
||||
}
|
||||
|
||||
public async Task<Order> Handle(CalculateOrderCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var order = await _mediator.Send(new GetOrderQuery(request.OrderId), cancellationToken);
|
||||
if (order.OrderStatus != OrderStatus.OrderBag)
|
||||
throw new AppException("Order is not in bag status and cant be calculate", ApiResultStatusCode.BadRequest);
|
||||
var totalProductPrice = order.OrderProducts.Sum(op => op.ProductCost);
|
||||
var totalProductPrice = order.OrderProducts.Sum(op => op.ProductFee * op.Count);
|
||||
var totalPackingPrice = order.OrderProducts.Sum(op => op.PackingCost);
|
||||
var servicePrice = _shopSettings.ServiceIsPercent
|
||||
? (totalProductPrice / 100) * _shopSettings.ServiceFee
|
||||
: _shopSettings.ServiceFee;
|
||||
//var servicePrice = _shopSettings.ServiceIsPercent
|
||||
// ? (totalProductPrice / 100) * _shopSettings.ServiceFee
|
||||
// : _shopSettings.ServiceFee;
|
||||
var servicePrice = 0;
|
||||
var deliveryPrice = order.OrderDeliveries.Sum(op => op.DeliveryCost);
|
||||
double discountPrice = 0;
|
||||
double discountPrice = order.OrderProducts.Sum(op=>(op.ProductFee - op.ProductFeeWithDiscount) * op.Count);
|
||||
if (!order.DiscountCode.IsNullOrEmpty())
|
||||
{
|
||||
discountPrice = await _mediator.Send(new CalculateDiscountCommand(order.DiscountCode, order),cancellationToken);
|
||||
discountPrice += await _mediator.Send(new CalculateOrderDiscountCommand(order.DiscountCode, order),cancellationToken);
|
||||
}
|
||||
|
||||
var taxesPrice = (((totalProductPrice - discountPrice) + totalPackingPrice + servicePrice) / 100) * _shopSettings.TaxesFee;
|
||||
//var taxesPrice = (((totalProductPrice - discountPrice) + totalPackingPrice + servicePrice) / 100) * _shopSettings.TaxesFee;
|
||||
var taxesPrice = 0;
|
||||
|
||||
order.SetTotalPrice(totalProductPrice, totalPackingPrice, servicePrice, deliveryPrice, discountPrice, taxesPrice);
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Folder Include="BaseServices\Abstracts\" />
|
||||
<Folder Include="EntityServices\ProductHandlers\" />
|
||||
<Folder Include="EntityServices\ReviewHandlers\" />
|
||||
<Folder Include="Models\Api\" />
|
||||
<Folder Include="Utilities\" />
|
||||
|
|
|
@ -43,4 +43,4 @@ public sealed record UpdateDiscountCommand(Guid Id,
|
|||
|
||||
public sealed record DeleteDiscountCommand(Guid Id) : IRequest<bool>;
|
||||
|
||||
public sealed record CalculateDiscountCommand(string DiscountCode,Order Order) : IRequest<double>;
|
||||
public sealed record CalculateOrderDiscountCommand(string DiscountCode,Order Order) : IRequest<double>;
|
|
@ -4,8 +4,8 @@ namespace NetinaShop.Domain.CommandQueries.Commands;
|
|||
|
||||
public sealed record CreateOrderCommand(string DiscountCode, List<OrderProductSDto> OrderProducts, OrderDeliverySDto OrderDelivery) : IRequest<OrderSDto>;
|
||||
|
||||
public sealed record AddToOrderBagCommand(List<OrderBagRequestDto> RequestDtos) : IRequest<bool>;
|
||||
public sealed record RemoveFromOrderBagCommand(List<OrderBagRequestDto> RequestDtos) : IRequest<bool>;
|
||||
public sealed record AddToOrderBagCommand(List<OrderBagRequestDto> RequestDtos) : IRequest<OrderSDto>;
|
||||
public sealed record RemoveFromOrderBagCommand(List<OrderBagRequestDto> RequestDtos) : IRequest<OrderSDto>;
|
||||
|
||||
public sealed record SubmitDiscountCommand(Guid OrderId,string DiscountCode) : IRequest<bool>;
|
||||
public sealed record SubmitOrderDeliveryCommand(string Address, string PostalCode, string ReceiverPhoneNumber, string ReceiverFullName, Guid OrderId, Guid ShippingId) : IRequest<bool>;
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
public sealed record CreateBaseOrderCommand(Guid UserId) : IRequest<Order>;
|
||||
|
||||
public sealed record CalculateOrderCommand(Guid OrderId) : IRequest<Order>;
|
||||
public sealed record CalculateOrderCommand(Guid OrderId , bool NamoosiCalculate = false) : IRequest<Order>;
|
||||
|
||||
public sealed record DeleteOrderCommand(Guid OrderId) : IRequest<bool>;
|
|
@ -41,4 +41,6 @@ public sealed record UpdateProductCommand(
|
|||
List<SpecificationSDto> Specifications,
|
||||
List<StorageFileSDto> Files) : IRequest<bool>;
|
||||
|
||||
public sealed record DeleteProductCommand(Guid Id) : IRequest<bool>;
|
||||
public sealed record DeleteProductCommand(Guid Id) : IRequest<bool>;
|
||||
|
||||
public sealed record CalculateProductDiscountCommand(ProductSDto ProductSDto) : IRequest<ProductSDto>;
|
|
@ -22,7 +22,6 @@ public class ProductLDto : BaseDto<ProductLDto,Product>
|
|||
|
||||
public List<SpecificationSDto> Specifications { get; set; } = new();
|
||||
public List<ReviewSDto> Reviews { get; set; } = new();
|
||||
public List<ProductCategorySDto> Categories { get; set; } = new();
|
||||
public List<StorageFileSDto> Files { get; set; } = new();
|
||||
|
||||
public DiscountSDto? SpecialOffer { get; set; }
|
||||
|
|
|
@ -15,6 +15,8 @@ public class ProductSDto : BaseDto<ProductSDto, Product>
|
|||
public double CostWithDiscount { get; set; }
|
||||
public bool IsEnable { get; set; }
|
||||
public bool IsSpecial { get; set; }
|
||||
public int Stock { get; internal set; }
|
||||
public int MaxOrderCount { get; internal set; }
|
||||
public bool BeDisplayed { get; set; }
|
||||
public double PackingCost { get; set; }
|
||||
public float Rate { get; set; }
|
||||
|
|
|
@ -8,12 +8,20 @@ public partial class Order
|
|||
|
||||
}
|
||||
|
||||
public void AddToOrderBag(Product product, int count)
|
||||
public void AddToOrderBag(Guid productId,double cost,double costWithDiscount,bool hasDiscount,double packingCost ,Guid categoryId , int count)
|
||||
{
|
||||
var orderProduct = OrderProducts.FirstOrDefault(op => op.ProductId == product.Id);
|
||||
var orderProduct = OrderProducts.FirstOrDefault(op => op.ProductId == productId);
|
||||
if (orderProduct == null)
|
||||
{
|
||||
orderProduct = OrderProduct.Create(count, product.Cost,product.PackingCost, OrderStatus.OrderBag, product.Id,product.CategoryId, this.Id);
|
||||
orderProduct = OrderProduct.Create(count,
|
||||
cost,
|
||||
costWithDiscount,
|
||||
hasDiscount,
|
||||
packingCost,
|
||||
OrderStatus.OrderBag,
|
||||
productId,
|
||||
categoryId,
|
||||
this.Id);
|
||||
OrderProducts.Add(orderProduct);
|
||||
}
|
||||
else
|
||||
|
@ -21,9 +29,9 @@ public partial class Order
|
|||
orderProduct.SetCount(count);
|
||||
}
|
||||
}
|
||||
public void RemoveFromOrderBag(Product product, int count)
|
||||
public void RemoveFromOrderBag(Guid productId, int count)
|
||||
{
|
||||
var orderProduct = OrderProducts.FirstOrDefault(op => op.ProductId == product.Id);
|
||||
var orderProduct = OrderProducts.FirstOrDefault(op => op.ProductId == productId);
|
||||
if (orderProduct != null)
|
||||
{
|
||||
orderProduct.SetCount(count);
|
||||
|
@ -89,17 +97,25 @@ public partial class Order
|
|||
|
||||
public partial class OrderProduct
|
||||
{
|
||||
public static OrderProduct Create(int count, double productFee, double packingFee, OrderStatus orderProductStatus, Guid productId, Guid productCategoryId, Guid orderId)
|
||||
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 * productFee;
|
||||
var productCost = count * productFeeWithDiscount;
|
||||
var packingCost = count * packingFee;
|
||||
return new OrderProduct(count, productFee, productCost,packingFee,packingCost, orderProductStatus, productId,productCategoryId, orderId);
|
||||
return new OrderProduct(count, productFee, productFeeWithDiscount, hasDiscount, productCost, packingFee, packingCost, orderProductStatus, productId, productCategoryId, orderId);
|
||||
}
|
||||
|
||||
public void SetCount(int count)
|
||||
{
|
||||
Count = count;
|
||||
var productCost = ProductFee * Count;
|
||||
var productCost = ProductFeeWithDiscount * Count;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,10 +6,22 @@ public partial class OrderProduct : ApiEntity
|
|||
{
|
||||
|
||||
}
|
||||
public OrderProduct(int count, double productFee, double productCost, double packingFee, double packingCost, OrderStatus orderProductStatus, Guid productId, Guid productCategoryId, Guid orderId)
|
||||
public OrderProduct(int count,
|
||||
double productFee,
|
||||
double productFeeWithDiscount,
|
||||
bool hasDiscount,
|
||||
double productCost,
|
||||
double packingFee,
|
||||
double packingCost,
|
||||
OrderStatus orderProductStatus,
|
||||
Guid productId,
|
||||
Guid productCategoryId,
|
||||
Guid orderId)
|
||||
{
|
||||
Count = count;
|
||||
ProductFee = productFee;
|
||||
ProductFeeWithDiscount = productFeeWithDiscount;
|
||||
HasDiscount = hasDiscount;
|
||||
ProductCost = productCost;
|
||||
OrderProductStatus = orderProductStatus;
|
||||
ProductId = productId;
|
||||
|
@ -20,6 +32,8 @@ public partial class OrderProduct : ApiEntity
|
|||
}
|
||||
public int Count { get; internal set; }
|
||||
public double ProductFee { get; internal set; }
|
||||
public double ProductFeeWithDiscount { get; set; }
|
||||
public bool HasDiscount { get; set; }
|
||||
public double ProductCost { get; internal set; }
|
||||
public double PackingFee { get; internal set; }
|
||||
public double PackingCost { get; internal set; }
|
||||
|
|
|
@ -268,9 +268,11 @@ namespace NetinaShop.Domain.Mappers
|
|||
IsEnable = p37.IsEnable,
|
||||
BeDisplayed = p37.BeDisplayed,
|
||||
PackingCost = p37.PackingCost,
|
||||
Stock = p37.Stock,
|
||||
Rate = p37.Rate,
|
||||
ReviewCount = p37.ReviewCount,
|
||||
Viewed = p37.Viewed,
|
||||
MaxOrderCount = p37.MaxOrderCount,
|
||||
BrandId = p37.BrandId,
|
||||
Brand = new Brand()
|
||||
{
|
||||
|
@ -305,9 +307,11 @@ namespace NetinaShop.Domain.Mappers
|
|||
result.IsEnable = p38.IsEnable;
|
||||
result.BeDisplayed = p38.BeDisplayed;
|
||||
result.PackingCost = p38.PackingCost;
|
||||
result.Stock = p38.Stock;
|
||||
result.Rate = p38.Rate;
|
||||
result.ReviewCount = p38.ReviewCount;
|
||||
result.Viewed = p38.Viewed;
|
||||
result.MaxOrderCount = p38.MaxOrderCount;
|
||||
result.BrandId = p38.BrandId;
|
||||
result.Brand = funcMain15(new Never(), result.Brand, p38);
|
||||
result.CategoryId = p38.CategoryId;
|
||||
|
@ -329,6 +333,8 @@ namespace NetinaShop.Domain.Mappers
|
|||
Warranty = p44.Warranty,
|
||||
Cost = p44.Cost,
|
||||
IsEnable = p44.IsEnable,
|
||||
Stock = p44.Stock,
|
||||
MaxOrderCount = p44.MaxOrderCount,
|
||||
BeDisplayed = p44.BeDisplayed,
|
||||
PackingCost = p44.PackingCost,
|
||||
Rate = p44.Rate,
|
||||
|
@ -359,6 +365,8 @@ namespace NetinaShop.Domain.Mappers
|
|||
result.Warranty = p45.Warranty;
|
||||
result.Cost = p45.Cost;
|
||||
result.IsEnable = p45.IsEnable;
|
||||
result.Stock = p45.Stock;
|
||||
result.MaxOrderCount = p45.MaxOrderCount;
|
||||
result.BeDisplayed = p45.BeDisplayed;
|
||||
result.PackingCost = p45.PackingCost;
|
||||
result.Rate = p45.Rate;
|
||||
|
@ -384,6 +392,8 @@ namespace NetinaShop.Domain.Mappers
|
|||
Warranty = p47.Warranty,
|
||||
Cost = p47.Cost,
|
||||
IsEnable = p47.IsEnable,
|
||||
Stock = p47.Stock,
|
||||
MaxOrderCount = p47.MaxOrderCount,
|
||||
BeDisplayed = p47.BeDisplayed,
|
||||
PackingCost = p47.PackingCost,
|
||||
Rate = p47.Rate,
|
||||
|
|
|
@ -42,15 +42,18 @@ public class StorageService : IStorageService
|
|||
return fileName;
|
||||
}
|
||||
|
||||
public async Task<string> UploadObjectFromFileAsync(string fileName, string filePath, string contentType, Stream fileStream)
|
||||
public async Task<string> UploadObjectFromFileAsync(string fileName, string filePath, string contentType, Stream fileStream , bool fixName = true)
|
||||
{
|
||||
|
||||
var client = GetClientAsync();
|
||||
|
||||
var fileEx = fileName.Split('.').Last();
|
||||
fileName = fileName.Split('.').First();
|
||||
if (fixName)
|
||||
{
|
||||
var fileEx = fileName.Split('.').Last();
|
||||
fileName = fileName.Split('.').First();
|
||||
|
||||
fileName = fileName + "_" + StringExtensions.GetId(5) + "_" + DateTimeExtensions.DateTimeToUnixTimeStamp(DateTime.Now) + "." + fileEx;
|
||||
fileName = fileName + "_" + StringExtensions.GetId(5) + "_" + DateTimeExtensions.DateTimeToUnixTimeStamp(DateTime.Now) + "." + fileEx;
|
||||
}
|
||||
|
||||
var putRequest = new PutObjectRequest
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Microsoft.EntityFrameworkCore.Internal;
|
||||
using NetinaShop.Domain.Dtos.LargDtos;
|
||||
using NetinaShop.Domain.Dtos.SmallDtos;
|
||||
|
||||
namespace NetinaShop.Repository.Handlers.Products;
|
||||
|
@ -61,6 +62,8 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, List<Pr
|
|||
products = products.Where(p => productDiscount.Contains(p.Id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<ProductSDto> productSDtos = await products
|
||||
.Skip(request.Page * 20)
|
||||
.Take(20)
|
||||
|
@ -69,43 +72,7 @@ public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, List<Pr
|
|||
|
||||
foreach (var productSDto in productSDtos)
|
||||
{
|
||||
double discountPrice = 0;
|
||||
productSDto.CostWithDiscount = productSDto.Cost;
|
||||
var categoryDiscount = await _repositoryWrapper.SetRepository<CategoryDiscount>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(d => d.CategoryId == productSDto.CategoryId && d.HasCode == false && d.ExpireDate.Date >= DateTime.Today.Date, cancellationToken);
|
||||
|
||||
if (categoryDiscount != null && !categoryDiscount.IsExpired())
|
||||
{
|
||||
var totalPrice = productSDto.Cost;
|
||||
discountPrice = categoryDiscount.AmountType == DiscountAmountType.Amount
|
||||
? totalPrice - categoryDiscount.DiscountAmount : totalPrice - ((totalPrice / 100) * categoryDiscount.DiscountAmount);
|
||||
productSDto.CostWithDiscount = productSDto.CostWithDiscount - discountPrice;
|
||||
productSDto.HasDiscount = true;
|
||||
productSDto.DiscountPercent = (100 * productSDto.CostWithDiscount) / productSDto.Cost;
|
||||
}
|
||||
|
||||
var productDiscount = await _repositoryWrapper.SetRepository<ProductDiscount>()
|
||||
.TableNoTracking
|
||||
.Where(d => d.HasCode == false && d.ProductId == productSDto.Id && d.ExpireDate.Date >= DateTime.Today.Date)
|
||||
.OrderByDescending(d => d.CreatedAt)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (productDiscount != null && !productDiscount.IsExpired())
|
||||
{
|
||||
var totalPrice = productSDto.Cost;
|
||||
discountPrice = productDiscount.AmountType == DiscountAmountType.Amount
|
||||
? totalPrice - productDiscount.DiscountAmount
|
||||
: totalPrice - ((totalPrice / 100) * productDiscount.DiscountAmount);
|
||||
|
||||
productSDto.CostWithDiscount = productSDto.CostWithDiscount - discountPrice;
|
||||
productSDto.HasDiscount = true;
|
||||
if (productSDto.Cost > 0)
|
||||
productSDto.DiscountPercent = (100 * productSDto.CostWithDiscount) / productSDto.Cost;
|
||||
if (productDiscount.IsSpecialOffer)
|
||||
productSDto.IsSpecial = true;
|
||||
}
|
||||
|
||||
await _mediator.Send(new CalculateProductDiscountCommand(productSDto), cancellationToken);
|
||||
}
|
||||
|
||||
return productSDtos;
|
||||
|
|
1569
NetinaShop.Repository/Migrations/20240209214154_EditOrderProductAddDiscount.Designer.cs
generated
100644
1569
NetinaShop.Repository/Migrations/20240209214154_EditOrderProductAddDiscount.Designer.cs
generated
100644
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,44 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace NetinaShop.Repository.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class EditOrderProductAddDiscount : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "HasDiscount",
|
||||
schema: "public",
|
||||
table: "OrderProducts",
|
||||
type: "boolean",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
|
||||
migrationBuilder.AddColumn<double>(
|
||||
name: "ProductFeeWithDiscount",
|
||||
schema: "public",
|
||||
table: "OrderProducts",
|
||||
type: "double precision",
|
||||
nullable: false,
|
||||
defaultValue: 0.0);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "HasDiscount",
|
||||
schema: "public",
|
||||
table: "OrderProducts");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ProductFeeWithDiscount",
|
||||
schema: "public",
|
||||
table: "OrderProducts");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -529,6 +529,9 @@ namespace NetinaShop.Repository.Migrations
|
|||
b.Property<string>("CreatedBy")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("HasDiscount")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsRemoved")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
|
@ -559,6 +562,9 @@ namespace NetinaShop.Repository.Migrations
|
|||
b.Property<double>("ProductFee")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<double>("ProductFeeWithDiscount")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<Guid>("ProductId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
|
|
Loading…
Reference in New Issue