/// <summary> /// 获取删除数据的日志信息 /// </summary> /// <param name="entry"></param> /// <returns></returns> private static OperatingLog GetDeletedLog(ObjectStateEntry entry) { OperatingLog log = new OperatingLog() { EntityName = entry.EntitySet.ElementType.Name, OperateType = OperatingType.Delete }; for (int i = 0; i < entry.OriginalValues.FieldCount; i++) { string name = entry.OriginalValues.GetName(i); if (name == "Timestamp") { continue; } object originalValue = entry.OriginalValues[i]; OperatingLogItem logItem = new OperatingLogItem() { Field = name, OriginalValue = originalValue == null ? null : originalValue.ToString() }; log.LogItems.Add(logItem); } return(log); }
public async Task <IActionResult> Login(LoginReq req) { var log = new OperatingLog(); log.Create(""); log.Summary = req.UserName + "尝试登录"; var user = await _userBll.LoginAsync(req.UserName, req.Password); if (user == null) { await _logBll.AddAsync(log); return(new JsonResult(new { success = false, message = "用户不存在" })); } else { log.Create(user.PrimaryKey); log.Model = Json.Serialize(user); log.LinkId = user.PrimaryKey; await _logBll.AddAsync(log); } var claims = new[] { new Claim("name", user.UserName), new Claim("id", user.PrimaryKey), new Claim("role", "admin"), }; var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config.Value.SecretKey)); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken(_config.Value.Issuer, _config.Value.Audience, claims, DateTime.Now, DateTime.Now.AddMinutes(_config.Value.Expired), creds); var result = new JwtSecurityTokenHandler().WriteToken(token); return(new JsonResult(new { success = true, token = result })); }
/// <summary> /// 获取修改数据的日志信息 /// </summary> /// <param name="entry"></param> /// <returns></returns> private static OperatingLog GetModifiedLog(ObjectStateEntry entry) { OperatingLog log = new OperatingLog() { EntityName = entry.EntitySet.ElementType.Name, OperateType = OperatingType.Update }; for (int i = 0; i < entry.CurrentValues.FieldCount; i++) { string name = entry.CurrentValues.GetName(i); if (name == "Timestamp") { continue; } object currentValue = entry.CurrentValues.GetValue(i); object originalValue = entry.OriginalValues[name]; if (currentValue.Equals(originalValue)) { continue; } OperatingLogItem logItem = new OperatingLogItem() { Field = name, NewValue = currentValue == null ? null : currentValue.ToString(), OriginalValue = originalValue == null ? null : originalValue.ToString() }; log.LogItems.Add(logItem); } return(log); }
/// <summary> /// 获取添加数据的日志信息 /// </summary> /// <param name="entry"></param> /// <returns></returns> private static OperatingLog GetAddedLog(ObjectStateEntry entry) { OperatingLog log = new OperatingLog { EntityName = entry.EntitySet.ElementType.Name, OperateType = OperatingType.Insert }; for (int i = 0; i < entry.CurrentValues.FieldCount; i++) { string name = entry.CurrentValues.GetName(i); if (name == "Timestamp") { continue; } object value = entry.CurrentValues.GetValue(i); OperatingLogItem logItem = new OperatingLogItem() { Field = name, NewValue = value == null ? null : value.ToString() }; log.LogItems.Add(logItem); } return(log); }
public async Task AddAsync(string createId, string summary, string model, string linkId) { var log = new OperatingLog(); log.Create(createId); log.LinkId = linkId; log.Summary = summary; log.Model = model; await AddAsync(log); }
public async Task <IActionResult> GetOperatingLog(string logId) { OperatingLog log = await _logBll.GetOperatingLogAsync(logId); return(new JsonResult(new { success = true, data = log })); }
public async Task AddAsync(OperatingLog log) { await _operatingDataLayer.InsertAsync(log); }