Exemplo n.º 1
0
        public ActionResult BuyRoute(BuyRouteParams model)
        {
            var username = User.Identity.Name;

            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid Request"));
            }

            try
            {
                var changeStatusRoute = _routeService.BuyRoute(model, username);
                if (!string.IsNullOrEmpty(changeStatusRoute))
                {
                    return(StatusCode((int)HttpStatusCode.NotAcceptable, changeStatusRoute));
                }
                _paymentService.MakePayment(model.RouteId);
                _sendGridService.SendEmailReceiptForBuyer(model.RouteId);
                return(Ok());
            }
            catch (Exception ex)
            {
                //return BadRequest(ex.GetRootException().Message);
                return(StatusCode((int)HttpStatusCode.NotAcceptable, ex.Message));
            }
        }