public static TimeTrack GetTimeTrackFromUserTimeTrackHistory(UserTimeTrackHistory userTimeTrackHistory) { if (userTimeTrackHistory != null) { return(new TimeTrack(userTimeTrackHistory.TimeTrackId, userTimeTrackHistory.StampDate, userTimeTrackHistory.ClockInTime, userTimeTrackHistory.ClockOutTime)); } return(new TimeTrack()); }
public int Save() { using (var dbContext = new TimeTrackingEntities()) { var utth = new UserTimeTrackHistory { UserId = UserId, UserName = UserName, ClockInTime = ClockInTime, ClockOutTime = ClockOutTime, StampDate = StampDate, UserIP = UserIp, IsDeleted = IsDeleted, CreatedBy = CreatedBy, CreatedDate = CreatedDate }; dbContext.UserTimeTrackHistories.Add(utth); dbContext.SaveChanges(); return(utth.TimeTrackId); } }
public static void TrackClockInOutTime(string userName) { var startDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]).Date; var endDate = startDate.AddDays(1); SetDefaultClockoutTimeStampToForgottenStamps(userName); using (var dbContext = new TimeTrackingEntities()) { var usersLatestRecord = (from utsh in dbContext.UserTimeTrackHistories where utsh.IsDeleted == false && utsh.UserName.ToLower().Equals(userName.ToLower()) && (utsh.StampDate >= startDate && utsh.StampDate < endDate) && utsh.ClockInTime.Length > 0 && (utsh.ClockOutTime == null || utsh.ClockOutTime.Length == 0) select utsh).OrderByDescending(c => c.StampDate).ThenByDescending(c => c.CreatedDate).FirstOrDefault(); if (usersLatestRecord != null) // User has clocked in, Clock user out { usersLatestRecord.ClockOutTime = string.Format("{0:t}", WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"])); usersLatestRecord.UpdatedBy = userName; usersLatestRecord.UpdatedDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]); usersLatestRecord.UserIP = WebHelpers.GetIpAddress(); } else // User hasn't clocked in yet, Clock user in { var userTimeStampHistory = new UserTimeTrackHistory { UserId = MembershipUserExtended.GetUserIdByUserName(userName), UserName = userName, ClockInTime = string.Format("{0:t}", WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"])), StampDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]), CreatedBy = userName, CreatedDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]), UserIP = WebHelpers.GetIpAddress(), IsDeleted = false }; dbContext.UserTimeTrackHistories.Add(userTimeStampHistory); } dbContext.SaveChanges(); } }
protected List <MedicalUser> GetLegacyUsers() { foreach (MedicalUser user in LegacyUsers) { var userHistoryList = RavenSession.Query <UserTimeStampsHistory>().Where(c => c.UserName == user.User).ToList(); var efUHistoryList = UserTimeTrackHistory.GetUserTimeStampHistory(user.User); var dataNeedsToMigrate = false; if (userHistoryList.Count > 0) { if (efUHistoryList.Count > 0) { foreach (var hist in userHistoryList.SelectMany(c => c.History)) { var efHist = efUHistoryList.FirstOrDefault( c => c.ClockInTime.Equals(hist.Start_time) && c.ClockOutTime.Equals(hist.End_time)); dataNeedsToMigrate = efHist == null; if (dataNeedsToMigrate) { break; } } user.UserHasDataToMigrate = dataNeedsToMigrate; } else { user.UserHasDataToMigrate = true; } } user.UserHistoryList = userHistoryList; //Check If User has already been migrated user.IsUserMigrated = MembershipUsers.Any(c => c.UserName.ToLower().Equals(user.User.ToLower())); } return(LegacyUsers); }
protected bool MigrateUserData(string userName) { var userNameIdDic = MembershipUserExtended.GetUserIdUserNameList(); try { var ravenUserHistory = RavenSession.Query <UserTimeStampsHistory>().Where(c => c.UserName == userName).ToList(); var efUHistoryList = UserTimeTrackHistory.GetUserTimeStampHistory(userName); if (ravenUserHistory.Count > 0) { if (efUHistoryList.Count > 0) { foreach (var efUserTimeStampHistory in from history in ravenUserHistory from timeStamp in history.History where !efUHistoryList.Any( c => c.ClockInTime.Equals(timeStamp.Start_time) && c.ClockOutTime.Equals(timeStamp.End_time)) select new UserTimeTrackHistory() { UserId = userNameIdDic[userName], UserName = userName, ClockInTime = DateTime.Parse(timeStamp.Start_time).TimeOfDay.ToString(), ClockOutTime = DateTime.Parse(timeStamp.End_time).TimeOfDay.ToString(), StampDate = DateTime.Parse(timeStamp.Stampdate), CreatedBy = HttpContext.User.Identity.Name, CreatedDate = DateTime.Now, UserIP = WebHelpers.GetIpAddress() + "~" + Request.UserHostName }) { efUserTimeStampHistory.Save(); } } else { foreach (var efUserTimeStampHistory in from history in ravenUserHistory from timeStamp in history.History select new UserTimeTrackHistory() { UserId = userNameIdDic[userName], UserName = userName, ClockInTime = DateTime.Parse(timeStamp.Start_time).TimeOfDay.ToString(), ClockOutTime = DateTime.Parse(timeStamp.End_time).TimeOfDay.ToString(), StampDate = DateTime.Parse(timeStamp.Stampdate), CreatedBy = HttpContext.User.Identity.Name, CreatedDate = DateTime.Now, UserIP = WebHelpers.GetIpAddress() + "~" + Request.UserHostName }) { efUserTimeStampHistory.Save(); } } } return(true); } catch (Exception ex) { return(false); } }