예제 #1
0
        public HttpResponseMessage Post(TransactionModelCadastro model)
        {
            try
            {
                Client c    = appClient.ObterPorId(model.IdClient);
                Card   card = appCard.ObterPorId(model.IdCard);

                Transaction t = new Transaction()
                {
                    Amount   = model.Amount,
                    Type     = model.Type,
                    Number   = model.Number,
                    IdClient = model.IdClient,
                    IdCard   = model.IdCard
                };

                appTransaction.Cadastrar(t, card, c.Limit);

                return(Request.CreateResponse(HttpStatusCode.OK, "Transação aprovada."));
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
            }
        }
        public HttpResponseMessage GetValue(int id)
        {
            try
            {
                Client c = appClient.ObterPorId(id);

                if (c != null)
                {
                    ClientModelConsulta model = new ClientModelConsulta()
                    {
                        IdClient = c.IdClient,
                        Name     = c.Name,
                        Limit    = c.Limit
                    };

                    return(Request.CreateResponse(HttpStatusCode.OK, model));
                }
                else
                {
                    throw new Exception("Cliente não encontrado.");
                }
            }
            catch (Exception e)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
            }
        }