Exemplo n.º 1
0
        public async Task <ServiceResponse <GetSellerDTO> > UpdateSeller(UpdateSellerDTO updatedSeller)
        {
            ServiceResponse <GetSellerDTO> serviceResponse = new ServiceResponse <GetSellerDTO>();

            try
            {
                var seller = await _context.Sellers.FindAsync(updatedSeller.Id);

                if (seller != null)
                {
                    seller.Name     = updatedSeller.Name;
                    seller.Category = updatedSeller.Category;

                    _context.Sellers.Update(seller);
                    await _context.SaveChangesAsync();

                    serviceResponse.Data = _mapper.Map <GetSellerDTO>(seller);
                }
                else
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = $"Could not found seller with id '{updatedSeller.Id}'.";
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Success   = false;
                serviceResponse.Exception = ex.Message;
            }
            return(serviceResponse);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Update([FromBody] UpdateSellerDTO updatedSeller)
        {
            // check if requester is part of the seller
            if (!await _permissionService.UserIsSeller(HttpContext.GetUserIdFromToken(), updatedSeller.Id))
            {
                return(Forbid());
            }

            return(Ok(await _sellerService.UpdateSeller(updatedSeller)));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Update([FromRoute] int id, [FromBody] UpdateSellerDTO sellerDTO)
        {
            Seller seller = await _sellerRepository.FindByIdAsync(id);

            if (seller.IsNull())
            {
                return(NotFound());
            }

            _mapper.Map(sellerDTO, seller);
            await _sellerRepository.UpdateAsync(seller);

            return(NoContent());
        }
Exemplo n.º 4
0
        public async Task <ActionResult> UpdatePartial([FromRoute] int id, [FromBody] JsonPatchDocument <UpdateSellerDTO> pacthSellerDTO)
        {
            Seller seller = await _sellerRepository.FindByIdAsync(id);

            if (seller.IsNull())
            {
                return(NotFound());
            }

            UpdateSellerDTO sellerDTO = _mapper.Map <UpdateSellerDTO>(seller);

            pacthSellerDTO.ApplyTo(sellerDTO);
            if (!TryValidateModel(sellerDTO))
            {
                return(ValidationProblem(ModelState));
            }

            _mapper.Map(sellerDTO, seller);
            await _sellerRepository.UpdateAsync(seller);

            return(NoContent());
        }