コード例 #1
0
        public async Task UpdateCategory(int Id, CategoryForUpdate categoryForUpdate)
        {
            var categoria = await _repositoryWrapper.Category.GetById(Id);

            if (categoria == null)
            {
                return;
            }
            var categorytEntity = _mapper.Map <Category>(categoryForUpdate);
            await _repositoryWrapper.Category.Update(categorytEntity);
        }
コード例 #2
0
        public async Task <ActionResult <CategoryDTO> > UpdateAsync(string id, CategoryForUpdate model)
        {
            if (id != model.Id)
            {
                return(BadRequest(new ErrorResponse(HttpStatusCode.BadRequest, "Invalid Id")));
            }

            if (!ModelState.IsValid)
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage).ToList();
                return(BadRequest(new ErrorResponse(HttpStatusCode.BadRequest, "Validation error", errors)));
            }

            var result = await _categoryService.UpdateCategoryAsync(model);

            return(result.Succeed ? Ok(result.Value) : BadRequest(new ErrorResponse(HttpStatusCode.BadRequest, "Update fail", result.Errors)));
        }
コード例 #3
0
        public async Task <ProcessResult <CategoryDTO> > UpdateCategoryAsync(CategoryForUpdate model)
        {
            async Task <CategoryDTO> acction()
            {
                var category = await _repoWrapper.Category.FindById(model.Id);

                if (category == null)
                {
                    throw new InvalidOperationException("Id is not exist");
                }

                _ = _mapper.Map(model, category);

                category.ModifyBy   = CurrentUser.UserName;
                category.ModifyDate = DateTime.UtcNow;

                _repoWrapper.Category.Update(category);

                return(await _repoWrapper.SaveAsync() <= 0 ? throw new Exception("Save fail") : _mapper.Map <CategoryDTO>(category));
            }

            return(await Process.RunAsync(acction));
        }
コード例 #4
0
        public async Task <ActionResult> UpdateCategory(int Id, [FromBody] CategoryForUpdate categoryForUpdate)
        {
            await _categoryService.UpdateCategory(Id, categoryForUpdate);

            return(NoContent());
        }