/// <summary> /// Добавляет продукт на склад(если он уже есть на складе, то прибавляет количество) /// </summary> /// <returns></returns> public async Task AddAsync(ProductStorageModel model) { if (model == null) { throw new NullReferenceException($"Ссылка на модель равняется null."); } var result = await _context.ProductStorages.SingleOrDefaultAsync(x => x.IdProduct == model.IdProduct && x.IdStorage == model.IdStorage); if (result != null) { result.ProductCount += model.ProductCount; } else { result = new ProductStorage { IdProduct = model.IdProduct, IdStorage = model.IdStorage, ProductCount = model.ProductCount }; await _context.ProductStorages.AddAsync(result); } await _context.SaveChangesAsync(); }
public async Task Add([FromBody] ProductStorageModel model) { await _productStorageService.AddAsync(model); }