public IActionResult DeleteNews(int id) { var news = newsManager.Get().Where(e => e.Id == id).FirstOrDefault(); newsManager.Delete(news); return(RedirectToAction("News")); }
public ActionResult DeleteGroup(string id) { var group = groupsManager.GetById(id); var users = userManager.GetList().Where(x => x.GroupId == group.Id); foreach (var item in users) { item.GroupId = groupsManager.GetByName("Global").Id; if (item.Role == Roles.Praepostor) { item.Role = Roles.User; } userManager.Update(item); } foreach (var item in newsManager.GetList()) { if (item.GroupId == group.Id) { newsManager.Delete(item); } } groupsManager.Delete(group); return(RedirectToRoute("GetGroups")); }
public DeleteNewsResult Delete(int id) { try { if (id <= 0) { throw new ArgumentNullException(nameof(id)); } NewsDTO savedNews = NewsManager.GetByID(id); if (savedNews == null) { throw new Exception("News not found"); } if (savedNews.CreateUser != Guid.Parse(User.FindFirst(c => c.Type == ClaimTypes.NameIdentifier).Value)) { throw new UnauthorizedAccessException(); } NewsManager.Delete(id); ImageExtensions.DeleteImage(GetNewsImagePath(savedNews.IconName)); return(new DeleteNewsResult()); } catch (Exception ex) { return(new DeleteNewsResult(ex)); } }
public static object Delete(decimal newsId, string deleteReason) { if (Utils.CheckPermission(4, 27, Utils.LoggedUser.Roles) < 1) { return(Utils.ServiceResponse("", new ModelResponse(101), null)); } var result = Mgr.Delete(newsId, deleteReason); return(result); }
public ActionResult Delete(string id) { var userdata = new UserDataContainer(); var newsItem = newsManager.GetById(id); if (newsItem == null || !userdata.IsAuthorized) { return(RedirectToRoute("NotFound")); } if (userdata.CurrentUser.Id == newsItem.AuthorId || userdata.CurrentUser.Role == Roles.Admin || userdata.CurrentUser.Role == Roles.Moderator || (userdata.CurrentUser.Role == Roles.Praepostor && userdata.CurrentUser.GroupId == newsItem.GroupId)) { newsManager.Delete(newsItem); return(Json(true)); } else { return(RedirectToRoute("NotFound")); } }