예제 #1
0
        public void Handle(string target, HttpRequest baseRequest, HttpResponse response)
        {
            response.SetContentType("application/json;charset=utf-8");
            response.SetStatus(HttpStatusCode.OK);
            baseRequest.SetHandled(true);

            try
            {
                if (IsApplication(baseRequest))
                {
                    LoanApplication application = new LoanApplication();
                    application.SetAmount(AmountFrom(baseRequest));
                    application.SetContact(ContactFrom(baseRequest));
                    Ticket ticket = _loanRepository.Store(application);
                    response.Write(JsonSerialiser.ToJson(ticket));
                }
                else if (IsStatusRequest(baseRequest) && IdSpecified(baseRequest))
                {
                    response.Write(FetchLoanInfo(baseRequest.GetParameter(TICKET_ID)));
                }
                else if (IsApproval(baseRequest) && IdSpecified(baseRequest))
                {
                    response.Write(ApproveLoan(baseRequest.GetParameter(TICKET_ID)));
                }
                else
                {
                    response.Write("Incorrect parameters provided");
                }
            }
            catch (ApplicationException ex)
            {
                response.Write("Uh oh! Problem occured: " + ex);
            }
        }
예제 #2
0
        private string FetchLoanInfo(string ticketId)
        {
            LoanApplication formerApplication = _loanRepository.Fetch(ticketId);

            return(JsonSerialiser.ToJson(formerApplication));
        }