Exemplo n.º 1
0
        public HttpResponseMessage UpdateCustomer(HttpRequestMessage request, [FromBody] CustomerDTO dto)
        {
            TransactionalInformation transaction = new TransactionalInformation();

            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // REVERT
            //if (request.Headers.Authorization == null)
            //{
            //    transaction.ReturnMessage.Add("Your session is invalid.");
            //    transaction.ReturnStatus = false;
            //    var badResponse = Request.CreateResponse<TransactionalInformation>(HttpStatusCode.Unauthorized, transaction);
            //    return badResponse;
            //}

            //string tokenString = request.Headers.Authorization.ToString();

            //ClaimsPrincipal principal = TokenManager.ValidateToken(tokenString);

            //if (principal == null)
            //{

            //    transaction.ReturnMessage.Add("Your session is invalid.");
            //    transaction.ReturnStatus = false;
            //    var badResponse = Request.CreateResponse<TransactionalInformation>(HttpStatusCode.Unauthorized, transaction);
            //    return badResponse;
            //}
            var rd = new Random();

            if (dto.CustomerCode == null)
            {
                dto.CustomerCode = rd.Next().ToString();
            }

            CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService);

            customerBusinessService.UpdateCustomer(dto, out transaction);
            if (transaction.ReturnStatus == false)
            {
                var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction);
                return(badResponse);
            }

            dto.ReturnStatus  = true;
            dto.ReturnMessage = transaction.ReturnMessage;

            var response = Request.CreateResponse <CustomerDTO>(HttpStatusCode.OK, dto);

            return(response);
        }
Exemplo n.º 2
0
        public HttpResponseMessage UpdateCustomer(HttpRequestMessage request, [FromBody] CustomerInformation customerInformation)
        {
            TransactionalInformation transaction = new TransactionalInformation();

            if (request.Headers.Authorization == null)
            {
                transaction.ReturnMessage.Add("Your session is invalid.");
                transaction.ReturnStatus = false;
                var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.Unauthorized, transaction);
                return(badResponse);
            }

            string tokenString = request.Headers.Authorization.ToString();

            ClaimsPrincipal principal = TokenManager.ValidateToken(tokenString);

            if (principal == null)
            {
                transaction.ReturnMessage.Add("Your session is invalid.");
                transaction.ReturnStatus = false;
                var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.Unauthorized, transaction);
                return(badResponse);
            }

            CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService);

            customerBusinessService.UpdateCustomer(customerInformation, out transaction);
            if (transaction.ReturnStatus == false)
            {
                var badResponse = Request.CreateResponse <TransactionalInformation>(HttpStatusCode.BadRequest, transaction);
                return(badResponse);
            }

            customerInformation.ReturnStatus  = true;
            customerInformation.ReturnMessage = transaction.ReturnMessage;

            var response = Request.CreateResponse <CustomerInformation>(HttpStatusCode.OK, customerInformation);

            return(response);
        }
        public HttpResponseMessage UpdateCustomer(HttpRequestMessage request, [FromBody] CustomerViewModel customerViewModel)
        {
            TransactionalInformation transaction;

            Customer customer = new Customer();

            customer.CustomerID   = customerViewModel.CustomerID;
            customer.CompanyName  = customerViewModel.CompanyName;
            customer.ContactName  = customerViewModel.ContactName;
            customer.ContactTitle = customerViewModel.ContactTitle;
            customer.CustomerCode = customerViewModel.CustomerCode;
            customer.Address      = customerViewModel.Address;
            customer.City         = customerViewModel.City;
            customer.Region       = customerViewModel.Region;
            customer.PostalCode   = customerViewModel.PostalCode;
            customer.Country      = customerViewModel.Country;
            customer.PhoneNumber  = customerViewModel.PhoneNumber;
            customer.MobileNumber = customerViewModel.MobileNumber;

            CustomerBusinessService customerBusinessService = new CustomerBusinessService(_customerDataService);

            customerBusinessService.UpdateCustomer(customer, out transaction);
            if (transaction.ReturnStatus == false)
            {
                customerViewModel.ReturnStatus     = false;
                customerViewModel.ReturnMessage    = transaction.ReturnMessage;
                customerViewModel.ValidationErrors = transaction.ValidationErrors;

                var responseError = Request.CreateResponse <CustomerViewModel>(HttpStatusCode.BadRequest, customerViewModel);
                return(responseError);
            }

            customerViewModel.ReturnStatus  = true;
            customerViewModel.ReturnMessage = transaction.ReturnMessage;

            var response = Request.CreateResponse <CustomerViewModel>(HttpStatusCode.OK, customerViewModel);

            return(response);
        }