public HttpResponseMessage Get(int id, string simulatedRate = "")
        {
            Agreement          refAgreement;
            AgreementSimulator simAgreement;

            using (var context = new AgreementContext())

            {
                var fullagreements = context.Agreements.Include(agr => agr.CustomerDetails).ToList();
                refAgreement = fullagreements.FirstOrDefault(agr => agr.Id == id);
            }

            if (refAgreement != null)
            {
                if (Request.GetQueryNameValuePairs().Count() == 0)
                {
                    return new HttpResponseMessage()
                           {
                               Content = new ObjectContent <Agreement>(refAgreement,
                                                                       Configuration.Formatters.JsonFormatter)
                           }
                }
                ;
                else
                {
                    if (Agreement.ValidBaseCodeRate(simulatedRate))
                    {
                        simAgreement = new AgreementSimulator(refAgreement, simulatedRate);
                        return(new HttpResponseMessage(HttpStatusCode.Created)
                        {
                            Content = new ObjectContent <AgreementSimulator>(simAgreement,
                                                                             Configuration.Formatters.JsonFormatter)
                        });
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Rate not found"));
                    }
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Agreement not found"));
            }
        }
Exemplo n.º 2
0
 public Handler(AgreementContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }