Ejemplo n.º 1
0
        /// <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();
        }
Ejemplo n.º 2
0
 public async Task Add([FromBody] ProductStorageModel model)
 {
     await _productStorageService.AddAsync(model);
 }