public void Configuration(IAppBuilder app) { string token = GetAccessToken(); // validate token? List <Company> companies = SAAClientAPI.CompaniesGet(); Company firstCompany = null; foreach (Company company in companies) { if (firstCompany == null) { firstCompany = company; // only for sample logon } } // We need to specify a company to use for each subsequent request // For the example we just select the first company from the list, // however you would more likely display a list of companies and allow // the user to select the required company from a list SAAClientAPI.ConnectCompany(firstCompany); string sessionID = Sage.Common.Contexts.SessionContextValues.SessionID; _sessionID = sessionID; }
/// <summary> /// GET: Sites Async /// </summary> /// <returns>View representing Sites</returns> public ActionResult Index() { List <Company> companies = SAAClientAPI.CompaniesGet(); List <Site> sites = new List <Site>(); Company firstCompany = null; foreach (Company company in companies) { Site site = new Site(); site.company_id = company.CompanyNumber; site.company_name = company.CompanyName; sites.Add(site); if (firstCompany == null) { firstCompany = company; // only for sample logon } } // We need to specify a company to use for each subsequent request // For the example we just select the first company from the list, // however you would more likely display a list of companies and allow // the user to select the required company from a list SAAClientAPI.ConnectCompany(firstCompany); string sessionID = Sage.Common.Contexts.SessionContextValues.SessionID; ContextStore.Set(Session, sessionID); return(View(sites)); }
public string FetchCustomer(string sessionID, string reference) { string value = string.Empty; SAAClientAPI.SetSessionContext(sessionID); Customer customer = CustomerFactory.Factory.Fetch(reference); value = "Ref=" + customer.Reference + ", name=" + customer.Name; return(value); }
/// <summary> /// Checks that site ID and company ID are set on the session /// Executed on all controllers with RequiresValidSiteAttribute /// </summary> /// <param name="filterContext">The ActionExecutingContext</param> public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); string returnurl = string.Empty; try { // Set the return URL to the request URL returnurl = filterContext.HttpContext.Request.Url.AbsolutePath; } catch { } HttpRequestBase request = filterContext.HttpContext.Request; try { // Check the site ID and Company ID are set on the session, // if not then redirect to the index page string sessionID = Startup.GetSessionID(); if (string.IsNullOrEmpty(sessionID)) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary( new { controller = "Sites", action = "Index", ReturnUrl = returnurl })); } else { // Use Session to configure SessionContextValues SAAClientAPI.SetSessionContext(sessionID); } } catch (Exception) { { // force re-logon //ContextStore.Reset(filterContext.HttpContext.Session); filterContext.Result = new System.Web.Mvc.HttpUnauthorizedResult(); } } }
private void Connect() { if (_app == null) { _app = new Sage.Accounting.Application(); } if (_company == null) { List <Company> companies = SAAClientAPI.CompaniesGet(); _company = companies.First(); SAAClientAPI.ConnectCompany(_company); } }
/// <summary> /// GET: Sites Async /// </summary> /// <returns>View representing Sites</returns> public ActionResult Index() { List <Company> companies = SAAClientAPI.CompaniesGet(); List <Site> sites = new List <Site>(); foreach (Company company in companies) { Site site = new Site(); site.company_id = company.CompanyNumber; site.company_name = company.CompanyName; sites.Add(site); } return(View(sites)); }
public static string OpenSession(string user, string password, string companyName) { string sessionID = string.Empty; using (ImpersonationScope scope = new ImpersonationScope(user, password)) { SAAClientAPI.Logon(SessionSourceEnum.Web); List <Company> companies = SAAClientAPI.CompaniesGet(); foreach (Company company in companies) { if (string.Compare(company.CompanyName, companyName) == 0) { SAAClientAPI.ConnectCompany(company); sessionID = Sage.Common.Contexts.SessionContextValues.SessionID; break; } } } return(sessionID); }
public static void CloseSession(string sessionID) { SAAClientAPI.SetSessionContext(sessionID); SAAClientAPI.DisconnectCompany(); SAAClientAPI.Logoff(); }