コード例 #1
0
        public void Execute(ProductDto request)
        {
            _productValidation.ValidateAndThrow(request);

            var product = _mapper.Map <ProductDto, Product>(request);

            _context.Products.Add(product);
            _context.SaveChanges();
        }
コード例 #2
0
        public void Execute(ProductDto request)
        {
            _productValidation.ValidateAndThrow(request);

            var product = new Product
            {
                Name           = request.Name,
                Id             = request.Id,
                Price          = request.Price,
                Description    = request.Description,
                CategoryId     = _context.Categories.FirstOrDefault(x => x.Name == request.Category).Id,
                ManufacturerId = _context.Manufacturers.FirstOrDefault(x => x.Name == request.Manufacturer).Id,
                SupplierId     = _context.Suppliers.FirstOrDefault(x => x.Name == request.Supplier).Id,
            };

            _context.Products.Update(product);
            _context.SaveChanges();
        }
コード例 #3
0
        public void Execute(ProductDto request)
        {
            _productValidation.ValidateAndThrow(request);

            _productContext.Update(request);
        }