public ActionResult Create([Bind(Include = "Title,Briefing,Textpost")] Post post, HttpPostedFileBase picture) { ModelState.Remove("Picture"); post.Aspnetusers_Id = User.Identity.GetUserId(); post.Id = this.GetID(); if (post.Aspnetusers_Id == null) { ModelState.AddModelError("User", "The User is required."); } post.DateCreate = DateTime.Now; if (picture != null) { post.Picture = new byte[picture.ContentLength]; picture.InputStream.Read(post.Picture, 0, picture.ContentLength); } else { ModelState.AddModelError("Picture", "The Picture is required."); return(View(post)); } if (ModelState.IsValid) { db.Post.Add(post); db.SaveChanges(); this.CreateMessage("Successfully published.", "Information", 1); return(RedirectToActionPermanent("Index")); } return(View(post)); }
//actiondan sonra public void OnActionExecuted(ActionExecutedContext filterContext) { db.Logs.Add(new Logs { userId = (filterContext.HttpContext.Session["login"] as user).id, actionName = filterContext.ActionDescriptor.ActionName, controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName, time = DateTime.Now, alteration = "OnActionExecuted" }); db.SaveChanges(); }
public void OnResultExecuted(ResultExecutedContext filterContext) { db.Logs.Add(new Logs { userId = (filterContext.HttpContext.Session["login"] as user).id, actionName = filterContext.RouteData.Values["action"].ToString(), controllerName = filterContext.RouteData.Values["controller"].ToString(), time = DateTime.Now, alteration = "OnResultExecuted" }); db.SaveChanges(); }
public void OnException(ExceptionContext filterContext) { blogDBEntities db = new blogDBEntities(); int? userId = null; if (filterContext.HttpContext.Session["login"] != null) { userId = (filterContext.HttpContext.Session["login"] as user).id; } db.Logs.Add(new Logs { userId = userId, actionName = filterContext.RouteData.Values["action"].ToString(), controllerName = filterContext.RouteData.Values["controller"].ToString(), time = DateTime.Now, alteration = "Error :" + filterContext.Exception.Message }); db.SaveChanges(); filterContext.ExceptionHandled = true; filterContext.Controller.TempData["error"] = filterContext.Exception; filterContext.Result = new RedirectResult("~/Error/Index"); }