public ActionResult Edit(Course course) { if (ModelState.IsValid) { ConsumerContext.Entry(course).State = EntityState.Modified; ConsumerContext.SaveChanges(); return RedirectToAction("Index"); } return View(course); }
public static LtiRequestViewModel CreateContentItemSelectionRequestViewModel(HttpRequestBase request, ContentItemTool contentItemTool, Course course, ApplicationUser user, string returnUrl) { var ltiRequest = new LtiRequest(LtiConstants.ContentItemSelectionRequestLtiMessageType) { ConsumerKey = contentItemTool.ConsumerKey, Url = new Uri(contentItemTool.Url) }; // Tool Consumer 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; ltiRequest.LisCourseSectionSourcedId = course.CourseId.ToString(CultureInfo.InvariantCulture); // Instance ltiRequest.ToolConsumerInstanceGuid = "~/".ToAbsoluteUrl(); var title = Assembly.GetExecutingAssembly().GetCustomAttributes<AssemblyTitleAttribute>().FirstOrDefault(); ltiRequest.ToolConsumerInstanceName = title == null ? null : title.Title; // 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)); // Presentation ltiRequest.LaunchPresentationDocumentTarget = DocumentTarget.iframe; // Content Item Tool ltiRequest.AcceptMediaTypes = LtiConstants.LtiLinkMediaType; // Only accept LTI Link ltiRequest.AcceptMultiple = true; ltiRequest.AcceptPresentationDocumentTargets = "iframe"; ltiRequest.AcceptUnsigned = false; ltiRequest.ContentItemReturnUrl = returnUrl; //ltiRequest.ContentItemServiceUrl = "about:blank"; ltiRequest.Data = JsonConvert.SerializeObject(new ContentItemData { ContentItemToolId = contentItemTool.ContentItemToolId, CourseId = course.CourseId }); // Add the custom parameters. var customParameters = contentItemTool.CustomParameters; // This tool consumer supports 3 non-spec custom parameters if (!string.IsNullOrWhiteSpace(customParameters)) { ltiRequest.AddCustomParameters(customParameters); } return ltiRequest.GetViewModel(contentItemTool.ConsumerSecret); }
public ActionResult Create(Course model) { if (ModelState.IsValid) { model.Instructor = UserManager.FindById(User.Identity.GetUserId()); ConsumerContext.Courses.Add(model); ConsumerContext.SaveChanges(); return RedirectToAction("Index"); } return View(model); }