/// <summary> /// GET: /User/ /// </summary> /// <returns></returns> public ActionResult Index() { if (Session["usertype"] != null) // If some user is logged in { if (Session["usertype"].ToString() == "Admin") { return(View(LetsShopImplementation.GetAllUsers())); } else { return(RedirectToAction("Index", "Home")); } } else { return(RedirectToAction("Index", "Home")); } }
//______________________________________________________________________________________ /// <summary> /// GET: /User/ExportAllUsers [Exports all users to an Excel File] /// </summary> /// <returns></returns> public ActionResult ExportAllUsers() { try { GridView gv = new GridView(); gv.DataSource = LetsShopImplementation.GetAllUsers(); gv.DataBind(); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=RegisteredUsers.xls"); Response.ContentType = "application/excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gv.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } catch (Exception) { return(RedirectToAction("ErrorPage", "Product")); } return(View("Index")); }