// GET: Skapar en sida som listar dokumenten public ActionResult Index() { var model = db.Documents.ToList(); if (User.IsInRole("Elev")) { //var id = new LMS_Lexicon2015.Models.ApplicationDbContext().Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().GroupId; //model = db.Documents.Where(g => g.GroupId == id).ToList(); var id = new LMS_Lexicon2015.Models.ApplicationDbContext().Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Id; model = db.Documents.Where(g => g.UserId == id).ToList(); } return(View(model)); }
// GET: Skapar en lista med användare public ActionResult Index(string sortOrder, string searchString) { ViewBag.FirstNameSortParm = sortOrder == "FirstName" ? "FirstName_desc" : "FirstName"; ViewBag.LastNameSortParm = sortOrder == "LastName" ? "LastName_desc" : "LastName"; ViewBag.RolesSortParm = sortOrder == "Roles" ? "Roles_desc" : "Roles"; ViewBag.GroupSortParm = sortOrder == "Group" ? "Group_desc" : "Group"; ViewBag.EmailSortParm = sortOrder == "Email" ? "Email_desc" : "Email"; ViewBag.PhoneNumberSortParm = sortOrder == "PhoneNumber" ? "PhoneNumber_desc" : "PhoneNumber"; ViewBag.searchString = searchString; var Users = from s in db.Users select s; if (!String.IsNullOrEmpty(searchString)) { Users = Users.Where(s => s.FirstName.Contains(searchString) || s.LastName.Contains(searchString) || (s.FirstName + " " + s.LastName).Contains(searchString) //|| s.Roles.FirstOrDefault().RoleId.Contains(searchString) //|| ((s.Roles.FirstOrDefault().RoleId).ToString().(string).Name).Contains(searchString) //|| s.Group.Name.Contains(searchString) //|| s.Email.Contains(searchString) //|| s.PhoneNumber.Contains(searchString) ); } switch (sortOrder) { case "FirstName_desc": Users = Users.OrderByDescending(s => s.FirstName); break; case "FirstName": Users = Users.OrderBy(s => s.FirstName); break; case "LastName_desc": Users = Users.OrderByDescending(s => s.LastName); break; case "LastName": Users = Users.OrderBy(s => s.LastName); break; case "Roles_desc": Users = Users.OrderByDescending(s => s.Roles.FirstOrDefault().RoleId); break; case "Roles": Users = Users.OrderBy(s => s.Roles.FirstOrDefault().RoleId); break; case "Group_desc": Users = Users.OrderByDescending(s => s.Group.Name); break; case "Group": Users = Users.OrderBy(s => s.Group.Name); break; case "Email_desc": Users = Users.OrderByDescending(s => s.Email); break; case "Email": Users = Users.OrderBy(s => s.Email); break; case "PhoneNumber_desc": Users = Users.OrderByDescending(s => s.PhoneNumber); break; case "PhoneNumber": Users = Users.OrderBy(s => s.PhoneNumber); break; default: Users = Users.OrderByDescending(s => s.LastName); break; } var checkBox = Request.Form["ActiveChoise"]; var applicationUsers = Users; if (checkBox == "on") { applicationUsers = Users.Where(o => o.Group.EndDate > DateTime.Today && o.Group.StartDate < DateTime.Today); } if (User.IsInRole("Elev")) { var id = new LMS_Lexicon2015.Models.ApplicationDbContext().Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().GroupId; applicationUsers = applicationUsers.Where(g => g.GroupId == id); } ViewBag.Roles = db.Roles.ToList(); FromPartitialView = false; //var model = Users.Select(r => new UserListViewModel var model = applicationUsers.Select(r => new UserListViewModel { Id = r.Id, FirstName = r.FirstName, LastName = r.LastName, Email = r.Email, Role = db.Roles.Where(R => R.Id == r.Roles.FirstOrDefault().RoleId).FirstOrDefault().Name, Group = db.Groups.Where(G => G.Id == r.GroupId).FirstOrDefault().Name, GroupId = db.Groups.Where(G => G.Id == r.GroupId).FirstOrDefault().Id, PhoneNumber = r.PhoneNumber }).ToList(); return View(model); }
// GET: Skapar en sida med alla grupper public ActionResult Index(string sortOrder, string searchString) { { var groupIdInMenu = new LMS_Lexicon2015.Models.ApplicationDbContext().Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().GroupId; var studentIdWithPath = "Details/" + groupIdInMenu; ViewBag.OptionsDropDown = new SelectList(new[] { "Alla kurser", "Aktiva kurser" }); if (User.IsInRole("Elev")) { return RedirectToAction("Details/" + groupIdInMenu); } ViewBag.NameSortParm = sortOrder == "Name" ? "Name_desc" : "Name"; ViewBag.DescriptionSortParm = sortOrder == "Description" ? "Description_desc" : "Description"; ViewBag.StartDateSortParm = sortOrder == "StartDate" ? "StartDate_desc" : "StartDate"; ViewBag.EndDateSortParm = sortOrder == "EndDate" ? "EndDate_desc" : "EndDate"; ViewBag.searchString = searchString; LMS_Lexicon2015.Controllers.HomeController.HomeIndex = false; var Groups = from s in db.Groups select s; if (!String.IsNullOrEmpty(searchString)) { Groups = Groups.Where(s => s.Name.Contains(searchString) //|| (s.EndDate.ToString()).Contains(searchString) //|| (s.StartDate.ToString()).Contains(searchString) //|| s.Description.Contains(searchString) ); } switch (sortOrder) { case "Name_desc": Groups = Groups.OrderByDescending(s => s.Name); break; case "Name": Groups = Groups.OrderBy(s => s.Name); break; case "Description_desc": Groups = Groups.OrderByDescending(s => s.Description); break; case "Description": Groups = Groups.OrderBy(s => s.Description); break; case "StartDate_desc": Groups = Groups.OrderByDescending(s => s.StartDate); break; case "StartDate": Groups = Groups.OrderBy(s => s.StartDate); break; case "EndDate_desc": Groups = Groups.OrderByDescending(s => s.EndDate); break; case "EndDate": Groups = Groups.OrderBy(s => s.EndDate); break; default: Groups = Groups.OrderByDescending(s => s.Name); break; } var checkBox = Request.Form["ActiveChoise"]; if (checkBox == "on") { Groups = Groups.Where(o => o.EndDate > DateTime.Today && o.StartDate < DateTime.Today); } return View(Groups.ToList()); } }
// GET: Skapar en lista med användare public ActionResult Index(string sortOrder, string searchString) { ViewBag.FirstNameSortParm = sortOrder == "FirstName" ? "FirstName_desc" : "FirstName"; ViewBag.LastNameSortParm = sortOrder == "LastName" ? "LastName_desc" : "LastName"; ViewBag.RolesSortParm = sortOrder == "Roles" ? "Roles_desc" : "Roles"; ViewBag.GroupSortParm = sortOrder == "Group" ? "Group_desc" : "Group"; ViewBag.EmailSortParm = sortOrder == "Email" ? "Email_desc" : "Email"; ViewBag.PhoneNumberSortParm = sortOrder == "PhoneNumber" ? "PhoneNumber_desc" : "PhoneNumber"; ViewBag.searchString = searchString; var Users = from s in db.Users select s; if (!String.IsNullOrEmpty(searchString)) { Users = Users.Where(s => s.FirstName.Contains(searchString) || s.LastName.Contains(searchString) || (s.FirstName + " " + s.LastName).Contains(searchString) //|| s.Roles.FirstOrDefault().RoleId.Contains(searchString) //|| ((s.Roles.FirstOrDefault().RoleId).ToString().(string).Name).Contains(searchString) //|| s.Group.Name.Contains(searchString) //|| s.Email.Contains(searchString) //|| s.PhoneNumber.Contains(searchString) ); } switch (sortOrder) { case "FirstName_desc": Users = Users.OrderByDescending(s => s.FirstName); break; case "FirstName": Users = Users.OrderBy(s => s.FirstName); break; case "LastName_desc": Users = Users.OrderByDescending(s => s.LastName); break; case "LastName": Users = Users.OrderBy(s => s.LastName); break; case "Roles_desc": Users = Users.OrderByDescending(s => s.Roles.FirstOrDefault().RoleId); break; case "Roles": Users = Users.OrderBy(s => s.Roles.FirstOrDefault().RoleId); break; case "Group_desc": Users = Users.OrderByDescending(s => s.Group.Name); break; case "Group": Users = Users.OrderBy(s => s.Group.Name); break; case "Email_desc": Users = Users.OrderByDescending(s => s.Email); break; case "Email": Users = Users.OrderBy(s => s.Email); break; case "PhoneNumber_desc": Users = Users.OrderByDescending(s => s.PhoneNumber); break; case "PhoneNumber": Users = Users.OrderBy(s => s.PhoneNumber); break; default: Users = Users.OrderByDescending(s => s.LastName); break; } var checkBox = Request.Form["ActiveChoise"]; var applicationUsers = Users; if (checkBox == "on") { applicationUsers = Users.Where(o => o.Group.EndDate > DateTime.Today && o.Group.StartDate < DateTime.Today); } if (User.IsInRole("Elev")) { var id = new LMS_Lexicon2015.Models.ApplicationDbContext().Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().GroupId; applicationUsers = applicationUsers.Where(g => g.GroupId == id); } ViewBag.Roles = db.Roles.ToList(); FromPartitialView = false; //var model = Users.Select(r => new UserListViewModel var model = applicationUsers.Select(r => new UserListViewModel { Id = r.Id, FirstName = r.FirstName, LastName = r.LastName, Email = r.Email, Role = db.Roles.Where(R => R.Id == r.Roles.FirstOrDefault().RoleId).FirstOrDefault().Name, Group = db.Groups.Where(G => G.Id == r.GroupId).FirstOrDefault().Name, GroupId = db.Groups.Where(G => G.Id == r.GroupId).FirstOrDefault().Id, PhoneNumber = r.PhoneNumber }).ToList(); return(View(model)); }
// GET: Skapar en sida som listar dokumenten public ActionResult Index() { var model = db.Documents.ToList(); if (User.IsInRole("Elev")) { //var id = new LMS_Lexicon2015.Models.ApplicationDbContext().Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().GroupId; //model = db.Documents.Where(g => g.GroupId == id).ToList(); var id = new LMS_Lexicon2015.Models.ApplicationDbContext().Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().Id; model = db.Documents.Where(g => g.UserId == id).ToList(); } return View(model); }
// GET: Skapar en sida med alla grupper public ActionResult Index(string sortOrder, string searchString) { { var groupIdInMenu = new LMS_Lexicon2015.Models.ApplicationDbContext().Users.Where(u => u.Email == User.Identity.Name).FirstOrDefault().GroupId; var studentIdWithPath = "Details/" + groupIdInMenu; ViewBag.OptionsDropDown = new SelectList(new[] { "Alla kurser", "Aktiva kurser" }); if (User.IsInRole("Elev")) { return(RedirectToAction("Details/" + groupIdInMenu)); } ViewBag.NameSortParm = sortOrder == "Name" ? "Name_desc" : "Name"; ViewBag.DescriptionSortParm = sortOrder == "Description" ? "Description_desc" : "Description"; ViewBag.StartDateSortParm = sortOrder == "StartDate" ? "StartDate_desc" : "StartDate"; ViewBag.EndDateSortParm = sortOrder == "EndDate" ? "EndDate_desc" : "EndDate"; ViewBag.searchString = searchString; LMS_Lexicon2015.Controllers.HomeController.HomeIndex = false; var Groups = from s in db.Groups select s; if (!String.IsNullOrEmpty(searchString)) { Groups = Groups.Where(s => s.Name.Contains(searchString) //|| (s.EndDate.ToString()).Contains(searchString) //|| (s.StartDate.ToString()).Contains(searchString) //|| s.Description.Contains(searchString) ); } switch (sortOrder) { case "Name_desc": Groups = Groups.OrderByDescending(s => s.Name); break; case "Name": Groups = Groups.OrderBy(s => s.Name); break; case "Description_desc": Groups = Groups.OrderByDescending(s => s.Description); break; case "Description": Groups = Groups.OrderBy(s => s.Description); break; case "StartDate_desc": Groups = Groups.OrderByDescending(s => s.StartDate); break; case "StartDate": Groups = Groups.OrderBy(s => s.StartDate); break; case "EndDate_desc": Groups = Groups.OrderByDescending(s => s.EndDate); break; case "EndDate": Groups = Groups.OrderBy(s => s.EndDate); break; default: Groups = Groups.OrderByDescending(s => s.Name); break; } var checkBox = Request.Form["ActiveChoise"]; if (checkBox == "on") { Groups = Groups.Where(o => o.EndDate > DateTime.Today && o.StartDate < DateTime.Today); } return(View(Groups.ToList())); } }