/// <summary> /// Service Method To Log All The Actions /// </summary> /// <param name="actionLog"></param> /// <param name="location"></param> public static void LogAction(ActionLogModel actionLog, string location) { var dateCreated = DateTime.Now; String SQL = "INSERT INTO ActionLog(DateCreated,UserID,ActionPerformed,MethodName,IsError)" + "VALUES(GetDate(),'" + actionLog.UserID + "','" + actionLog.ActionPerformed + "','" + actionLog.MethodName + "','" + actionLog.IsError + "')"; using (SqlConnection dbConn = new SqlConnection(selectConnection(location))) { try { dbConn.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = SQL; cmd.Connection = dbConn; cmd.ExecuteNonQuery(); dbConn.Close(); } catch (Exception ex) { Console.WriteLine(ex); } finally { dbConn.Close(); } } }
protected ActionLogModel AutoBindDataReader(SqlDataReader dr, params string[] fields) { var model = new ActionLogModel(); if (DbTool.HasFields("ActionLogId", fields)) { model.ActionLogId = DbTool.ConvertObject <System.Int32>(dr["ActionLogId"]); } if (DbTool.HasFields("ActionName", fields)) { model.ActionName = DbTool.ConvertObject <System.String>(dr["ActionName"]); } if (DbTool.HasFields("UserName", fields)) { model.UserName = DbTool.ConvertObject <System.String>(dr["UserName"]); } if (DbTool.HasFields("ActionResult", fields)) { model.ActionResult = DbTool.ConvertObject <System.String>(dr["ActionResult"]); } if (DbTool.HasFields("KeyData", fields)) { model.KeyData = DbTool.ConvertObject <System.String>(dr["KeyData"]); } if (DbTool.HasFields("Notes", fields)) { model.Notes = DbTool.ConvertObject <System.String>(dr["Notes"]); } if (DbTool.HasFields("CreateOn", fields)) { model.CreateOn = DbTool.ConvertObject <System.DateTime>(dr["CreateOn"]); } return(model); }
public override void OnActionExecuted(ActionExecutedContext filterContext) { //在Action执行之后执行 return; //home,index-登录成功 try { ActionLogModel logs = new ActionLogModel(); logs.IP = GetIP(); logs.UserId = int.Parse(filterContext.RequestContext.HttpContext.Request.Cookies["User"]["UserId"]); logs.DepartmentName = filterContext.RequestContext.HttpContext.Request.Cookies["User"]["DepName"]; logs.RoleName = filterContext.RequestContext.HttpContext.Request.Cookies["User"]["UserRoleName"]; logs.VisitTime = new DateTime(System.DateTime.Now.Year, System.DateTime.Now.Month, System.DateTime.Now.Day, System.DateTime.Now.Hour, System.DateTime.Now.Minute, System.DateTime.Now.Second); logs.Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName; logs.Action = filterContext.ActionDescriptor.ActionName; logs.Discription = "111"; logs.BrowserType = filterContext.RequestContext.HttpContext.Request.Browser.Type; logs.BrowserVersion = filterContext.RequestContext.HttpContext.Request.Browser.Version; db.ActionLogs.Add(logs); db.SaveChanges(); } catch (Exception) { ; } base.OnActionExecuted(filterContext); //filterContext.ActionDescriptor.ControllerDescriptor.ControllerName }
public ActionResult DeleteConfirmed(int id) { ActionLogModel actionlogmodel = db.ActionLogs.Find(id); db.ActionLogs.Remove(actionlogmodel); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(ActionLogModel actionlogmodel) { if (ModelState.IsValid) { db.Entry(actionlogmodel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(actionlogmodel)); }
// // GET: /ActionLog/Edit/5 public ActionResult Edit(int id = 0) { ActionLogModel actionlogmodel = db.ActionLogs.Find(id); if (actionlogmodel == null) { return(HttpNotFound()); } return(View(actionlogmodel)); }
protected void BindDataReader(ActionLogModel model, SqlDataReader dr) { model.ActionLogId = DbTool.ConvertObject <System.Int32>(dr["ActionLogId"]); model.ActionName = DbTool.ConvertObject <System.String>(dr["ActionName"]); model.UserName = DbTool.ConvertObject <System.String>(dr["UserName"]); model.ActionResult = DbTool.ConvertObject <System.String>(dr["ActionResult"]); model.KeyData = DbTool.ConvertObject <System.String>(dr["KeyData"]); model.Notes = DbTool.ConvertObject <System.String>(dr["Notes"]); model.CreateOn = DbTool.ConvertObject <System.DateTime>(dr["CreateOn"]); }
public ActionResult Create(ActionLogModel actionlogmodel) { if (ModelState.IsValid) { db.ActionLogs.Add(actionlogmodel); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(actionlogmodel)); }
public void InsertActionLog(ActionLogModel actionLogModel) { string indexName = LogIndexType.action_log.ToString(); if (!_client.Indices.Exists(indexName).Exists) { _client.Indices.Create(indexName, x => x.Map <ActionLogModel>(m => m.AutoMap()) .Aliases(a => a.Alias(indexName)) ); } _client.Index <ActionLogModel>(actionLogModel, x => x.Index(indexName)); }
public ActionLogModel GetModel(int Id) { string sql = "select top 1 * from ActionLog where ActionLogId =" + Id; ActionLogModel model = new ActionLogModel(); SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, sql.ToString()); if (dr.Read()) { //var fields = DbTool.GetReaderFieldNames(dr); //model = AutoBindDataReader(dr, fields); BindDataReader(model, dr); } dr.Close(); return(model); }
public JsonResult GetActionLogList() { var actionLogListObj = this.actionLogService.GetAllActionLog(); List <ActionLogModel> actionLogVMList = new List <ActionLogModel>(); foreach (var actionLog in actionLogListObj) { ActionLogModel actionLogTemp = new ActionLogModel(); //actionLogTemp.Id = actionLog.Id; //actionLogTemp.Name = actionLog.Name; //actionLogTemp.Code = actionLog.Code; actionLogVMList.Add(actionLogTemp); } return(Json(actionLogVMList, JsonRequestBehavior.AllowGet)); }
public List <ActionLogModel> GetModelList() { List <ActionLogModel> result = new List <ActionLogModel>(); string sql = "select * from ActionLog where 1=1"; ActionLogModel model = new ActionLogModel(); SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.Text, sql.ToString()); //var fields = DbTool.GetReaderFieldNames(dr); while (dr.Read()) { //model = AutoBindDataReader(dr, fields); model = new ActionLogModel(); BindDataReader(model, dr); result.Add(model); } dr.Close(); return(result); }
/// <summary> /// Service Method To Get ActionLog Details /// </summary> /// <param name="authBaseModel"></param> /// <returns></returns> public static async Task <List <ActionLogModel> > GetActionLogDetails(AuthBaseModel authBaseModel) { List <ActionLogModel> actionLogs = new List <ActionLogModel>(); using (SqlConnection dbConn = new SqlConnection(selectConnection(authBaseModel.Location))) { var Query = "SELECT * FROM ActionLog ORDER BY ID DESC"; SqlDataReader reader; try { dbConn.Open(); SqlCommand cmd = new SqlCommand(Query, dbConn); reader = await cmd.ExecuteReaderAsync(); if (reader.HasRows) { while (reader.Read()) { ActionLogModel actionLog = new ActionLogModel(); actionLog.ID = reader.GetInt32(0); actionLog.DateCreated = reader.GetDateTime(1); actionLog.UserID = reader.GetInt32(2); actionLog.ActionPerformed = reader.GetString(3); actionLog.MethodName = reader.GetString(4); actionLog.IsError = reader.GetBoolean(5); actionLogs.Add(actionLog); } } dbConn.Close(); } catch { reader = null; } finally { dbConn.Close(); } return(actionLogs); } }
public int Add(ActionLogModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into [ActionLog]"); strSql.Append("(ActionName,UserName,ActionResult,KeyData,Notes,CreateOn)"); strSql.Append(" values (@ActionName,@UserName,@ActionResult,@KeyData,@Notes,@CreateOn)"); strSql.Append(";select SCOPE_IDENTITY()"); SqlParameter[] parameters = { new SqlParameter("@ActionName", DbTool.FixSqlParameter(model.ActionName)) , new SqlParameter("@UserName", DbTool.FixSqlParameter(model.UserName)) , new SqlParameter("@ActionResult", DbTool.FixSqlParameter(model.ActionResult)) , new SqlParameter("@KeyData", DbTool.FixSqlParameter(model.KeyData)) , new SqlParameter("@Notes", DbTool.FixSqlParameter(model.Notes)) , new SqlParameter("@CreateOn", DbTool.FixSqlParameter(model.CreateOn)) }; return(DbTool.ConvertObject <int>(SqlHelper.ExecuteScalar(conn, CommandType.Text, strSql.ToString(), parameters), 0)); }
public int Update(ActionLogModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update ActionLog set "); strSql.Append("ActionName=@ActionName,UserName=@UserName,ActionResult=@ActionResult,KeyData=@KeyData,Notes=@Notes,CreateOn=@CreateOn "); strSql.Append(" where ActionLogId=@ActionLogId "); SqlParameter[] parameters = { new SqlParameter("@ActionName", DbTool.FixSqlParameter(model.ActionName)) , new SqlParameter("@UserName", DbTool.FixSqlParameter(model.UserName)) , new SqlParameter("@ActionResult", DbTool.FixSqlParameter(model.ActionResult)) , new SqlParameter("@KeyData", DbTool.FixSqlParameter(model.KeyData)) , new SqlParameter("@Notes", DbTool.FixSqlParameter(model.Notes)) , new SqlParameter("@CreateOn", DbTool.FixSqlParameter(model.CreateOn)) , new SqlParameter("@ActionLogId", model.ActionLogId) }; return(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters)); }
public ActionLogFilter(IElasticsearchService elasticsearchService) { _elasticsearchService = elasticsearchService; _actionLogModel = new ActionLogModel(); _stopwatch = new Stopwatch(); }