コード例 #1
0
        public async Task <JsonResult> GetAppointment(string workOrderReference)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(workOrderReference))
                {
                    var errors = new List <ApiErrorMessage>
                    {
                        new ApiErrorMessage
                        {
                            developerMessage = "Invalid parameter - workorderreference",
                            userMessage      = "Please provide a valid work order reference"
                        }
                    };
                    var json = Json(errors);
                    json.StatusCode = 400;
                    return(json);
                }
                else
                {
                    var appointmentsActions = new AppointmentActions(_loggerAdapter, _appointmentsService, _serviceRequestBuilder, _repairsService, _repairsServiceRequestBuilder);
                    var response            = await appointmentsActions.GetAppointmentForWorksOrder(workOrderReference);

                    var json = Json(response);
                    json.StatusCode  = 200;
                    json.ContentType = "application/json";
                    return(json);
                }
            }
            catch (Exception ex)
            {
                var errors = new List <ApiErrorMessage>
                {
                    new ApiErrorMessage
                    {
                        developerMessage = ex.Message,
                        userMessage      = "We had some problems processing your request"
                    }
                };
                var json = Json(errors);
                json.StatusCode = 500;
                return(json);
            }
        }