public JsonResult CreateStep([DataSourceRequest] DataSourceRequest request, int tutorialId, StepDisplayModel stepModel) { var tutorial = this.db.Tutorials.Find(tutorialId); var user = this.db.Users.FirstOrDefault(u => u.UserName == HttpContext.User.Identity.Name); if (user != tutorial.User) { ModelState.AddModelError("Permissions", "You don't have permissions"); } if (tutorial != null && user != null && tutorial.User == user && ModelState.IsValid) { Step step = new Step(); step.Content = stepModel.Content; step.Title = stepModel.Title; string newImage = this.GetStepImage(tutorial.Title, step.Title); if (newImage != null) { step.Image = newImage; } tutorial.Steps.Add(step); db.SaveChanges(); } return Json(new[] { stepModel }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); }
public JsonResult DeleteStep([DataSourceRequest] DataSourceRequest request, int id, StepDisplayModel stepModel) { var step = this.db.Steps.Include("Tutorial").FirstOrDefault(st => st.Id == stepModel.Id); var tutorial = step.Tutorial; var user = tutorial.User; if (user.UserName != HttpContext.User.Identity.Name) { ModelState.AddModelError("Permissions", "You don't have permissions"); return Json(new[] { stepModel }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); } if (step != null) { this.db.Steps.Remove(step); this.db.SaveChanges(); } return Json(new[] { stepModel }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); }
public JsonResult UpdateStep([DataSourceRequest] DataSourceRequest request, StepDisplayModel stepModel) { var step = this.db.Steps.FirstOrDefault(st => st.Id == stepModel.Id); if (step != null && ModelState.IsValid) { step.Title = stepModel.Title; step.Content = stepModel.Content; var tutorial = step.Tutorial; string newImage = this.GetStepImage(tutorial.Title, step.Title); if (newImage != null) { step.Image = newImage; } this.db.SaveChanges(); } return Json(new[] { stepModel }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); }
public JsonResult DeleteStep([DataSourceRequest] DataSourceRequest request, StepDisplayModel stepModel) { var step = this.db.Steps.FirstOrDefault(st => st.Id == stepModel.Id); if (step != null) { this.db.Steps.Remove(step); this.db.SaveChanges(); } return Json(new[] { stepModel }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); }