Пример #1
0
        public ActionResult PartialBrandUpdate(Guid brandId, JsonPatchDocument <BrandUpdateDto> patcher)
        {
            Brand brandFromRep = _repository.GetBrandById(brandId);

            //patch upserting
            if (brandFromRep == null)
            {
                var newBrand = new BrandUpdateDto();
                patcher.ApplyTo(newBrand, ModelState);
                var brand = _mapper.Map <Brand>(newBrand);
                brand.Id = brandId;

                _repository.AddBrand(brand);
                _repository.SaveChanges();

                var brandReadDto = _mapper.Map <BrandReadDto>(brand);
                return(CreatedAtRoute("GetBrandById", new { brandId }, brandReadDto));
            }

            var brandToPatch = _mapper.Map <BrandUpdateDto>(brandFromRep);

            patcher.ApplyTo(brandToPatch, ModelState);

            _mapper.Map(brandToPatch, brandFromRep);

            _repository.UpdateBrand(brandFromRep);

            _repository.SaveChanges();

            return(NoContent());
        }
Пример #2
0
        public async Task <IResult> UpdateAsync(BrandUpdateDto brandUpdateDto)
        {
            var ruleResult = BusinessRules.Run(await CheckBrandNameExistButIgnoreByIdAsync(brandUpdateDto.Id, brandUpdateDto.Name));

            if (!ruleResult.Success)
            {
                return(ruleResult);
            }

            var findedBrandResult = await this.GetByIdAsync(brandUpdateDto.Id);

            if (!findedBrandResult.Success)
            {
                return(new ErrorResult(findedBrandResult.Message));
            }

            findedBrandResult.Data.Name = brandUpdateDto.Name;

            bool updateResult = await _brandDal.UpdateAsync(findedBrandResult.Data);

            if (!updateResult)
            {
                return(new ErrorResult(Messages.BrandNotUpdated));
            }

            return(new SuccessResult(Messages.BrandUpdated));
        }
Пример #3
0
        public IResult Update(BrandUpdateDto brandUpdateDto)
        {
            //mapping
            Brand brand = _mapper.Map <Brand>(brandUpdateDto);

            _brandDal.Update(brand);
            return(new SuccessResult(Messages.BrandUpdated));
        }
Пример #4
0
        public async Task <IActionResult> Update(BrandUpdateDto updateDto)
        {
            var result = await _brandService.UpdateAsync(_mapper.Map <Brand>(updateDto));

            if (result.Success)
            {
                return(NoContent());
            }
            return(BadRequest(result));
        }
Пример #5
0
        public IActionResult Update(BrandUpdateDto brandUpdateDto)
        {
            var result = _brandService.Update(brandUpdateDto);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Пример #6
0
        public async Task <IActionResult> UpdateAsync(BrandUpdateDto brandUpdateDto)
        {
            var result = await _brandService.UpdateAsync(brandUpdateDto);

            if (result.Success)
            {
                return(Ok(result));
            }

            return(BadRequest(result));
        }
Пример #7
0
        public ActionResult UpdateBrand(Guid brandId, BrandUpdateDto brandUpdateDto)
        {
            Brand brandFromRep = _repository.GetBrandById(brandId);

            //put upserting
            if (brandFromRep == null)
            {
                Brand newBrand = _mapper.Map <Brand>(brandUpdateDto);
                newBrand.Id = brandId;
                _repository.AddBrand(newBrand);
                _repository.SaveChanges();

                BrandReadDto newBrandRead = _mapper.Map <BrandReadDto>(newBrand);
                return(CreatedAtRoute("GetBrandById", new { brandId }, newBrandRead));
            }
            _mapper.Map(brandUpdateDto, brandFromRep);

            _repository.UpdateBrand(brandFromRep);

            _repository.SaveChanges();

            return(NoContent());
        }