public ActionResult AssignSession() { var currentUser = _userManager.FindById(User.Identity.GetUserId()); List <RecordingViewModel> recordings = _recordings.GetUnassignedRecordings() .OrderBy(r => r.StartTime) .Select(Mapper.Map <RecordingViewModel>) .ToList(); var assign = new SessionAssigningViewModel(recordings.Select(r => new SelectableRecordingViewModel(r))); assign.ResetProjectSelection(GetProjectSessionSelection(currentUser.Id, User.IsInRole(UserRoles.ADMIN))); return(View(assign)); }
public ActionResult AssignSession(SessionAssigningViewModel assign) { Request.ThrowIfDifferentReferrer(); var currentUser = _userManager.FindById(User.Identity.GetUserId()); if (ModelState.IsValid && assign.Recordings != null && assign.Recordings.Any(r => r.IsSelected)) { var session = _database.Sessions .Where(s => s.Id == assign.SessionId && s.ProjectId == assign.ProjectId) .AsDbQuery() .Include(s => s.Project.Owner) .SingleOrDefault(); if (session != null && (session.Project.Owner.Id == currentUser.Id || User.IsInRole(UserRoles.ADMIN))) { var selectedRecordings = assign.Recordings.Where(r => r.IsSelected); foreach (var recording in selectedRecordings) { _recordings.AssignRecordingToSession(session, recording.NodeName, recording.StartTime); } return(RedirectToAction(nameof(SessionController.Details), SessionController.ControllerName, new { sessionId = assign.SessionId })); } ModelState.AddModelError(nameof(assign.SessionId), "Session was not selected."); } assign.ResetProjectSelection(GetProjectSessionSelection(currentUser.Id, User.IsInRole(UserRoles.ADMIN))); return(View(assign)); }