public void AddProductInStock(ProductsInWarehousesDTO item) { var n_item = new ProductInWarehouse { Id = item.Id, ProductId = item.ProductId, WarehouseId = item.WarehouseId }; Database.ProductsInWarehouses.Create(n_item); Database.Save(); }
public async Task <IActionResult> AddProduct(ProductToAddDto productToAddDto) { var warehouse = await _warehouserepo.GetWarehouse(productToAddDto.WarehouseId); if (warehouse == null) { return(BadRequest("No warehouse by this Id")); } if (!await _warehouserepo.ZoneExists(warehouse.WarehouseId, productToAddDto.ZoneId)) { return(BadRequest("Provided zone does not exist in this warehouse")); } //здесь добавить проверку на то, осталось ли достаточно места на складе. //Если да - вернуть зону, в котрую пометсить продукт var user = await _authrepo.GetUser(productToAddDto.Username, UserTypes.Renter); if (user == null) { return(BadRequest("User does not exist")); } var productToCreate = _mapper.Map <Product>(productToAddDto); productToCreate.UserId = user.UserId; _apprepo.Add(productToCreate); if (!await _apprepo.SaveAll()) { return(BadRequest("Problem adding product")); } ProductInWarehouse piw = new ProductInWarehouse(warehouse.WarehouseId, productToCreate.ProductId, productToAddDto.ZoneId); _apprepo.Add(piw); if (await _apprepo.SaveAll()) { return(Ok(piw)); } return(BadRequest("Problem adding product")); }