public ActionResult Delete(int id) { LOG_ACCESS log = database.LOG_ACCESS.Find(id); database.Entry(log).State = EntityState.Deleted; database.SaveChanges(); return(RedirectToAction("Index")); }
public override void OnAuthorization(AuthorizationContext filterContext) { // format permission : controller-action string requiredPermission = String.Format("{0}-{1}", filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, filterContext.ActionDescriptor.ActionName); var Identity = (IdentityUser)filterContext.HttpContext.Session["Identity"]; MassMailsDbContext database = new MassMailsDbContext(); if (Identity != null) { LOG_ACCESS log = new LOG_ACCESS(); log.page = requiredPermission; log.created_at = System.DateTime.Now; log.User_Id = Identity.UserId; AuthUser requestingUser = new AuthUser(Identity.UserId); if (!requestingUser.HasPermission(requiredPermission) & !requestingUser.IsSysAdmin) { log.status = false; database.LOG_ACCESS.Add(log); database.SaveChanges(); filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "action", "Index" }, { "controller", "Unauthorised" } }); } else { log.status = true; database.LOG_ACCESS.Add(log); database.SaveChanges(); } } else { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "action", "Index" }, { "controller", "Login" }, { "returnUrl", filterContext.HttpContext.Request.RawUrl } }); } }