Beispiel #1
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            HttpContext ctx = default(HttpContext);

            ctx = HttpContext.Current;

            var request = actionContext.Request;

            if (!actionContext.ModelState.IsValid)
            {
                var transactionInformation = new TransactionInformationDTO();

                transactionInformation.ReturnMessage    = ModelStateHelper.ReturnErrorMessages(actionContext.ModelState.Values);
                transactionInformation.ValidationErrors = ModelStateHelper.ReturnValidationErrors(actionContext.ModelState);
                transactionInformation.ReturnStatus     = false;
                transactionInformation.IsAuthenticated  = ctx.User.Identity.IsAuthenticated;
                actionContext.Response = request.CreateResponse(HttpStatusCode.BadRequest, transactionInformation);
            }
        }
        public HttpResponseMessage UpdateCustomer(HttpRequestMessage request, [FromBody] CustomerMaintenanceDTO customerDTO)
        {
            TransactionalInformation transaction;

            CustomerMaintenanceViewModel customerMaintenanceViewModel = new CustomerMaintenanceViewModel();

            if (!ModelState.IsValid)
            {
                var errors = ModelState.Errors();
                customerMaintenanceViewModel.ReturnMessage    = ModelStateHelper.ReturnErrorMessages(errors);
                customerMaintenanceViewModel.ValidationErrors = ModelStateHelper.ReturnValidationErrors(errors);
                customerMaintenanceViewModel.ReturnStatus     = false;
                var badresponse = Request.CreateResponse <CustomerMaintenanceViewModel>(HttpStatusCode.BadRequest, customerMaintenanceViewModel);
                return(badresponse);
            }

            Customer customer = new Customer();

            ModelStateHelper.UpdateViewModel(customerDTO, customer);

            CustomerApplicationService customerApplicationService = new CustomerApplicationService(customerDataService);

            customerApplicationService.UpdateCustomer(customer, out transaction);

            customerMaintenanceViewModel.Customer         = customer;
            customerMaintenanceViewModel.ReturnStatus     = transaction.ReturnStatus;
            customerMaintenanceViewModel.ReturnMessage    = transaction.ReturnMessage;
            customerMaintenanceViewModel.ValidationErrors = transaction.ValidationErrors;

            if (transaction.ReturnStatus == false)
            {
                var badresponse = Request.CreateResponse <CustomerMaintenanceViewModel>(HttpStatusCode.BadRequest, customerMaintenanceViewModel);
                return(badresponse);
            }
            else
            {
                var response = Request.CreateResponse <CustomerMaintenanceViewModel>(HttpStatusCode.Created, customerMaintenanceViewModel);
                return(response);
            }
        }