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 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));
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }