public UserTimeTrackHistoryMapped Get(int timeTrackId) { using (var dbContext = new TimeTrackingEntities()) { var userTimeTrackRecord = dbContext.UserTimeTrackHistories.FirstOrDefault(c => c.TimeTrackId == timeTrackId); if (userTimeTrackRecord != null) { var timeTrackMappedRecord = new UserTimeTrackHistoryMapped() { TimeTrackId = userTimeTrackRecord.TimeTrackId, UserName = userTimeTrackRecord.UserName, UserId = userTimeTrackRecord.UserId, ClockInTime = userTimeTrackRecord.ClockInTime, ClockOutTime = userTimeTrackRecord.ClockOutTime, StampDate = userTimeTrackRecord.StampDate, IsDeleted = userTimeTrackRecord.IsDeleted, CreatedBy = userTimeTrackRecord.CreatedBy, CreatedDate = userTimeTrackRecord.CreatedDate }; return(timeTrackMappedRecord); } return(new UserTimeTrackHistoryMapped()); } }
public static MembershipUserExtended Update(string userName, string firstName, string lastName, string title, double?hourlyRate, string address, string city, string state, string zip, string phone) { using (var dbContext = new TimeTrackingEntities()) { var extendedUser = dbContext.ExtendedUserProfiles.FirstOrDefault(ur => ur.UserName == userName); if (extendedUser != null) { extendedUser.FirstName = firstName; extendedUser.LastName = lastName; extendedUser.Title = title; extendedUser.HourlyRate = hourlyRate; extendedUser.Address = address; extendedUser.City = city; extendedUser.State = state; extendedUser.Zip = zip; extendedUser.Phone = phone; extendedUser.CreatedBy = HttpContext.Current.User == null || string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name) ? "sys" : HttpContext.Current.User.Identity.Name; extendedUser.CreatedDate = DateTime.Now; dbContext.SaveChanges(); return(GetUser(userName, userIsOnline: false)); } return(null); } }
public static bool UserNameExists(string userName) { using (var dbContext = new TimeTrackingEntities()) { return(dbContext.aspnet_Users.Any(c => c.UserName.Equals(userName))); } }
public static List <ExtendedUserProfile> GetExtendedProfileUsersCollection() { using (var dbContext = new TimeTrackingEntities()) { return(dbContext.ExtendedUserProfiles.ToList()); } }
public static void SetDefaultClockoutTimeStampToForgottenStamps(string userName) { var startDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]).Date; using (var dbContext = new TimeTrackingEntities()) { var userForgottenTimeOutStamps = (from utsh in dbContext.UserTimeTrackHistories where utsh.IsDeleted == false && utsh.UserName.ToLower().Equals(userName.ToLower()) && utsh.StampDate < startDate && (utsh.ClockInTime.Length > 0 && (utsh.ClockOutTime == null || utsh.ClockOutTime.Length == 0)) select utsh).ToList(); if (userForgottenTimeOutStamps.Any()) { var sDate = new DateTime(); foreach (var userForgottenTimeOutStamp in userForgottenTimeOutStamps) { var timeSpan = TimeSpan.Parse(WebConfigurationManager.AppSettings["AutomaticTimeOutLimit"]); userForgottenTimeOutStamp.ClockOutTime = String.Format("{0:t}", sDate.Add(timeSpan)); userForgottenTimeOutStamp.UpdatedBy = "sys"; userForgottenTimeOutStamp.UpdatedDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]); } } dbContext.SaveChanges(); } }
public static DailyTimeTrack GetDailyClockInOutTimeByDate(string userName, DateTime startDate, DateTime endDate) { var weekEndDateToSearchInDatabase = endDate.AddDays(1); using (var dbContext = new TimeTrackingEntities()) { var currentUser = dbContext.ExtendedUserProfiles.FirstOrDefault(c => c.UserName.ToLower().Equals(userName)); var userTimeTrackHistoryForRequestedDay = (from utsh in dbContext.UserTimeTrackHistories where utsh.IsDeleted == false && utsh.UserName.ToLower().Equals(userName.ToLower()) && (utsh.StampDate >= startDate && utsh.StampDate < weekEndDateToSearchInDatabase) && utsh.ClockInTime.Length > 0 select utsh).ToList(); if (userTimeTrackHistoryForRequestedDay.Any()) { var dailyTimeTrack = new DailyTimeTrack(startDate, currentUser.HourlyRate.HasValue ? currentUser.HourlyRate.Value : 0) { StampDate = startDate, TimeTrackList = GetTimeTrackList(userTimeTrackHistoryForRequestedDay, startDate). OrderByDescending(c => c.TimeTrackId).ThenByDescending( d => d.ClockInTime).ToList() }; return(dailyTimeTrack); } } return(new DailyTimeTrack()); }
/// <summary> /// Creates the Membership user and update Extended Membership user. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="password">The password.</param> /// <param name="email">The email.</param> /// <param name="firstName">The first name.</param> /// <param name="lastName">The last name.</param> /// <param name="title"></param> /// <param name="hourlyRate"></param> /// <param name="address"></param> /// <param name="city"></param> /// <param name="state"></param> /// <param name="zip"></param> /// <param name="phone"></param> /// <param name="createUserStatus"></param> /// <returns></returns> public static MembershipUserExtended CreateUser(string userName, string password, string email, string firstName, string lastName, string title, double?hourlyRate, string address, string city, string state, string zip, string phone, out MembershipCreateStatus createUserStatus) { if (password.Length < 6) { password = Membership.GeneratePassword(6, 0); } var user = Membership.CreateUser(userName, password, email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createUserStatus); if (createUserStatus == MembershipCreateStatus.Success) { using (var dbContext = new TimeTrackingEntities()) { try { var extendedUserProfile = dbContext.ExtendedUserProfiles.FirstOrDefault(u => u.UserName == user.UserName); if (extendedUserProfile == null) { extendedUserProfile = new ExtendedUserProfile { UserId = GetUserIdByUserName(user.UserName), UserName = user.UserName, FirstName = firstName, LastName = lastName, TempPassword = password, Title = title, HourlyRate = hourlyRate, Address = address, City = city, State = state, Zip = zip, Phone = phone, CreatedBy = HttpContext.Current.User == null || string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name) ? "sys" : HttpContext.Current.User.Identity.Name, CreatedDate = DateTime.Now }; dbContext.ExtendedUserProfiles.Add(extendedUserProfile); dbContext.SaveChanges(); } else { if (user != null) { Update(user.UserName, firstName, lastName, title, hourlyRate, address, city, state, zip, phone); } } return(GetUser(userName, userIsOnline: false)); } catch (Exception ex) { createUserStatus = MembershipCreateStatus.UserRejected; } } } return(null); }
/// <summary> /// Updates the specified membership and extented profile user. /// </summary> /// <param name="mUser">The m user.</param> /// <param name="firstName">The first name.</param> /// <param name="lastName">The last name.</param> /// <param name="title"></param> /// <param name="hourlyRate"></param> /// <param name="address"></param> /// <param name="city"></param> /// <param name="state"></param> /// <param name="zip"></param> /// <param name="phone"></param> /// <returns></returns> /// public static MembershipUserExtended Update(MembershipUser mUser, string firstName, string lastName, string title, double?hourlyRate, string address, string city, string state, string zip, string phone) { using (var dbContext = new TimeTrackingEntities()) { Membership.UpdateUser(mUser); return(Update(mUser.UserName, firstName, lastName, title, hourlyRate, address, city, state, zip, phone)); } }
public static CustomTimeTrack GetUserTimeTrackHistoryForSpecifiedPeriod(string userName, DateTime startDate, DateTime endDate) { var weekEndDateToSearchInDatabase = endDate.AddDays(1); var customTimeTrack = new CustomTimeTrack { CustomStartDate = startDate.Date, CustomEndDate = endDate.Date, UserName = userName, DailyTimeTracks = new List <DailyTimeTrack>() }; using (var dbContext = new TimeTrackingEntities()) { var currentUser = dbContext.ExtendedUserProfiles.FirstOrDefault(c => c.UserName.ToLower().Equals(userName)); customTimeTrack.EmployeeName = currentUser.FirstName + " " + currentUser.LastName; var userClockInOutTimings = (from utsh in dbContext.UserTimeTrackHistories where utsh.IsDeleted == false && utsh.UserName.ToLower().Equals(userName.ToLower()) && (utsh.StampDate >= startDate && utsh.StampDate < weekEndDateToSearchInDatabase) && utsh.ClockInTime.Length > 0 select utsh).ToList(); if (userClockInOutTimings.Any()) { var currentDay = startDate.Date; while (currentDay <= endDate.Date) { var dailyUserStampList = userClockInOutTimings.Where( daily => daily.StampDate >= currentDay && daily.StampDate < currentDay.AddDays(1)).ToList(); var dailyTimeTrack = new DailyTimeTrack(startDate, currentUser.HourlyRate.HasValue ? currentUser.HourlyRate.Value : 0) { StampDate = currentDay, TimeTrackList = GetTimeTrackList(dailyUserStampList, currentDay). OrderByDescending(c => c.ClockInTime).ThenByDescending( d => d.ClockOutTime).ToList() }; customTimeTrack.DailyTimeTracks.Add(dailyTimeTrack); customTimeTrack.DailyTimeTracks = customTimeTrack.DailyTimeTracks.OrderByDescending(c => c.StampDate).ToList(); currentDay = currentDay.AddDays(1); } } } return(customTimeTrack); }
public static Dictionary <string, Guid> GetUserIdUserNameList() { using (var dbContext = new TimeTrackingEntities()) { return((from user in dbContext.aspnet_Users select new { uName = user.UserName, uId = user.UserId }).ToDictionary(c => c.uName, c => c.uId)); } }
public static Dictionary <string, string> GetFullNameUserNameList() { using (var dbContext = new TimeTrackingEntities()) { return((from user in dbContext.ExtendedUserProfiles select new { uName = user.UserName, FullName = user.FirstName + " " + user.LastName }).ToDictionary(c => c.FullName, c => c.uName)); } }
public static WeeklyTimeTrack GetWeeklyClockInOutTimeByDate(string userName, DateTime startDate, DateTime endDate) { var weekEndDateToSearchInDatabase = endDate.AddDays(1); var weeklyTimeTrack = new WeeklyTimeTrack { WeekStartDate = startDate.Date, WeekEndDate = endDate.Date, DailyTimeTracks = new List <DailyTimeTrack>() }; using (var dbContext = new TimeTrackingEntities()) { var currentUser = dbContext.ExtendedUserProfiles.FirstOrDefault(c => c.UserName.ToLower().Equals(userName)); var userWeeklyClockInOutTimings = (from utsh in dbContext.UserTimeTrackHistories where utsh.IsDeleted == false && utsh.UserName.ToLower().Equals(userName.ToLower()) && (utsh.StampDate >= startDate && utsh.StampDate < weekEndDateToSearchInDatabase) && utsh.ClockInTime.Length > 0 select utsh).ToList(); if (userWeeklyClockInOutTimings.Any()) { var weekDay = startDate.Date; while (weekDay.Date <= endDate.Date) { var dailyUserStampList = userWeeklyClockInOutTimings.Where( daily => daily.StampDate >= weekDay && daily.StampDate < weekDay.AddDays(1)).ToList(); var dailyTimeTrack = new DailyTimeTrack(startDate, currentUser.HourlyRate.HasValue ? currentUser.HourlyRate.Value : 0) { StampDate = weekDay, TimeTrackList = GetTimeTrackList(dailyUserStampList, weekDay). OrderByDescending(c => c.ClockInTime).ThenByDescending( d => d.ClockOutTime).ToList() }; weeklyTimeTrack.DailyTimeTracks.Add(dailyTimeTrack); weeklyTimeTrack.DailyTimeTracks = weeklyTimeTrack.DailyTimeTracks.OrderByDescending(c => c.StampDate).ToList(); weekDay = weekDay.AddDays(1); } } } return(weeklyTimeTrack); }
public static Guid GetUserIdByUserName(string userName) { using (var dbContext = new TimeTrackingEntities()) { var user = dbContext.aspnet_Users.FirstOrDefault(c => c.UserName.Equals(userName)); if (user == null) { throw new Exception("user does not exists"); } return(user.UserId); } }
public static bool DeleteTimeTrackRecord(int timeTrackId, string loggedInUserName) { using (var dbContext = new TimeTrackingEntities()) { var userTimeTrackRecord = dbContext.UserTimeTrackHistories.FirstOrDefault(utsh => utsh.TimeTrackId == timeTrackId); if (userTimeTrackRecord != null && userTimeTrackRecord.TimeTrackId > 0) { dbContext.UserTimeTrackHistories.Remove(userTimeTrackRecord); dbContext.SaveChanges(); return(true); } return(false); } }
//public Guid RoleId { get; set; } //public string RoleName { get; set; } public List <WebMenuRole> GetMenuItemsForRoles(List <string> roleNames) { using (var dbContext = new TimeTrackingEntities()) { var menuRole = (from wm in dbContext.WebMenus from role in wm.aspnet_Roles where roleNames.Contains(role.RoleName) select new WebMenuRole { MenuId = wm.MenuId, MenuTitle = wm.Title, Action = wm.Action, Controller = wm.Controller, OrderNumber = wm.OrderNumber, }).Distinct().OrderBy(c => c.OrderNumber).ToList(); return(menuRole); } }
public static void GetUserAndHistory(string userName, DateTime startDate) { var weekEndDateToSearchInDatabase = startDate.AddDays(2); using (var dbContext = new TimeTrackingEntities()) { var userClockInOutTimeList = (from utsh in dbContext.UserTimeTrackHistories join user in dbContext.ExtendedUserProfiles on utsh.UserId equals user.UserId where utsh.IsDeleted == false && utsh.UserName.ToLower().Equals(userName.ToLower()) && utsh.ClockInTime.Length > 0 select new { historylist = utsh, currentuser = user }).ToList(); var user1 = userClockInOutTimeList.FirstOrDefault().currentuser; var history = userClockInOutTimeList.FirstOrDefault().historylist; } }
public static List <MembershipUserExtended> GetExtendedMembershipUserCollection() { var membershipUserCollection = GetMembershipUserCollection(); var extendedProfileUserCollection = GetExtendedProfileUsersCollection(); var extenderMembershipCollection = new List <MembershipUserExtended>(); using (var dbContext = new TimeTrackingEntities()) { extenderMembershipCollection.AddRange( from object mu in membershipUserCollection let extenderUser = extendedProfileUserCollection.FirstOrDefault(c => c.UserName == ((MembershipUser)mu).UserName) where extenderUser != null select new MembershipUserExtended((MembershipUser)mu, extenderUser.FirstName, extenderUser.LastName, extenderUser.Title, extenderUser.HourlyRate, extenderUser.Address, extenderUser.City, extenderUser.State, extenderUser.Zip, extenderUser.Phone, extenderUser.CreatedBy, extenderUser.CreatedDate, extenderUser.UpdatedBy, extenderUser.UpdatedDate, extenderUser.TempPassword) ); return(extenderMembershipCollection); } }
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(); } }
/// <summary> /// Gets the extended membership profile user. /// </summary> /// <param name="username">The username.</param> /// <param name="userIsOnline"></param> /// <returns></returns> public static MembershipUserExtended GetUser(string username, bool userIsOnline) { using (var dbContext = new TimeTrackingEntities()) { MembershipUser user = Membership.GetUser(username, userIsOnline); if (user != null) { var upUser = dbContext.ExtendedUserProfiles.FirstOrDefault(eu => eu.UserName == user.UserName); if (upUser != null) { return(new MembershipUserExtended(user, upUser.FirstName, upUser.LastName, upUser.Title, upUser.HourlyRate, upUser.Address, upUser.City, upUser.State, upUser.Zip, upUser.Phone, upUser.CreatedBy, upUser.CreatedDate, upUser.UpdatedBy, upUser.UpdatedDate, upUser.TempPassword)); } return(new MembershipUserExtended()); } return(new MembershipUserExtended()); } }
public static DailyTimeTrack GetCurrentDayClockInOutTime(string userName) { var startDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]).Date; var endDate = startDate.AddDays(1); using (var dbContext = new TimeTrackingEntities()) { var currentUser = dbContext.ExtendedUserProfiles.FirstOrDefault(c => c.UserName.ToLower().Equals(userName)); var userClockInOutTimeList = (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 select utsh).ToList(); if (userClockInOutTimeList.Any()) { var userTimeStampHistory = userClockInOutTimeList.FirstOrDefault(); if (userTimeStampHistory != null) { var dailyTimeTrack = new DailyTimeTrack(userTimeStampHistory.StampDate, currentUser.HourlyRate.HasValue ? currentUser.HourlyRate.Value : 0) { TimeTrackList = GetTimeTrackList(userClockInOutTimeList, userTimeStampHistory.StampDate). OrderByDescending(c => c.ClockInTime).ThenByDescending( d => d.ClockOutTime).ToList() }; dailyTimeTrack.SubmitButtonText = dailyTimeTrack.TimeTrackList.Any(c => c.ClockOutTime == null) ? WebConfigurationManager.AppSettings["ClockOutText"] : WebConfigurationManager.AppSettings["ClockInText"]; return(dailyTimeTrack); } } return(new DailyTimeTrack()); } }
public void Add(List <string> roleNames) { using (var dbContext = new TimeTrackingEntities()) { } }
public EmployeeServices() { _ttContext = new TimeTrackingEntities(); }
public static TimeTrackErrorViewModel UpdateClockInOutTime(int timeTrackId, string stampDate, string selectedUser, string clockInTime, string clockOutTime, string updatedBy) { using (var dbContext = new TimeTrackingEntities()) { var startDate = DateTime.Parse(stampDate); var endDate = startDate.AddDays(1); var userTimeTrackRecordForStampedDate = dbContext.UserTimeTrackHistories .Where(utsh => utsh.IsDeleted == false && utsh.UserName.ToLower().Equals(selectedUser.ToLower()) && (utsh.StampDate >= startDate && utsh.StampDate < endDate)) .ToList(); var userTimeTrackRecord = userTimeTrackRecordForStampedDate.FirstOrDefault(utsh => utsh.TimeTrackId == timeTrackId); var indexOfSelectedRecord = userTimeTrackRecordForStampedDate.IndexOf(userTimeTrackRecord); var errorMessage = new StringBuilder(); var errorCount = 0; var sDate = new DateTime(); if (userTimeTrackRecord != null) { DateTime updatedClockInDateTime; DateTime updatedClockOutDateTime; if (DateTime.TryParse(clockInTime, out updatedClockInDateTime) && DateTime.TryParse(clockOutTime, out updatedClockOutDateTime)) { var updatedClockInTime = updatedClockInDateTime.TimeOfDay; var updatedClockOutTime = updatedClockOutDateTime.TimeOfDay; // CHECK IF userTimeTrackRecord object has CloclOutTime set. IF NOT SET IT WITH PROVIDED ClockOutTime if (string.IsNullOrEmpty(userTimeTrackRecord.ClockOutTime)) { userTimeTrackRecord.ClockOutTime = String.Format("{0:t}", sDate.Add(updatedClockOutTime)); } var previousTimeTrackClockOutTimeRecord = string.Empty; var nextTimeTrackClockInTimeRecord = string.Empty; if (indexOfSelectedRecord > 0 && (indexOfSelectedRecord - 1) >= 0) { previousTimeTrackClockOutTimeRecord = userTimeTrackRecordForStampedDate[indexOfSelectedRecord - 1].ClockOutTime; } if ((indexOfSelectedRecord + 1) < userTimeTrackRecordForStampedDate.Count) { nextTimeTrackClockInTimeRecord = userTimeTrackRecordForStampedDate[indexOfSelectedRecord + 1].ClockInTime; } if (updatedClockOutTime.CompareTo(updatedClockInTime) == -1) { errorMessage.Append("Updated Clock Out time can not be earlier than Updated Clock In time."); errorCount += 1; } else if (!updatedClockInTime.Equals(DateTime.Parse(userTimeTrackRecord.ClockInTime).TimeOfDay)) { if ((!string.IsNullOrEmpty(previousTimeTrackClockOutTimeRecord) && updatedClockInTime.CompareTo( DateTime.Parse(previousTimeTrackClockOutTimeRecord).TimeOfDay) == -1) || (!string.IsNullOrEmpty(nextTimeTrackClockInTimeRecord) && updatedClockInTime.CompareTo(DateTime.Parse(nextTimeTrackClockInTimeRecord).TimeOfDay) == 1)) { // error clock in time cannot be earlier then previous checkout time and can not be later then next clockout time errorMessage.Append( "Updated Clock In time can not be earlier than previous clock out time or later than earlier clock in time"); errorCount += 1; } } else if (!updatedClockOutTime.Equals(DateTime.Parse(userTimeTrackRecord.ClockOutTime).TimeOfDay)) { // Clock Out time has changed if ((!string.IsNullOrEmpty(previousTimeTrackClockOutTimeRecord) && updatedClockOutTime.CompareTo( DateTime.Parse(previousTimeTrackClockOutTimeRecord).TimeOfDay) == -1) || (!string.IsNullOrEmpty(nextTimeTrackClockInTimeRecord) && updatedClockOutTime.CompareTo( DateTime.Parse(nextTimeTrackClockInTimeRecord).TimeOfDay) == 1)) { errorMessage.Append( "Updated Clock Out time can not be earlier than previous clock out time or later than earlier clock in time"); errorCount += 1; } } else if ( !updatedClockInTime.Equals(DateTime.Parse(userTimeTrackRecord.ClockInTime).TimeOfDay) && (!updatedClockOutTime.Equals( DateTime.Parse(userTimeTrackRecord.ClockOutTime).TimeOfDay))) { // Both clock in and out time has been changed if ( updatedClockInTime.CompareTo( DateTime.Parse(previousTimeTrackClockOutTimeRecord).TimeOfDay) == -1 || updatedClockInTime.CompareTo( DateTime.Parse(nextTimeTrackClockInTimeRecord).TimeOfDay) == 1) { errorMessage.Append( "Updated Clock Out time can not be earlier than previous clock out time or later than earlier clock in time"); errorCount += 1; } if ( updatedClockOutTime.CompareTo( DateTime.Parse(previousTimeTrackClockOutTimeRecord).TimeOfDay) == -1 || updatedClockOutTime.CompareTo( DateTime.Parse(nextTimeTrackClockInTimeRecord).TimeOfDay) == 1) { errorMessage.Append( "Updated Clock Out time can not be earlier than previous clock out time or later than earlier clock in time"); errorCount += 1; } } if (errorCount == 0) { userTimeTrackRecord.ClockInTime = String.Format("{0:t}", sDate.Add(updatedClockInTime)); userTimeTrackRecord.ClockOutTime = String.Format("{0:t}", sDate.Add(updatedClockOutTime)); userTimeTrackRecord.UpdatedBy = updatedBy; userTimeTrackRecord.UpdatedDate = WebHelpers.GetCurrentDateTimeByTimeZoneId(WebConfigurationManager.AppSettings["UserTimeZoneId"]); dbContext.SaveChanges(); } return(new TimeTrackErrorViewModel(GetTimeTrackFromUserTimeTrackHistory(dbContext.UserTimeTrackHistories.FirstOrDefault(utsh => utsh.TimeTrackId == timeTrackId)), errorMessage.ToString())); } return(new TimeTrackErrorViewModel(GetTimeTrackFromUserTimeTrackHistory(dbContext.UserTimeTrackHistories.FirstOrDefault(utsh => utsh.TimeTrackId == timeTrackId)), "Please provide a valid Clock In/Clock Out time.")); } return(new TimeTrackErrorViewModel(GetTimeTrackFromUserTimeTrackHistory(dbContext.UserTimeTrackHistories.FirstOrDefault(utsh => utsh.TimeTrackId == timeTrackId)), string.Empty)); } }