public ActionResult Index() { //Check cookie and session variables for retaining login status //if true go to page, else return to login page if (HttpHandler.CheckSession()) { string username = Session["Username"].ToString(); string userType = UserModels.GetUserType(username); string thumbnailPhoto = UserModels.GetThumbnailPhoto(username); try { HttpContext.Session.Add("ThumbnailPhoto", thumbnailPhoto); HttpContext.Session.Add("Name", Request.Cookies["Name"].Value.ToString()); HttpContext.Session.Add("Position", Request.Cookies["Position"].Value.ToString()); HttpContext.Session.Add("EmployeeNumber", Request.Cookies["EmployeeNumber"].Value.ToString()); } catch { } //get the module var modName = "User"; var module = ModuleModels.getModule(modName); ViewBag.Title = "Cell Controller"; bool check = false; if (module != null) { //generate the menus ViewBag.Menu = custom_helper.GenerateMenu(module.Id, module.ParentId, userType); ViewBag.PageHeader = module.ParentName + " / " + module.Name; ViewBag.Breadcrumbs = module.Name; check = true; } else { check = false; } //check access for module, if no access redirect to error page if (ModuleModels.checkAccessForURL(userType, module.Id) && check) { try { Session.Remove("ModuleErrorHeader"); Session.Remove("ModuleErrorBreadCrumbs"); } catch { } return(View()); } else { Session.Add("ModuleErrorHeader", ViewBag.PageHeader); Session.Add("ModuleErrorBreadCrumbs", ViewBag.Breadcrumbs); return(RedirectToAction("Index", "Error")); } } else { return(RedirectToAction("Login", "Account")); } }
public ActionResult Index() { //Check cookie and session variables for retaining login status //if true go to page, else return to login page if (HttpHandler.CheckSession()) { string username = Session["Username"].ToString(); string userType = UserModels.GetUserType(username); string thumbnailPhoto = UserModels.GetThumbnailPhoto(username); try { HttpContext.Session.Add("ThumbnailPhoto", thumbnailPhoto); HttpContext.Session.Add("Name", Request.Cookies["Name"].Value.ToString()); HttpContext.Session.Add("Position", Request.Cookies["Position"].Value.ToString()); HttpContext.Session.Add("EmployeeNumber", Request.Cookies["EmployeeNumber"].Value.ToString()); } catch { } //get the enrolled equipments of the user var enrolledEquipments = HttpHandler.GetEnrolledEquipments(username); int count = 0; try { count = enrolledEquipments.Count; } catch { count = 0; } //loop the equipments and create cookie string equipments = ""; if (count > 0) { foreach (var x in enrolledEquipments) { equipments += x.Equipment + ","; } equipments += ")"; equipments = equipments.Replace(",)", ""); } try { HttpContext.Session.Add("Equipments", equipments); HttpCookie cookieEquipments = new HttpCookie("Equipments"); cookieEquipments.Value = equipments; DateTime now = DateTime.Now; cookieEquipments.Expires = now.AddDays(30); Response.Cookies.Add(cookieEquipments); } catch { } //get the module var modName = "Home"; var module = ModuleModels.getModule(modName); ViewBag.Title = "Cell Controller"; bool check = false; if (module != null) { //generate the menus ViewBag.Menu = custom_helper.GenerateMenu(module.Id, module.ParentId, userType); check = true; //ViewBag.PageHeader = modName + " / " + "Enrolled Machines"; ViewBag.PageHeader = modName; ViewBag.Breadcrumbs = "Enrolled Machines"; } //check access for module, if no access redirect to error page if (ModuleModels.checkAccessForURL(userType, module.Id) && check) { try { Session.Remove("ModuleErrorHeader"); Session.Remove("ModuleErrorBreadCrumbs"); } catch { } return(View(enrolledEquipments)); } else { Session.Add("ModuleErrorHeader", ViewBag.PageHeader); Session.Add("ModuleErrorBreadCrumbs", ViewBag.Breadcrumbs); return(RedirectToAction("Index", "Error")); } } else { return(RedirectToAction("Login", "Account")); } }