コード例 #1
0
        public async Task <Response <object> > UpdateAsync(UpdateProductBindingModel bindingModel)
        {
            var response = await ValidateUpdateViewModel(bindingModel);

            if (response.ErrorOccurred)
            {
                return(response);
            }

            var product = await _productRepository.GetByAsync(x => x.Id == bindingModel.Id);

            _productRepository.Detach(product);

            var updatedProduct = _mapper.Map <Product>(bindingModel);

            updatedProduct.UserId = product.UserId;
            updatedProduct.User   = product.User;
            updatedProduct.Id     = product.Id;
            bool updateSucceed = await _productRepository.UpdateAsync(updatedProduct);

            if (!updateSucceed)
            {
                response.AddError(Key.Product, Error.UpdateError);
            }

            response.SuccessResult = bindingModel;
            return(response);
        }
コード例 #2
0
        public async Task <IActionResult> UpdateAsync(UpdateProductBindingModel bindingModel)
        {
            var result = await _productService.UpdateAsync(bindingModel);

            if (result.ErrorOccurred)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
コード例 #3
0
        public async Task <IActionResult> UpdateProductAsync(UpdateProductBindingModel model)
        {
            var(IsSuccessed, ErrorMsg) = await _productBLL.UpdateProductAsync(model.ID, model.Title, model.Description, model.CategoryID, model.AttachmentUrls);

            return(Json(new
            {
                IsSuccessed,
                ErrorMsg
            }));
        }
コード例 #4
0
        private async Task <Response <object> > ValidateUpdateViewModel(UpdateProductBindingModel bindingModel)
        {
            var  response      = new Response <object>();
            bool productExists = await _productRepository.ExistAsync(x => x.Id == bindingModel.Id);

            if (!productExists)
            {
                response.AddError(Key.Product, Error.ProductNotExist);
            }

            return(response);
        }