public override async Task <ProductSold> FindAsync(params object[] id) { var res = ProductSoldMapper.MapFromDAL(await Uow.ProductsSold.FindAsync(id)); res.Sale = SaleMapper.MapFromDAL(await Uow.Sales.FindAsync(res.SaleId)); return(res); }
public async Task <ActionResult <IEnumerable <PublicApi.v1.DTO.ProductSold> > > GetInfoBySaleId(int id) { var productSold = (await _bll.ProductsSold.AllAsyncByShopAndSaleId(id, User.GetShopId())) .Select(e => ProductSoldMapper.MapFromBLL(e)).ToList(); return(productSold); }
public override async Task <List <ProductSold> > AllAsync() { var res = (await Uow.ProductsSold.AllAsync()).Select(e => ProductSoldMapper.MapFromDAL(e)).ToList(); foreach (var result in res) { result.Sale = SaleMapper.MapFromDAL(await Uow.Sales.FindAsync(result.SaleId)); } return(res); }
public async Task <ActionResult <PublicApi.v1.DTO.ProductSold> > GetProductSold(int id) { var productSold = await _bll.ProductsSold.GetAsyncByShopAndIdDTO(id, User.GetShopId()); if (productSold == null) { return(NotFound()); } return(ProductSoldMapper.MapFromBLL(productSold)); }
public override async Task <List <DTO.DomainLikeDTO.ProductSold> > AllAsync() { return(await RepositoryDbSet .Include(a => a.Product).ThenInclude(aa => aa.ProductName).ThenInclude(t => t.Translations) .Include(a => a.Product).ThenInclude(aa => aa.Length).ThenInclude(t => t.Translations) .Include(a => a.Product).ThenInclude(aa => aa.Weight).ThenInclude(t => t.Translations) .Include(a => a.Product).ThenInclude(aa => aa.ManuFacturerItemCode).ThenInclude(t => t.Translations) .Include(a => a.Product).ThenInclude(aa => aa.ShopCode).ThenInclude(t => t.Translations) .Include(p => p.Sale).ThenInclude(aa => aa.Description).ThenInclude(t => t.Translations) .Select(e => ProductSoldMapper.MapFromDomain(e)).ToListAsync()); }
public override async Task <DTO.DomainLikeDTO.ProductSold> FindAsync(params object[] id) { var productSold = await RepositoryDbSet.FindAsync(id); return(ProductSoldMapper.MapFromDomain(await RepositoryDbSet.Where(a => a.Id == productSold.Id) .Include(a => a.Product).ThenInclude(aa => aa.ProductName).ThenInclude(t => t.Translations) .Include(a => a.Product).ThenInclude(aa => aa.Length).ThenInclude(t => t.Translations) .Include(a => a.Product).ThenInclude(aa => aa.Weight).ThenInclude(t => t.Translations) .Include(a => a.Product).ThenInclude(aa => aa.ManuFacturerItemCode).ThenInclude(t => t.Translations) .Include(a => a.Product).ThenInclude(aa => aa.ShopCode).ThenInclude(t => t.Translations) .Include(p => p.Sale).ThenInclude(aa => aa.Description).ThenInclude(t => t.Translations) .FirstOrDefaultAsync())); }
public async Task <IActionResult> PutProductSold(int id, PublicApi.v1.DTO.ProductSold productSold) { if (!ModelState.IsValid || id != productSold.Id) { return(BadRequest()); } if (await _bll.ProductsSold.EditProductInSale(id, productSold.ProductId, ProductSoldMapper.MapFromExternal(productSold))) { return(NoContent()); } return(BadRequest()); }
public async Task <bool> AddProductToSale(int productId, ProductSold productSold) { var product = await Uow.Products.FindProductInfoAsync(productId); // subtract quantity (check if enough in stock) if (product.Quantity - productSold.Quantity < 0) { return(false); } product.Quantity -= productSold.Quantity; Uow.Products.Update(product); await Uow.ProductsSold.AddAsync(ProductSoldMapper.MapFromBLL(productSold)); await Uow.SaveChangesAsync(); return(true); }
public async Task <bool> EditProductInSale(int id, int productId, ProductSold productSold) { var product = await Uow.Products.FindProductInfoAsync(productId); var initialQuantity = await Uow.ProductsSold.GetQuantity(id); var quantityBeforeChange = product.Quantity + initialQuantity; if (quantityBeforeChange - productSold.Quantity < 0) { return(false); } product.Quantity = quantityBeforeChange - productSold.Quantity; Uow.Products.Update(product); Uow.ProductsSold.Update(ProductSoldMapper.MapFromBLL(productSold)); await Uow.SaveChangesAsync(); return(true); }
public async Task <ActionResult <ProductSold> > PostProductSold(PublicApi.v1.DTO.ProductSold productSold) { if (!ModelState.IsValid) { return(BadRequest()); } if (await _bll.ProductsSold.AddProductToSale(productSold.ProductId, ProductSoldMapper.MapFromExternal(productSold))) { await _bll.SaveChangesAsync(); productSold = PublicApi.v1.Mappers.ProductSoldMapper.MapFromBLL( _bll.ProductsSold.GetUpdatesAfterUOWSaveChanges( PublicApi.v1.Mappers.ProductSoldMapper.MapFromExternal(productSold))); return(CreatedAtAction("GetProductSold", new { version = HttpContext.GetRequestedApiVersion().ToString(), id = productSold.Id }, productSold)); } return(BadRequest()); }
public async Task <List <DTO.ProductSold> > AllAsyncByShopAndSaleId(int id, int?shopId) { return((await Uow.ProductsSold.AllAsyncByShopAndSaleId(id, shopId)) .Select(e => ProductSoldMapper.MapFromDAL(e)).ToList()); }
public async Task <DTO.ProductSold> GetAsyncByShopAndIdDTO(int id, int?shopId) { return(ProductSoldMapper.MapFromDAL(await Uow.ProductsSold.GetAsyncByShopAndIdDTO(id, shopId))); }
public async Task <List <ProductSold> > FindBySaleId(int saleId) { return((await Uow.ProductsSold.FindBySaleId(saleId)).Select(e => ProductSoldMapper.MapFromDAL(e)).ToList()); }