public ActionResult Index(int?id) { //grab all submissions if you're a teacher //grab your submissions if your groups submissions if you're a student if (id == null) { return(RedirectToAction("Index", "Home")); } account currentUser = accountHelp.getCurrentUser(Session["User"].ToString()); int userId = currentUser.id; ViewBag.userName = currentUser.name; ViewBag.imagePath = currentUser.imagePath; List <submission> subs; if (currentUser.roleId > 1) { subs = db.submission.Where(s => s.problemId == id).ToList(); } else { int problId = Convert.ToInt32(id); subs = subServ.GetSubmissionsOfUserOfProblem(currentUser.id, problId); } SubmissionsViewModel viewModel = new SubmissionsViewModel { submissions = subs, ideOne = new Utilites.IdeOne() }; return(View(viewModel)); }
public async Task <IActionResult> Submissions(string DisplayText = "", int?page = null) { SubmissionsViewModel model = new SubmissionsViewModel(); var query = _session.Query <ContentItem, ContentItemIndex>(); if (DisplayText == null) { DisplayText = string.Empty; } var pageOfContentItems = await query.Where(o => o.DisplayText.Contains(DisplayText) && o.ContentType == "AdvancedFormSubmissions" && (o.Latest || o.Published)).OrderByDescending(o => o.CreatedUtc).ListAsync(); var contentItemSummaries = new List <dynamic>(); List <string> roles; var currentUserRoles = ((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == ClaimTypes.Role).Select(c => c.Value).ToList(); foreach (var contentItem in pageOfContentItems) { var contentItemId = await _contentAliasManager.GetContentItemIdAsync("slug:AdvancedForms/" + contentItem.Content.AdvancedFormSubmissions.Title.ToString().Replace(" ", "-")); if (contentItemId == null) { contentItemId = await _contentAliasManager.GetContentItemIdAsync("slug:AdvancedForms/" + contentItem.DisplayText.ToString().Replace(" ", "-")); } if (contentItemId != null) { var AFcontentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Published); string groups = AFcontentItem.Content.AdvancedForm.Group.Text; roles = groups.Split(",").ToList(); if (currentUserRoles.Any(item => item == "Administrator" || roles.Contains(item))) { contentItemSummaries.Add(contentItem); } } } PagerParameters pagerParameters = new PagerParameters(); pagerParameters.Page = page; var siteSettings = await _siteService.GetSiteSettingsAsync(); var pager = new Pager(pagerParameters, siteSettings.PageSize); var maxPagedCount = siteSettings.MaxPagedCount; if (maxPagedCount > 0 && pager.PageSize > maxPagedCount) { pager.PageSize = maxPagedCount; } var pagerShape = (await New.Pager(pager)).TotalItemCount(maxPagedCount > 0 ? maxPagedCount : contentItemSummaries.Count()); contentItemSummaries = contentItemSummaries.Skip(pager.GetStartIndex()).Take(pager.PageSize).ToList(); model.Pager = pagerShape; model.DisplayText = DisplayText; model.ContentItemSummaries = contentItemSummaries; return(View(model)); }
public ActionResult SubmissionsByGrantCategory(int?amount, int?quarter) { var subsList = new List <Submission>() { new Submission { nameOfCause = "Homeless" }, new Submission { nameOfCause = "food" } }; var user = new AdminUser() { Username = "******", HasAdminRights = true, AdminType = new AdminType() }; //have to initialize the ViewModel var viewModel = new SubmissionsViewModel { Submissions = subsList, User = user }; return(View(viewModel)); }