public async Task Add(ActionLogItem logItem) { logItem.Timestamp = DateTime.Now; logItem.UserId = UserContext.ApplicationUser?.Id ?? string.Empty; // Check if user is logged in or not DbContext.ActionLog.Add(logItem); // If performance becomes a concern, we could execute both of these simultaneously. // The downside is that the current actionLogItem would not be available on the current request. // Perhaps this could be sidestepped by saving back to the context. await DbContext.SaveChangesAsync(); if (!(UserContext.ApplicationUser is null)) { UserContext.ApplicationUser.LastActionLogItemId = logItem.Id; var records = await AccountRepository.Records(); var record = records.First(r => r.Id == UserContext.ApplicationUser.Id); record.LastActionLogItemId = logItem.Id; await DbContext.SaveChangesAsync(); } }
public LogsCollection GetActionLogByReffID(string InternalID) { LogsCollection logss = null; if (!this.IsReady) { base.CurDBEngine = new DatabaseEngine(this.DBType, this.Conn); if (this.IsReady = base.CurDBEngine.Connect()) { this.CurSQLFactory = new SQLFactory(this.DBType); } } if (this.IsReady) { DatabaseParameters parameters = new DatabaseParameters(); parameters.Add(new DatabaseParameter(this.DataStructure.Tables.LogActions.ReffID.ActualFieldName, InternalID)); this.CurSQLFactory.SelectCommand(parameters, this.DataStructure.Tables.LogActions.ActualTableName); DataTable table = base.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL); if (table != null) { logss = new LogsCollection(); DataRow[] rowArray = table.Select("", this.DataStructure.Tables.LogActions.LogDateTime.ActualFieldName); foreach (DataRow row in rowArray) { ActionLogItem item = new ActionLogItem { ReffID = row[this.DataStructure.Tables.LogActions.ReffID.ActualFieldName].ToString(), LogDate = Convert.ToDateTime(row[this.DataStructure.Tables.LogActions.LogDateTime.ActualFieldName]), LoggedBy = new ApplicationUser(row[this.DataStructure.Tables.LogActions.LogBy.ActualFieldName].ToString()), ActionDescription = row[this.DataStructure.Tables.LogActions.Description.ActualFieldName].ToString() }; logss.Add(item); } return(logss); } this.ErrMsg = "[LogManager.GetActionLogByReffID] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + base.CurDBEngine.ErrorMessage; } return(logss); }