/// <summary> /// QBO API Request /// </summary> public ActionResult ApiCallService() { if (Session["realmId"] == null) { return(View("ApiCallService", (object)"QBO API call Failed!")); } string realmId = Session["realmId"].ToString(); try { if (User is ClaimsPrincipal principal) { var serviceContext = QboHelper.GetServiceContext(principal, realmId); QboHelper.AddCustomer(serviceContext); var output = QboHelper.GetCompanyInfo(serviceContext); if (output != null) { return(View("ApiCallService", (object)("QBO API call Successful!! Response: " + output))); } } } catch (Exception ex) { return(View("ApiCallService", (object)("QBO API call Failed!" + " Error message: " + ex.Message))); } return(View("ApiCallService", (object)"QBO API call Failed!")); }
public JsonResult AddCustomer(CustomerModel cModel) { object data = new { Status = false, Message = "RealmId not found in session" }; if (Session["realmId"] == null) { return(Json(data, JsonRequestBehavior.AllowGet)); } string realmId = Session["realmId"].ToString(); try { if (!(User is ClaimsPrincipal principal)) { throw new Exception("User principal is empty."); } var serviceContext = QboHelper.GetServiceContext(principal, realmId); var addedCustomer = QboHelper.AddCustomer(serviceContext, cModel); data = new { Status = addedCustomer != null, Message = addedCustomer == null ? "Failed to add customer" : "Customer was added successfully!" }; } catch (Exception ex) { data = new { Status = false, Message = $"Failed to add customer. More details - {ex.Message}" }; } return(Json(data, JsonRequestBehavior.AllowGet)); }