예제 #1
0
 public ProductsController(IGetProductsCommand getCommand, IGetProductCommand getOneCommand, IAddProductCommand addProductCommand, IDeleteProductCommand deleteProductCommand, IUpdateProductCommand updateProductCommand)
 {
     _getCommand    = getCommand;
     _getOneCommand = getOneCommand;
     _addCommand    = addProductCommand;
     _deleteCommand = deleteProductCommand;
     _updateCommand = updateProductCommand;
 }
예제 #2
0
 public ProductController(IGetProductListQuery getProductListQuery, ICreateProductViewModelFactory viewModelFactory,
                          ICreateProductCommand createProductCommand, IDeleteProductCommand deleteProductCommand,
                          IEditProductViewModelFactory editProductViewModelFactory, IUpdateProductCommand updateProductCommand)
 {
     this.getProductListQuery         = getProductListQuery;
     this.viewModelFactory            = viewModelFactory;
     this.createProductCommand        = createProductCommand;
     this.deleteProductCommand        = deleteProductCommand;
     this.editProductViewModelFactory = editProductViewModelFactory;
     this.updateProductCommand        = updateProductCommand;
 }
 public ProductsController(IGetProductsQuery IGetProductsQuery,
                           IGetProductByIDQuery IGetProductByIDQuery,
                           ICreateProductCommand ICreateProductCommand,
                           IUpdateProductCommand IUpdateProductCommand,
                           IDeleteProductCommand IDeleteProductCommand)
 {
     _IGetProductsQuery     = IGetProductsQuery;
     _IGetProductByIDQuery  = IGetProductByIDQuery;
     _ICreateProductCommand = ICreateProductCommand;
     _IUpdateProductCommand = IUpdateProductCommand;
     _IDeleteProductCommand = IDeleteProductCommand;
 }
예제 #4
0
        /// <summary>
        /// Update product
        /// </summary>
        /// <param name="productCommand"></param>
        /// <returns></returns>
        public async Task <UpdateProductDto> UpdateProduct(IUpdateProductCommand productCommand)
        {
            UpdateProductDto response = null;

            try
            {
                var product = Product.CreateProduct(productCommand);

                if (product == null)
                {
                    return(await Task.Run(() => response = new UpdateProductDto(null)));
                }

                if (product.Errors.Count > 0)
                {
                    return(await Task.Run(() => response = new UpdateProductDto(product)));
                }

                var existingProduct = _repository.Product.GetProductById(product.Id);
                if (existingProduct != null)
                {
                    var result = _repository.Product.GetByCondition(x =>
                                                                    (x.Code.Equals(product.Code) || x.Name.Equals(product.Name)) && x.Id != product.Id);

                    if (result?.Count() == 0)
                    {
                        _repository.Product.UpdateProduct(existingProduct, product);
                        _repository.Save();

                        response = new UpdateProductDto(product);
                    }
                }
                else
                {
                    response = new UpdateProductDto(product)
                    {
                        Errors = new List <Error>
                        {
                            new Error("Product", "Product doesn't exists")
                        }
                    };
                }

                return(await Task.Run(() => response));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                response = UpdateProductDto.PrepareExceptionResponse(null, "ERROR_SYSTEM");
                return(await Task.Run(() => response));
            }
        }
예제 #5
0
        public IActionResult Edit(
            ProductDto product,
            [FromServices] IUpdateProductCommand command)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Model error");
                GenerateViewBags();
                return(View(product));
            }

            _executor.ExecuteCommand(command, product);
            return(RedirectToAction("Index"));
        }
예제 #6
0
        public static Product CreateProduct(IUpdateProductCommand command)
        {
            if (command == null)
            {
                return(null);
            }

            var product = new Product
            {
                Id          = command.Id,
                Code        = command.Code,
                Name        = command.Name,
                Description = command.Description,
                PhotoName   = command.PhotoName,
                BlobName    = command.BlobName,
                Price       = command.Price,
                LastUpdated = DateTime.Now
            };

            product.ValidateModel();
            return(product);
        }
예제 #7
0
 public ActionResult Put(int id, [FromBody] ProductDto dto,
                         [FromServices] IUpdateProductCommand command)
 {
     executor.ExecuteCommand(command, id, dto);
     return(NoContent());
 }
예제 #8
0
 public void Put([FromForm] UpdateProductDto dto, [FromServices] IUpdateProductCommand command)
 {
     executor.ExecuteCommand(command, dto);
 }
예제 #9
0
 public void Put(int id, [FromBody] ProductDto dto,
                 [FromServices] IUpdateProductCommand command)
 {
     dto.Id = id;
     _executor.ExecuteCommand(command, dto);
 }
예제 #10
0
 public IActionResult Put(int id, [FromBody] ProductChangeDto dto, [FromServices] IUpdateProductCommand command)
 {
     dto.Id = id;
     _executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status204NoContent));
 }