private SelectList GetProtopopiatesForDropdown() { var loggedUserId = this.User.Identity.GetUserId(); var loggedUser = this.Data .Users .Find(loggedUserId); SelectList selectedListProtopopiates; List<DropdownMenuViewModel> protopopiates; if (loggedUser.IsAdmin) { protopopiates = this.Data.Protopopiates .All() .Select(p => new DropdownMenuViewModel { Id = p.ProtopopiateId, Name = p.Denumire }) .ToList(); var defaultDropdownValue = new DropdownMenuViewModel() { Id = -1, Name = "All" }; protopopiates.Add(defaultDropdownValue); } else { protopopiates = this.Data.Protopopiates .All() .Where(p => p.ProtopopiateId == loggedUser.ProtopopiateId) .Select(p => new DropdownMenuViewModel { Id = p.ProtopopiateId, Name = p.Denumire }) .ToList(); } var orderedProtopopiates = protopopiates.OrderBy(p => p.Id != -1).ThenBy(p => p.Name).ToList(); selectedListProtopopiates = new SelectList(orderedProtopopiates, "Id", "Name"); return selectedListProtopopiates; }
public ActionResult GetParohiisDependsOnPropopiateId(int protopopiateId) { if (protopopiateId == -1) { var list = new List<DropdownMenuViewModel>(); var defaultDropdownValue = new DropdownMenuViewModel() { Id = -1, Name = "All" }; list.Add(defaultDropdownValue); var emptyDropdownValue = new DropdownMenuViewModel() { Id = 0, Name = "" }; list.Add(emptyDropdownValue); var orderedList = list.OrderBy(p => p.Id != -1).ThenBy(p => p.Name).ToList(); return Json(orderedList, JsonRequestBehavior.AllowGet); } else { var parohiis = this.Data.Parohiis .All() .Where(p => p.ProtopopiateId == protopopiateId) .Select(p => new DropdownMenuViewModel() { Id = p.Cif, Name = p.Denumire }) .ToList(); var defaultDropdownValue = new DropdownMenuViewModel() { Id = -1, Name = "All" }; parohiis.Add(defaultDropdownValue); var orderedParohiis = parohiis.OrderBy(p => p.Id != -1).ThenBy(p => p.Name).ToList(); return Json(orderedParohiis, JsonRequestBehavior.AllowGet); } }