// Remove a page and every related entities public ActionResult Remove(string slug) { PageModel model = GetPageModel(slug); bool hasRemovePermission = false; // check if he is in a role that has delete permissions using (TransactionScope ts = new TransactionScope()) { var deleteRoles = (from p in model.Permissions where p.Delete == true select p.RoleName).ToList(); var userRoles = from r in ( from u in _userRepository.All() where u.Id == LoggedInUserId select u ).Fetch(u => u.Roles).Single().Roles select r.Name; ts.Complete(); hasRemovePermission = userRoles.Any(r => deleteRoles.Contains(r)); } if (hasRemovePermission) { try { _pageRepository.Delete(_pageRepository.FindById(model.Id)); } catch { Alert(AlertType.danger, "Error", "Failed to remove page. Please remove all its children first."); return(RedirectToAction("edit", "page", new { slug = slug })); } } Alert(AlertType.success, "Success", string.Format("Page '{0}' successfully removed.", model.Name)); return(Redirect("~/")); }
[HttpPost] // patch for shared server compatibility, usually would use [HttpDelete] public JsonNetResult DeletePageWidget(PageWidgetModel model) { _pageWidgetRepository.Delete( _pageWidgetRepository.FindById(model.Id)); return(new JsonNetResult(model)); }