public ActionResult Launch(int contentItemToolId, int courseId) { var contentItemTool = ConsumerContext.ContentItemTools.Find(contentItemToolId); if (contentItemTool == null) { return(RedirectToAction("BadRequest", "Error", new { error = "Invalid content tool id" })); } var course = ConsumerContext.Courses.Find(courseId); if (course == null) { return(RedirectToAction("BadRequest", "Error", new { error = "Invalid course id" })); } var user = UserManager.FindById(User.Identity.GetUserId()); var returnUrl = UrlHelper.GenerateUrl("Default", "PlaceContentItem", "ContentItemTool", null, RouteTable.Routes, Request.RequestContext, true); Uri returnUri; if (Uri.TryCreate(Request.Url, returnUrl, out returnUri)) { returnUrl = returnUri.AbsoluteUri; } return(View(LtiUtility.CreateContentItemSelectionRequestViewModel(Request, contentItemTool, course, user, returnUrl))); }
/// <summary> /// Form a basic LTI launch request for the browser to POST. /// </summary> /// <param name="id">The assignment ID to launch.</param> /// <returns>A form post for the browser to execute.</returns> public ActionResult LtiLaunch(int id = 0) { var assignment = ConsumerContext.Assignments.Find(id); var user = UserManager.FindById(User.Identity.GetUserId()); return(View(LtiUtility.CreateBasicLaunchRequestViewModel(Request, assignment, user))); }
public ToolConsumerProfileController() { OnGetToolConsumerProfile = context => { // I use AssemblyInfo to store product and vendor values that may be used // in multiple places in this sample var guid = LtiUtility.GetProduct(); var code = guid; // Product and ProductFamily are the same in this sample var vendorName = LtiUtility.GetCompany(); var productName = LtiUtility.GetTitle(); var productVersion = LtiUtility.GetVersion(); // Build a minimal ToolConsumerProfile for LTI 1.2 var profile = new ToolConsumerProfile { CapabilityOffered = new[] { LtiConstants.BasicLaunchLtiMessageType }, Guid = guid, LtiVersion = context.LtiVersion, ProductInstance = new ProductInstance { Guid = guid, ProductInfo = new ProductInfo { ProductFamily = new ProductFamily { Code = code, Vendor = new Vendor { Code = code, Timestamp = DateTime.UtcNow, VendorName = new VendorName(vendorName) } }, ProductName = new ProductName(productName), ProductVersion = productVersion } } }; // Add Outcomes Management var outcomesUrl = UrlHelper.GenerateUrl("DefaultApi", null, "Outcomes", new RouteValueDictionary { { "httproute", string.Empty } }, RouteTable.Routes, HttpContext.Current.Request.RequestContext, false); Uri serviceUri; profile.ServiceOffered = new[] { new RestService { Action = new[] { "POST" }, EndPoint = Uri.TryCreate(Request.RequestUri, outcomesUrl, out serviceUri) ? serviceUri : null, Format = new[] { LtiConstants.OutcomeMediaType } } }; context.ToolConsumerProfile = profile; return(Task.FromResult <object>(null)); }; }