public ActionResult Create(Auditing auditing)
        {
            if (ModelState.IsValid)
            {
                db.Auditings.Add(auditing);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(auditing);
        }
Beispiel #2
0
 void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
 {
     if (HttpContext.Current.Session["login"] == null)
     {
         filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new
         {
             action = "SessionExpired",
             controller = "Error",
             area = ""
         }));
     }
     else
     {
         using (LealtadEntities db = new LealtadEntities())
         {
             db.Database.Connection.ConnectionString = AppModule.ConnectionString("SumaLealtad");
             int idlog;
             if (db.Auditings.Count() > 0)
             {
                 idlog = db.Auditings.Max(x => x.id) + 1;
             }
             else
             {
                 idlog = 1;
             }
             Auditing log = new Auditing()
             {
                 id = idlog,
                 objectid = 1,
                 operationsid = 1,
                 userid = (int)HttpContext.Current.Session["userid"],
                 creationdate = filterContext.HttpContext.Timestamp,
                 originaldata = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
                 changedata = filterContext.ActionDescriptor.ActionName,
                 ipaddress = filterContext.HttpContext.Request.UserHostAddress
             };
             db.Auditings.Add(log);
             db.SaveChanges();
         }
     }
     this.OnActionExecuting(filterContext);
 }
 public ActionResult Edit(Auditing auditing)
 {
     if (ModelState.IsValid)
     {
         db.Entry(auditing).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(auditing);
 }