public JsonResult FinalizeOrder(OrderViewModel orderViewModel) { Order order = new Order(); try { orderViewModel.IdLoggedUser = base.IdLoggedUser; order = orderService.PopulateModel(orderViewModel); order.IdAddress = addressService.SaveOrEditAddress(orderViewModel.Address, base.IdLoggedUser); order.OrderItens = orderService.GetOrderItens(order); var promoCode = promoCodeRepository.FindFirstBy(c => c.Code == orderViewModel.PromoCode); if (promoCode != null) { order.IdPromoCode = promoCode.Id; } if (!stockService.CheckStock(order)) { basketService.InativeAllBy(order.IdUser); return(Json(new { success = false, message = Infrastructure.Resources.CartResource.ErrorStock })); } var url = orderService.Finalize(order); return(Json(new { success = true, idOrder = order.Id, url = url })); } catch (System.Exception) { return(Json(new { success = false, message = Infrastructure.Resources.CartResource.ErrorFinalize })); } }