public CreateEditAssignmentModel(Assignment assignment) { AssignmentId = assignment.AssignmentId; ConsumerKey = assignment.ConsumerKey; ConsumerSecret = assignment.ConsumerSecret; CourseId = assignment.Course.CourseId; CustomParameters = assignment.CustomParameters; Description = assignment.Description; Name = assignment.Name; Url = assignment.Url; }
public ActionResult Create(CreateEditAssignmentModel model) { if (ModelState.IsValid) { var course = ConsumerContext.Courses.Find(model.CourseId); var assignment = new Assignment { ConsumerKey = model.ConsumerKey, ConsumerSecret = model.ConsumerSecret, Course = course, CustomParameters = model.CustomParameters, Description = model.Description, Name = model.Name, Url = model.Url }; ConsumerContext.Assignments.Add(assignment); ConsumerContext.SaveChanges(); return RedirectToAction("Details", "Course", new { id = model.CourseId }); } return View(model); }
/// <summary> /// Create a basic launch request for the assignment. /// </summary> /// <param name="request">The browser request.</param> /// <param name="assignment">The assignment to launch.</param> /// <param name="user">The user that is launching the assignment.</param> /// <returns>An LtiRequestViewModel which can be displayed by the View in such /// a way that the browser will invoke the LTI launch.</returns> public static LtiRequestViewModel CreateBasicLaunchRequestViewModel(HttpRequestBase request, Assignment assignment, ApplicationUser user) { var ltiRequest = new LtiRequest(LtiConstants.BasicLaunchLtiMessageType) { ConsumerKey = assignment.ConsumerKey, ResourceLinkId = assignment.AssignmentId.ToString(CultureInfo.InvariantCulture), Url = new Uri(assignment.Url) }; var course = assignment.Course; // Tool ltiRequest.ToolConsumerInfoProductFamilyCode = Assembly.GetExecutingAssembly().GetName().Name; ltiRequest.ToolConsumerInfoVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); // Context ltiRequest.ContextId = course.CourseId.ToString(CultureInfo.InvariantCulture); ltiRequest.ContextTitle = course.Name; ltiRequest.ContextType = course.EnrolledUsers.Any(u => u.Id == user.Id) ? LisContextType.CourseSection : LisContextType.CourseTemplate; // Instance ltiRequest.ToolConsumerInstanceGuid = "~/".ToAbsoluteUrl(); var title = Assembly.GetExecutingAssembly().GetCustomAttributes<AssemblyTitleAttribute>().FirstOrDefault(); ltiRequest.ToolConsumerInstanceName = title == null ? null : title.Title; ltiRequest.ResourceLinkTitle = assignment.Name; ltiRequest.ResourceLinkDescription = assignment.Description; // User if (user.SendEmail.GetValueOrDefault(true)) { ltiRequest.LisPersonEmailPrimary = user.Email; } if (user.SendName.GetValueOrDefault(true)) { ltiRequest.LisPersonNameFamily = user.LastName; ltiRequest.LisPersonNameGiven = user.FirstName; } ltiRequest.UserId = user.Id; ltiRequest.UserName = user.UserName; ltiRequest.SetRoles(GetLtiRolesForUser(user)); // Outcomes service if (course.EnrolledUsers.Any(u => u.Id == user.Id)) { var outcomesUrl = UrlHelper.GenerateUrl("DefaultApi", null, "Outcomes", new RouteValueDictionary { { "httproute", string.Empty } }, RouteTable.Routes, request.RequestContext, false); Uri outcomesUri; if (Uri.TryCreate(request.Url, outcomesUrl, out outcomesUri)) { ltiRequest.LisOutcomeServiceUrl = outcomesUri.AbsoluteUri; } ltiRequest.LisResultSourcedId = JsonConvert.SerializeObject(new LisResultSourcedId { AssignmentId = assignment.AssignmentId, UserId = user.Id }); } // Tool Consumer Profile service var profileUrl = UrlHelper.GenerateUrl("DefaultApi", null, "ToolConsumerProfile", new RouteValueDictionary { { "httproute", string.Empty } }, RouteTable.Routes, request.RequestContext, false); Uri profileUri; if (Uri.TryCreate(request.Url, profileUrl, out profileUri)) { ltiRequest.ToolConsumerProfileUrl = profileUri.AbsoluteUri; } // Add the custom parameters. This consumer supports 3 special substitutions. var customParameters = assignment.CustomParameters; if (!string.IsNullOrWhiteSpace(customParameters)) { ltiRequest.AddCustomParameters(customParameters); } return ltiRequest.GetViewModel(assignment.ConsumerSecret); }
public ActionResult PlaceContentItem(LtiRequest model) { var ltiMessageType = model.LtiMessageType; if (!string.IsNullOrEmpty(ltiMessageType) && !ltiMessageType.Equals(LtiConstants.ContentItemSelectionLtiMessageType)) { return RedirectToAction("BadRequest", "Error", new { error = "Unknown LTI message" }); } var ltiResponse = (IContentItemSelection)model; var data = JsonConvert.DeserializeObject<ContentItemData>(ltiResponse.Data); var contentItemTool = ConsumerContext.ContentItemTools.Find(data.ContentItemToolId); if (contentItemTool == null) { return RedirectToAction("BadRequest", "Error", new { error = "Invalid content item tool id" }); } var course = ConsumerContext.Courses.Find(data.CourseId); if (course == null) { return RedirectToAction("BadRequest", "Error", new { error = "Invalid course id" }); } var contentItems = JsonConvert.DeserializeObject<ContentItemSelectionGraph>(ltiResponse.ContentItems); foreach (var contentItem in contentItems.Graph) { if (contentItem.Type == LtiConstants.LtiLinkType) { var custom = new StringBuilder(); foreach (var key in contentItem.Custom.Keys) { custom.AppendFormat("{0}={1}\n", key, contentItem.Custom[key]); } var assignment = new Assignment { ConsumerKey = contentItemTool.ConsumerKey, Course = course, ConsumerSecret = contentItemTool.ConsumerSecret, CustomParameters = custom.ToString(), Description = contentItem.Text, Name = contentItem.Title, Url = (contentItem.Id ?? new Uri(contentItemTool.Url)).AbsoluteUri }; ConsumerContext.Assignments.Add(assignment); } } ConsumerContext.SaveChanges(); return RedirectToAction("Details", "Course", new { id = data.CourseId }); }
public ScoredAssignmentModel(Assignment assignment) { AssignmentId = assignment.AssignmentId; Course = assignment.Course; Description = assignment.Description; Name = assignment.Name; Url = assignment.Url; }