/// <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)); }
/// <summary> /// GET: Sites Async /// </summary> /// <returns>View representing Sites</returns> public async Task <ActionResult> Index() { string json = await GetSitesAsync(); IEnumerable <Site> sites = JsonConvert.DeserializeObject <IEnumerable <Site> >(json); // We need to specify a company to use for each subsequent request // For the example we just select the last 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 Site site = sites.Last <Site>(); // Set the site and company on the session ContextStore.Set(Session, site.site_id, site.company_id.ToString()); return(View(sites)); }