public ConsumersRepository(ConsumerContext context) { _context = context; if (_context.Consumers.Count() == 0) { _context.Consumers.AddRange( new Consumer { Name = "Opie", Location = "Shih Tzu", ConsumerType = ConsumerType.Agent }, new Consumer { Name = "Reggie", Location = "Beagle", ConsumerType = ConsumerType.Agent }, new Consumer { Name = "Diesel", Location = "Bombay", ConsumerType = ConsumerType.User }, new Consumer { Name = "Lucy", Location = "Maine Coon", ConsumerType = ConsumerType.User }); _context.SaveChanges(); } }
public ActionResult DeleteConfirmed(int id) { ContentItemTool contentitemtool = ConsumerContext.ContentItemTools.Find(id); ConsumerContext.ContentItemTools.Remove(contentitemtool); ConsumerContext.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(Course course) { if (ModelState.IsValid) { ConsumerContext.Entry(course).State = EntityState.Modified; ConsumerContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(course)); }
public ActionResult Edit([Bind(Include = "ContentItemToolId,ConsumerKey,ConsumerSecret,CustomParameters,Description,Name,Url")] ContentItemTool contentitemtool) { if (ModelState.IsValid) { ConsumerContext.Entry(contentitemtool).State = EntityState.Modified; ConsumerContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(contentitemtool)); }
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 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)); }
/// <summary> /// Delete the Score that corresponds to the result. /// </summary> /// <param name="lisResultSourcedId">The sourcedId of the LisResult to delete.</param> /// <returns>True if the Score was deleted.</returns> protected override bool DeleteResult(string lisResultSourcedId) { var model = GetScore(lisResultSourcedId); if (model.IsValid && model.Score != null) { ConsumerContext.Scores.Remove(model.Score); ConsumerContext.SaveChanges(); return(true); } return(false); }
public ActionResult Create([Bind(Include = "ContentItemToolId,ConsumerKey,ConsumerSecret,CustomParameters,Description,Name,Url")] ContentItemTool contentitemtool) { if (ModelState.IsValid) { contentitemtool.Owner = UserManager.FindById(User.Identity.GetUserId()); ConsumerContext.ContentItemTools.Add(contentitemtool); ConsumerContext.SaveChanges(); return(RedirectToAction("Index")); } return(View(contentitemtool)); }
public ActionResult DeleteConfirmed(int id) { var assignment = ConsumerContext.Assignments.Find(id); var scores = ConsumerContext.Scores.Where(s => s.AssignmentId == id); foreach (var score in scores.ToList()) { ConsumerContext.Scores.Remove(score); } var courseId = assignment.Course.CourseId; ConsumerContext.Assignments.Remove(assignment); ConsumerContext.SaveChanges(); return(RedirectToAction("Details", "Course", new { id = courseId })); }
public ActionResult Enroll(CourseEnrollmentModel model) { if (ModelState.IsValid) { var course = ConsumerContext.Courses.Find(model.CourseId); var user = UserManager.FindById(model.UserId); if (model.Enrolled) { course.EnrolledUsers.Remove(user); } else { course.EnrolledUsers.Add(user); } ConsumerContext.SaveChanges(); } return(RedirectToAction("Details", new { id = model.CourseId })); }
public ActionResult Edit(CreateEditAssignmentModel model) { if (ModelState.IsValid) { var assignment = ConsumerContext.Assignments.Find(model.AssignmentId); assignment.ConsumerKey = model.ConsumerKey; assignment.ConsumerSecret = model.ConsumerSecret; assignment.Course = ConsumerContext.Courses.Find(model.CourseId); assignment.CustomParameters = model.CustomParameters; assignment.Description = model.Description; assignment.Name = model.Name; assignment.Url = model.Url; ConsumerContext.Entry(assignment).State = EntityState.Modified; ConsumerContext.SaveChanges(); return(RedirectToAction("Details", "Course", new { id = model.CourseId })); } return(View(model)); }
/// <summary> /// Create or update a Score with the LTI result. /// </summary> /// <param name="result">The LTI result.</param> /// <returns>True if the Score was created or updated.</returns> protected override bool ReplaceResult(LisResult result) { var score = GetScore(result.SourcedId); if (score.IsValid) { if (score.Score == null) { score.Score = CreateScore(result); ConsumerContext.Scores.Add(score.Score); } if (result.Score.HasValue) { score.Score.DoubleValue = result.Score.Value; } ConsumerContext.SaveChanges(); return(true); } return(false); }
public ActionResult DeleteConfirmed(int id) { var course = ConsumerContext.Courses.Find(id); foreach (var assignment in course.Assignments.ToList()) { var assignment1 = assignment; var scores = ConsumerContext.Scores.Where(s => s.AssignmentId == assignment1.AssignmentId); foreach (var score in scores.ToList()) { ConsumerContext.Scores.Remove(score); } course.Assignments.Remove(assignment); ConsumerContext.Assignments.Remove(assignment); } foreach (var user in course.EnrolledUsers.ToList()) { course.EnrolledUsers.Remove(user); } ConsumerContext.Courses.Remove(course); ConsumerContext.SaveChanges(); return(RedirectToAction("Index")); }
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)); }