// GET: ManageDiplomas public ActionResult Index(string sortOrder, string currentFilter, string searchString, int? page) { this.ViewBag.CurrentSort = sortOrder; this.ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : string.Empty; this.ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } this.ViewBag.CurrentFilter = searchString; //var teacher = this.teachers.GetByUserId(this.User.Identity.GetUserId()).FirstOrDefault(); var diplomas = this.diplomas.GetAll().Where(d => d.IsApprovedByLeader) .To<CommonDiplomaViewModel>(); if (!string.IsNullOrEmpty(searchString)) { if (searchString.ToLower() == "одобрени") { diplomas = diplomas.Where(d => d.IsApprovedByLeader || d.IsApprovedByHead); } else if (searchString.ToLower() == "избрани") { diplomas = diplomas.Where(d => d.IsSelectedByStudent); } else { diplomas = diplomas.Where(s => s.Title.Contains(searchString) || s.Description.Contains(searchString)); } } if (diplomas.LongCount() <= 0) { this.TempData["Message"] = "Не са намерени дипломи!"; } else { switch (sortOrder) { case "name_desc": diplomas = diplomas.OrderByDescending(s => s.Title); break; case "Date": diplomas = diplomas.OrderBy(s => s.CreatedOn); break; case "date_desc": diplomas = diplomas.OrderByDescending(s => s.CreatedOn); break; default: // Title ascending diplomas = diplomas.OrderBy(s => s.Title); break; } } int pageSize = 5; int pageNumber = page ?? 1; return this.View(diplomas.ToPagedList(pageNumber, pageSize)); }
/// <summary> /// Done /// </summary> /// <param name="id">Id of the tag</param> /// <param name="teacherId">Id of the teacher</param> /// <param name="sortOrder">Order to be used for sorting</param> /// <param name="currentFilter">Filter</param> /// <param name="searchString">Searching string</param> /// <param name="page">Page that we are at</param> /// <returns>Returns diplomas by tag</returns> public ActionResult Tag(int? id, int? teacherId, string sortOrder, string currentFilter, string searchString, int? page) { if (id == null) { return this.RedirectToAction("Diplomas"); } this.ViewBag.CurrentSort = sortOrder; this.ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : string.Empty; this.ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } this.ViewBag.CurrentFilter = searchString; int intId = id ?? 0; var tag = this.tags.GetObjectById(intId); var diplomas = this.diplomas.GetAll() .Where(d => !d.IsSelectedByStudent && (d.TeacherID == teacherId || teacherId == null)) .To<CommonDiplomaViewModel>() .ToList() .Where(d => d.Tags.Contains(tag)); if (!string.IsNullOrEmpty(searchString)) { diplomas = diplomas.Where(s => s.Title.Contains(searchString) || s.Description.Contains(searchString)); } if (diplomas.LongCount() <= 0) { this.TempData["DiplomasNotFound"] = "Не са намерени дипломи!"; } else { switch (sortOrder) { case "name_desc": diplomas = diplomas.OrderByDescending(s => s.Title); break; case "Date": diplomas = diplomas.OrderBy(s => s.CreatedOn); break; case "date_desc": diplomas = diplomas.OrderByDescending(s => s.CreatedOn); break; default: // Title ascending diplomas = diplomas.OrderBy(s => s.Title); break; } } int pageSize = GlobalConstants.PageSize; int pageNumber = page ?? 1; return this.View(diplomas.ToPagedList(pageNumber, pageSize)); }
// GET: Deleted public ActionResult Deleted(string sortOrder, string currentFilter, string searchString, int? page) { this.ViewBag.CurrentSort = sortOrder; this.ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name_desc" : string.Empty; this.ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } this.ViewBag.CurrentFilter = searchString; var teacher = this.teachers.GetByUserId(this.User.Identity.GetUserId()).FirstOrDefault(); var diplomas = this.diplomas.GetDeleted() .Where(x => x.Teacher.Id == teacher.Id) .To<CommonDiplomaViewModel>(); if (!string.IsNullOrEmpty(searchString)) { diplomas = diplomas.Where(s => s.Title.Contains(searchString) || s.Description.Contains(searchString)); } if (diplomas.LongCount() <= 0) { this.TempData["Message"] = "Няма намерени дипломи!"; this.TempData["NotFound"] = true; } else { switch (sortOrder) { case "name_desc": diplomas = diplomas.OrderByDescending(s => s.Title); break; case "Date": diplomas = diplomas.OrderBy(s => s.CreatedOn); break; case "date_desc": diplomas = diplomas.OrderByDescending(s => s.CreatedOn); break; default: // Title ascending diplomas = diplomas.OrderBy(s => s.Title); break; } } int pageSize = 5; int pageNumber = page ?? 1; return this.View(diplomas.ToPagedList(pageNumber, pageSize)); }