public Task <ProductSalesDTO> FindSoldProductInfo(string productId, DateTime dateFrom, DateTime dateTo) { var resultDic = new Dictionary <string, ProductSalesDTO>(); IMongoCollection <Sales> salesCollection = mongoDbService.GetCollection <Sales>(); IEnumerable <Sales> salesList = salesCollection.AsQueryable().Where(item => item.SalesDate >= dateFrom && item.SalesDate <= dateTo); long totalSalesQuantity = 0; string productName = string.Empty; foreach (Sales sales in salesList) { IEnumerable <SalesLineItem> SalesLineItems = sales.SalesLineItems.Where(item => item.ProductId.Equals(productId)); foreach (SalesLineItem item in SalesLineItems) { totalSalesQuantity += item.SalesQuantity; if (string.IsNullOrEmpty(productName)) { productName = item.ProductName; } } } var proudctSalesDTO = new ProductSalesDTO { ProductId = productId, ProductName = productName, SalesQuantity = totalSalesQuantity }; return(Task.FromResult(proudctSalesDTO)); }
public async Task <QueryResult> Handle(SalesQuery query) { ProductSalesDTO productSalesDTO = await salesRepository.FindSoldProductInfo(query.ProductId, query.DateFrom, query.DateTo); return(new QueryResult { Result = productSalesDTO }); }
public void UpdateProductSales(ProductSalesDTO productSaleDTO) { ProductSale productSale = new ProductSale(); ProductSalesConvertor.ConvertToProductSaleEntity(ref productSale, productSaleDTO, true); UnitOfWork unitOfWork = new UnitOfWork(); unitOfWork.ProductSalesRepository.Update(productSale); unitOfWork.SaveChanges(); }
public ProductSalesDTO GetProductSalesById(int productSalesId) { ProductSalesDTO productSaleDTO = null; var productSales = unitOfWork.ProductSalesRepository.GetById(productSalesId); if (productSales != null) { productSaleDTO = ProductSalesConvertor.ConvertToProductSaleDto(productSales); } return(productSaleDTO); }
public static void ConvertToProductSaleEntity(ref ProductSale sale, ProductSalesDTO productSalesDTO, bool isUpdate) { if (isUpdate) { sale.SalesId = productSalesDTO.SalesId; } sale.SalesDate = productSalesDTO.SalesDate; sale.ProductMappingId = productSalesDTO.ProductMappingId; sale.Quantity = productSalesDTO.SalesQuantity; sale.TotalPrice = productSalesDTO.SalesPrice; sale.Ref1 = productSalesDTO.Ref1; sale.Ref2 = productSalesDTO.Ref2; }
public static ProductSalesDTO ConvertToProductSaleDto(ProductSale sale) { ProductSalesDTO productSalesDTO = new ProductSalesDTO(); productSalesDTO.SalesId = sale.SalesId; productSalesDTO.SalesDate = sale.SalesDate; productSalesDTO.ProductMappingId = sale.ProductMappingId; productSalesDTO.SalesQuantity = sale.Quantity; productSalesDTO.SalesPrice = sale.TotalPrice; productSalesDTO.Ref1 = sale.Ref1; productSalesDTO.Ref2 = sale.Ref2; return(productSalesDTO); }
public IHttpActionResult Put(int id, [FromBody] ProductSalesDTO productSalesDTO) { try { productSalesDTO.SalesId = id; if (productSalesDTO == null) { return(BadRequest("Argument Null")); } _productSalesService.UpdateProductSales(productSalesDTO); return(Ok()); } catch (PlatformModuleException ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Post([FromBody] ProductSalesDTO productSalesDTO) { try { if (productSalesDTO == null) { return(BadRequest("Argument Null")); } _productSalesService.AddProductSales(productSalesDTO); return(Ok()); } catch (PlatformModuleException ex) { //Write Log Here return(BadRequest(ex.Message)); } }