public async Task<ActionResult> SaveAssignment(AssignmentDetailsViewModel model) { if (model.CategoryIds.Count == 0) { ModelState.AddModelError("CategoryIds", "You must select at least one Category for this Assignment."); return BadRequest(ModelState); } else { if (string.IsNullOrEmpty(model.Id)) { var assignment = model.CloneToAssignment(); assignment.CreatedBy = _userContext.UserId; await _assignmentManager.InsertAssignmentAsync(assignment, model.CategoryIds, model.ConnectionGroupIds); model.Id = assignment.Id; model.CreatedUTC = assignment.CreatedUTC; } else { var assignment = model.CloneToAssignment(); await _assignmentManager.UpdateAssignmentAsync(assignment, model.CategoryIds, model.ConnectionGroupIds); } return Ok(model); } }
public ActionResult Details(int id) { Course course = _GetCourse(); if (course == null) { return(RedirectToAction("SelectCourse")); } Assignment assignment = course.Assignments.FirstOrDefault(a => a.AssignmentId == id); if (assignment == null) { return(new HttpNotFoundResult()); } ApplicationUser user = ApplicationUser.Current; AssignmentDetailsViewModel vm = new AssignmentDetailsViewModel(); vm.User = user; vm.Course = course; vm.Assignment = assignment; vm.Submissions = _db.StudentSubmissions .Where(s => s.StudentAssignment.AssignmentId == id) .Where(s => s.StudentAssignment.Enrollment.UserId == user.Id) .OrderBy(s => s.DateCreated) .ToList(); return(View(vm)); }
public IActionResult New() { var model = new AssignmentDetailsViewModel { SquadList = GetSquadList() }; return(View("Create", model)); }
private IActionResult PromptForSubmission(AssignmentDetailsViewModel model) { model.SquadList = GetSquadList(); model.SelectedPlayerList = GetSelectedPlayerList(model.Players); model.SelectedTrainingMaterialList = GetSelectedTrainingMaterialList(model.TrainingMaterials); return(View("Create", model)); }
private async Task LoadCategoriesAsync(AssignmentDetailsViewModel model, string assignmentId) { var categories = await _assignmentManager.GetCategoriesAssignedToAssignmentAsync(assignmentId); foreach (var cat in categories) { model.Categories.Add(cat); model.CategoryIds.Add(cat.Id); } }
private async Task LoadUserGroupsAsync(AssignmentDetailsViewModel model, string assignmentId) { var userGroups = await _assignmentManager.GetUserGroupsAssignedToAssignmentAsync(assignmentId); foreach (var ug in userGroups) { if (ug.UserGroupType == UserGroupType.ConnectionGroup) { model.ConnectionGroups.Add(ug); } } }
public IActionResult New(AssignmentDetailsViewModel model) { if (!ModelState.IsValid) { return(PromptForSubmission(model)); } else if (model.AssignedTo == AssignedTo.IndividualPlayers && (model.Players == null || model.Players.Count() == 0)) { ModelState.AddModelError("", "Please specify which players this is assigned to"); return(PromptForSubmission(model)); } else if (model.AssignedTo == AssignedTo.SelectedSquads && (model.Squads == null || model.Squads.Count() == 0)) { ModelState.AddModelError("", "Please specify which squads this is assigned to"); return(PromptForSubmission(model)); } var email = User.Identity.Name; var members = memberQuery.GetMembersByEmail(club.Guid, email); var coach = members?.FirstOrDefault(m => m.Membership == Membership.Coach); if (coach == null) { ModelState.AddModelError("", "Coach could not be resolved"); PromptForSubmission(model); } var response = assignmentService.CreateAssignment(new AssignmentRequest { Title = model.Title, ClubId = club.Guid, CoachId = coach.Guid, DueDate = model.DueDate, Instructions = model.Instructions, Players = model.AssignedTo == AssignedTo.IndividualPlayers ? model.Players : null, Squads = model.AssignedTo == AssignedTo.SelectedSquads ? model.Squads : null, TrainingMaterials = model.TrainingMaterials, AssignedTo = model.AssignedTo.Value }); if (!response.RequestIsFulfilled) { foreach (var error in response.Errors) { ModelState.AddModelError("", error); } PromptForSubmission(model); return(View("Create", model)); } return(RedirectToAction(nameof(Index))); }
public ActionResult Details(int id) { var service = new AssignmentService(new AssignmentRepository()); var detailsDto = service.GetDetails(id); var viewModel = new AssignmentDetailsViewModel { DaysLeft = detailsDto.DaysLeft, DueDate = detailsDto.DueDate }; return(View(viewModel)); }
public static Assignment CloneToAssignment(this AssignmentDetailsViewModel source) { var model = new Assignment(); model.Id = source.Id; model.OwnerId = source.OwnerId; model.OwnerLevel = source.OwnerLevel; model.CreatedBy = source.CreatedBy; model.CreatedUTC = source.CreatedUTC; model.Title = source.Title; model.AssignmentBody = source.AssignmentBody; model.Status = source.Status; model.AllowComments = source.AllowComments; model.NotificationId = source.NotificationId; model.SendNotification = source.SendNotification; model.TimeZoneId = source.TimeZoneId; model.DueUTC = TimeZoneHelper.ConvertToUTC(source.DueDT, source.TimeZoneId); return(model); }
public async Task <IViewComponentResult> InvokeAsync(string id, string ownerLevel, string ownerId, string categoryId) { if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(ownerLevel)) { return(new ViewComponentPlaceholder()); } ViewData["ownerLevel"] = ownerLevel ?? string.Empty; ViewData["ownerId"] = ownerId ?? string.Empty; ViewData["TimeZoneList"] = TimeZoneHelper.GetTimeZoneSelectList(); AssignmentDetailsViewModel model; if (string.IsNullOrEmpty(id)) { // Create new assignment model = new AssignmentDetailsViewModel() { Id = string.Empty, OwnerLevel = (OwnerLevel)Enum.Parse(typeof(OwnerLevel), ownerLevel), OwnerId = ownerId, Status = AssignmentStatus.Draft, DueDT = DateTime.Now.AddDays(3), TimeZoneId = TimeZoneHelper.DefaultTimeZoneId, TimeZoneName = TimeZoneHelper.NameOfTimeZoneId(TimeZoneHelper.DefaultTimeZoneId), AllowComments = false, SendNotification = false }; if (!string.IsNullOrEmpty(categoryId)) { var category = await _assignmentManager.GetCategoryAsync(categoryId); if (category != null) { model.Categories.Add(category); model.CategoryIds.Add(categoryId); } } return(View("AssignmentDetailsCreate", model)); } else { // Load existing assignment var note = await _assignmentManager.GetAssignmentAsync(id); if (note == null) { return(new ViewComponentPlaceholder()); } model = note.CloneToAssignmentDetailsViewModel(); if (string.IsNullOrEmpty(model.TimeZoneId)) { model.TimeZoneId = TimeZoneHelper.DefaultTimeZoneId; // TO DO: Get the default time zone from the user context. model.DueDT = TimeZoneHelper.Now(model.TimeZoneId); } model.TimeZoneName = TimeZoneHelper.NameOfTimeZoneId(model.TimeZoneId); await LoadCategoriesAsync(model, id); await LoadUserGroupsAsync(model, id); if (note.Status == AssignmentStatus.Draft) { return(View("AssignmentDetailsEdit", model)); } else { return(View("AssignmentDetailsView", model)); } } }
private async Task LoadCategoriesAsync(AssignmentDetailsViewModel model, string id) { model.Categories = await _assignmentManager.GetCategoriesAssignedToAssignmentAsync(id); }
public ActionResult Index(int assignmentId) { if (ActiveCourseUser == null) //user is not logged in { return(RedirectToRoute(new { controller = "Home", action = "Index", area = "" })); } ViewBag.HideMail = ActiveCourseUser != null?DBHelper.GetAbstractCourseHideMailValue(ActiveCourseUser.AbstractCourseID) : false; Assignment assignment = db.Assignments.Find(assignmentId); //If the assignment does not exist, or the assignment has not been released and the user is a student: kick them out if (assignment == null || (assignment.ReleaseDate > DateTime.UtcNow && ActiveCourseUser.AbstractRoleID == (int)OSBLE.Models.Courses.CourseRole.CourseRoles.Student)) { return(RedirectToRoute(new { action = "Index", controller = "Assignment", area = "" })); } AssignmentDetailsFactory factory = new AssignmentDetailsFactory(); AssignmentDetailsViewModel viewModel = factory.Bake(assignment, ActiveCourseUser); // E.O.: There can be files associated with an assignment description and solutions. We look // for these now. ViewBag.DescFilesHTML = string.Empty; ViewBag.SoluFilesHTML = string.Empty; if (assignment.CourseID.HasValue) { OSBLE.Models.FileSystem.AssignmentFilePath fs = OSBLE.Models.FileSystem.Directories.GetAssignment( assignment.CourseID.Value, assignmentId); OSBLEDirectory attrFiles = fs.AttributableFiles; OSBLE.Models.FileSystem.FileCollection files = attrFiles.GetFilesWithSystemAttribute("assignment_description", assignmentId.ToString()); if (files.Count > 0) { StringBuilder sb = new StringBuilder("<ul>"); foreach (string fileName in files) { //Check to see if the user is an admin if (CurrentUser.CanCreateCourses == true) { //Build the URL action for deleting //Assignment file deletion is handled different. string UrlAction = Url.Action("DeleteAssignmentFile", "Home", new { courseID = assignment.CourseID.Value, assignmentID = assignment.ID, fileName = System.IO.Path.GetFileName(fileName) }); // Make a link for the file sb.AppendFormat( "<li><a href=\"/Services/CourseFilesOps.ashx?cmd=assignment_file_download" + "&courseID={0}&assignmentID={1}&filename={2}\">{2} </a>" + "<a href=\"" + UrlAction + "\"><img src=\"/Content/images/delete_up.png\" alt=\"Delete Button\"></img></a>" + "</li>", assignment.CourseID.Value, assignment.ID, System.IO.Path.GetFileName(fileName)); } else { sb.AppendFormat( "<li><a href=\"/Services/CourseFilesOps.ashx?cmd=assignment_file_download" + "&courseID={0}&assignmentID={1}&filename={2}\">{2}</li>", assignment.CourseID.Value, assignment.ID, System.IO.Path.GetFileName(fileName)); } } sb.Append("</ul>"); ViewBag.DescFilesHTML = sb.ToString(); } //Check for solution files and if they exist create a string to send to the assignment details attrFiles = fs.AttributableFiles; files = attrFiles.GetFilesWithSystemAttribute("assignment_solution", assignmentId.ToString()); //Check active course user ///////////////////////// // This is checking hard coded AbstractCourseID values, // needs to check if the User is enrolled in the current course ID // this will cause errors in the future, noted for now ////////////////////////// //if (files.Count > 0 && (ActiveCourseUser.AbstractCourseID == 1 ||ActiveCourseUser.AbstractCourseID == 2 || // ActiveCourseUser.AbstractCourseID == 3 || ActiveCourseUser.AbstractCourseID == 5)) if (currentCourses.Contains(ActiveCourseUser)) { bool pastCourseDueDate = DBHelper.AssignmentDueDatePast(assignmentId, ActiveCourseUser.AbstractCourseID); DateTime?CourseTimeAfterDueDate = DBHelper.AssignmentDueDateWithLateHoursInCourseTime(assignmentId, ActiveCourseUser.AbstractCourseID); StringBuilder sb; // make sure we don't have an incorrect assignmentId if (CourseTimeAfterDueDate != null) { sb = new StringBuilder("<ul>"); foreach (string fileName in files) { //Check to see if the user can modify the course if (ActiveCourseUser.AbstractRole.CanModify) { //Build the URL action for deleting //Assignment file deletion is handled different. string UrlAction = Url.Action("DeleteAssignmentFile", "Home", new { courseID = assignment.CourseID.Value, assignmentID = assignment.ID, fileName = System.IO.Path.GetFileName(fileName) }); string fName = System.IO.Path.GetFileName(fileName); // Make a link for the file sb.AppendFormat( "<li><a href=\"/Services/CourseFilesOps.ashx?cmd=assignment_file_download" + "&courseID={0}&assignmentID={1}&filename={2}\">{3} </a>" + "<a href=\"" + UrlAction + "\"><img src=\"/Content/images/delete_up.png\" alt=\"Delete Button\"></img></a>" + "</li>", assignment.CourseID.Value, assignment.ID, fName, fName + " (Viewable after " + CourseTimeAfterDueDate + ")"); } else if (!pastCourseDueDate) { sb.AppendFormat( "<li>Viewable after {0}", CourseTimeAfterDueDate); } // past due date, give link to the file else { sb.AppendFormat( "<li><a href=\"/Services/CourseFilesOps.ashx?cmd=assignment_file_download" + "&courseID={0}&assignmentID={1}&filename={2}\">{2}</li>", assignment.CourseID.Value, assignment.ID, System.IO.Path.GetFileName(fileName)); } } sb.Append("</ul>"); ViewBag.SoluFilesHTML = sb.ToString(); } } } //discussion assignments and critical reviews require their own special view if (assignment.Type == AssignmentTypes.TeamEvaluation) { return(View("TeamEvaluationIndex", viewModel)); } else if (assignment.Type == AssignmentTypes.DiscussionAssignment || assignment.Type == AssignmentTypes.CriticalReviewDiscussion) { return(View("DiscussionAssignmentIndex", viewModel)); } //MG&MK: For teamevaluation assignments, assignment details uses the //previous assingment teams for displaying. So, we are forcing //TeamEvaluation assignment to use TeamIndex. else if (assignment.HasTeams || assignment.Type == AssignmentTypes.TeamEvaluation) { return(View("TeamIndex", viewModel)); } else { return(View("Index", viewModel)); } }