private StockRoom AddNewStockRoomUpdatingTotal(StockRoomDto newStockRoomDto)
        {
            var currentProduct = _productServices.FindProduct(
                newStockRoomDto.ModelId,
                newStockRoomDto.SelectedColor.ColorId,
                newStockRoomDto.Size);

            var lastStockRoom = GetLastStockRoomByProductId(currentProduct.Id);
            var stocks        = newStockRoomDto.Quantity;

            if (lastStockRoom != null)
            {
                stocks += lastStockRoom.StockValue;
            }

            var newStockRoom = new StockRoom
            {
                ProductId     = currentProduct.Id,
                StockValue    = stocks,
                EntryValue    = newStockRoomDto.Quantity,
                EntryDate     = newStockRoomDto.EntryDate,
                OperationType = OperationType.IN.ToString(),
                SupplierId    = newStockRoomDto.SupplierId
            };

            _shoesDataEntities.StockRooms.Add(newStockRoom);
            return(newStockRoom);
        }
예제 #2
0
        public void AddSalesToStockAndDecrementProducts(SaleDto saleDto)
        {
            var newSale = new Sale()
            {
                SellingDate = saleDto.SellingDate,
                ClientId    = saleDto.ClientId
            };

            _shoesDataEntities.Sales.Add(newSale);
            foreach (var saleProductDto in saleDto.SalesProducts)
            {
                var currentProduct = _productServices.FindProduct(
                    saleProductDto.ModelId, saleProductDto.ColorId, saleProductDto.Size);
                var newSaleProduct = new SaleProduct
                {
                    ProductId    = currentProduct.Id,
                    SaleId       = newSale.Id,
                    Quantity     = saleProductDto.Quantity,
                    SellingPrice = saleProductDto.Price
                };
                _shoesDataEntities.SaleProducts.Add(newSaleProduct);
                var lastStockRoom = _stockRoomDataServices.GetLastStockRoomByProductId(currentProduct.Id);
                var newStockRoom  = new StockRoom()
                {
                    ProductId     = currentProduct.Id,
                    StockValue    = lastStockRoom.StockValue - saleProductDto.Quantity,
                    EntryValue    = -saleProductDto.Quantity,
                    EntryDate     = saleDto.SellingDate,
                    OperationType = OperationType.OUT.ToString()
                };
                _shoesDataEntities.StockRooms.Add(newStockRoom);
                SaveChanges();
            }
        }
        public int GetTotalShoesInStockRoomByProduct(int storeId, int modelId, int?colorId, double?size)
        {
            var currentProduct = _productServices.FindProduct(modelId, colorId, size);

            if (currentProduct == null)
            {
                return(0);
            }
            var lastStockEntry = GetLastStoreStockRoomByProductId(storeId, currentProduct.Id);

            return(lastStockEntry?.StockValue ?? 0);
        }