public ActionResult Promote(int id) { try { if (int.Parse(Session["Id"].ToString()) != id) { ModeratorDAO dao = new ModeratorDAO(); UserDAO udao = new UserDAO(); if (dao.SearchByUserId(id) == null) { Moderator m = new Moderator(); m.UserId = id; dao.Add(m); Moderator mod = dao.SearchByUserId(id); User u = udao.SearchById(id); u.ModeratorId = mod.Id; udao.Update(); } } return(RedirectToAction("Register")); } catch { return(RedirectToAction("Index", "Home")); } }
public ActionResult Demote(int id) { try { if (int.Parse(Session["Id"].ToString()) != id) { ModeratorDAO dao = new ModeratorDAO(); UserDAO udao = new UserDAO(); if (dao.SearchByUserId(id) != null) { User u = udao.SearchById(id); Moderator m = dao.SearchByUserId(id); u.ModeratorId = null; udao.Update(); dao.Remove(m); } } return(RedirectToAction("Register")); } catch { return(RedirectToAction("Index", "Home")); } }