Пример #1
0
        public async Task <ActionResult> CustomerUpdate(int customerId, CustomerPutDTO customerPutDTO)
        {
            if (customerId != customerPutDTO.CustomerId)
            {
                ModelState.AddModelError("CustomerId", "The Parameter CustomerId and the CustomerId from the body do not match.");
                return(ValidationProblem(ModelState));
            }

            // Get a copy of the Customer entity from the respository
            var updateCustomer = await _customerRespository.GetById(customerId);

            if (updateCustomer is null)
            {
                return(NotFound());
            }

            // Map customerPutDTO to the repositories Customer entity
            updateCustomer = _mapper.Map(customerPutDTO, updateCustomer);

            // Apply audit changes to Customer entity
            updateCustomer = Audit <Customer> .PerformAudit(updateCustomer);

            // Update Customer in the respository
            var isUpdated = await _customerRespository.Update(updateCustomer);

            if (!isUpdated)
            {
                return(NotFound());
            }

            return(Ok());
        }
Пример #2
0
        public async Task <Response> Update(int id, CustomerRequest request)
        {
            Customer info = await _customerRespository.FindById(id);

            if (info == null)
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Messages.NotFound.ToString()
                });
            }
            info.CC       = request.CC;
            info.Phone    = request.Phone;
            info.Name     = request.Name;
            info.LastName = request.LastName;
            int result = await _customerRespository.Update(info,
                                                           request.IPSId);

            if (result > 0)
            {
                return(new Response
                {
                    IsSuccess = true,
                    Message = Messages.Updated.ToString(),
                    Result = result
                });
            }
            else
            {
                return(new Response
                {
                    IsSuccess = false,
                    Message = Messages.NotUpdated.ToString()
                });
            }
        }