/// <summary> /// Add new session to database /// </summary> /// <param name="session"></param> /// <returns></returns> protected async Task AddNewSession(ProcessExplorerUserSession session) { //set user id on session instance FillSessionEntity(session); //add to database _work.Session.Add(session); await SaveSyncChanges(); }
/// <summary> /// Register user session for console application /// </summary> /// <param name="userName">name of computer (user that loged on computer)</param> /// <param name="sesssionId">session id generated by console application</param> /// <param name="started">start of session (When did user turn on his computer)</param> /// <returns></returns> public async Task RegisterSession(string userName, Guid sesssionId, DateTime started) { var userSession = await _work.Session.GetAsync(sesssionId); if (userSession != null) //session exists so stop further execution { return; } //create new session instance var newUserSession = new ProcessExplorerUserSession { ExplorerUserId = _user.UserId, Id = sesssionId, Inserted = _time.Now, Started = started, UserName = userName }; //add to db _work.Session.Add(newUserSession); await _work.CommitAsync(); }
/// <summary> /// Set UserId and inserted time on entity model /// </summary> /// <param name="entity"></param> protected void FillSessionEntity(ProcessExplorerUserSession entity) { entity.ExplorerUserId = UserId; entity.Inserted = _dateTime.Now; }