public ActionResult Edit(int id) { if (User.IsInRole("Admin")) { var service = CreateStorySubmissionService(); var detail = service.AdminGetStoryById(id); var model = new StorySubmissionEdit { StoryId = detail.StoryId, StoryTitle = detail.StoryTitle, StoryText = detail.StoryText }; return(View(model)); } if (User.Identity.IsAuthenticated && !User.IsInRole("Admin")) { var service = CreateStorySubmissionService(); var detail = service.GetStoryById(id); var model = new StorySubmissionEdit { StoryId = detail.StoryId, StoryTitle = detail.StoryTitle, StoryText = detail.StoryText }; return(View(model)); } return(View()); }
public bool UpdateStorySubmission(StorySubmissionEdit model) { using (var ctx = new ApplicationDbContext()) { var entity = ctx .StorySubmissions .Single(e => e.StoryId == model.StoryId && e.StudentId == _userId); entity.StoryTitle = model.StoryTitle; entity.StoryText = model.StoryText; entity.ModifiedUtc = DateTimeOffset.UtcNow; return(ctx.SaveChanges() == 1); } }
public ActionResult Edit(int id, StorySubmissionEdit model) { if (!ModelState.IsValid) { return(View(model)); } if (model.StoryId != id) { ModelState.AddModelError("", "Id Mismatch"); return(View(model)); } var service = CreateStorySubmissionService(); if (User.IsInRole("Admin")) { if (service.AdminUpdateStorySubmission(model)) { TempData["SaveResult"] = "Your comments have been recorded."; return(RedirectToAction("AdminIndex")); } } if (User.Identity.IsAuthenticated && !User.IsInRole("Admin")) { if (service.UpdateStorySubmission(model)) { TempData["SaveResult"] = "Your story was updated for the teacher's review."; return(RedirectToAction("Index")); } } ModelState.AddModelError("", "Your story could not be updated."); return(View(model)); }