Example #1
0
        public async void Create(ProductDto productDto)
        {
            try
            {
                _validationService.CheckForCategory(productDto.CategoryId);
                _validationService.CheckForSupplier(productDto.SupplierId);

                Product newProduct = new Product
                {
                    Name         = productDto.Name,
                    Category     = await _context.Categories.FindAsync(productDto.CategoryId),
                    Supplier     = await _context.Suppliers.FindAsync(productDto.SupplierId),
                    Count        = productDto.Count,
                    CountInStock = productDto.CountInStock,
                    Description  = productDto.Description,
                    Price        = productDto.Price,
                    Unit         = productDto.Unit
                };
                _context.Products.Add(newProduct);
                await _context.SaveChangesAsync();
            }
            catch (NotFoundExeption ex)
            {
                Console.WriteLine(ex.Message, ex);
            }
        }