/// <summary> /// Persists the specifed <see cref="IWorkdayInfo"/> instance into the database. /// </summary> /// <param name="day">The current workday instance.</param> public void Update(IWorkdayInfo day) { var targetDay = this.Days.FindOne(d => d.WorkdayId == day.WorkdayId); MapValues(day, targetDay); this.Days.Update(targetDay); }
/// <summary> /// Assigns the values of the source object to the corresponding properties of the target object. /// </summary> /// <param name="source">Contains the values that will be assigned to the target object.</param> /// <param name="target">Receives the values of the source object.</param> private static void MapValues(IWorkdayInfo source, Workday target) { if (source.WorkdayId > 0) { target.WorkdayId = source.WorkdayId; } target.StartTime = source.StartTime; target.EndTime = source.EndTime; target.DefaultWorkLength = source.DefaultWorkLength; target.TotalBreakLength = source.TotalBreakLength; }
/// <summary> /// Calculates the difference from start time to current time. /// </summary> /// <param name="workday">The currently processed work day object.</param> /// <param name="currentTime">Defines the current time against which the work day time will be measured.</param> /// <returns>Returns a delta time that shows how long has already worked today.</returns> public static TimeSpan GetDeltaTime(IWorkdayInfo workday, DateTime currentTime) { var targetTime = GetTargetTime(workday.StartTime, workday.DefaultWorkLength, workday.TotalBreakLength); var deltaTime = (targetTime - currentTime).Duration(); if (targetTime > currentTime) { // In this case we're still working undertime deltaTime = deltaTime.Negate(); } return(deltaTime); }
/// <summary> /// Finds which <see cref="DateTime"/> is applicable. /// Returns <see cref="IWorkdayInfo.EndTime"/> if <see cref="IWorkdayInfo.EndTime"/> equals <see cref="DateTime.MinValue"/>; /// Otherwise, returns <see cref="DateTime.Now"/>. /// </summary> /// <param name="workday">The currently processed work day object.</param> /// <returns>Returns the found DateTime object.</returns> public static DateTime GetCurrentTime(IWorkdayInfo workday) { DateTime currentTime = workday.EndTime > DateTime.MinValue ? workday.EndTime : DateTime.Now; return(currentTime); }
/// <summary> /// Saves the values of the specified work day instance. /// </summary> /// <param name="day">The current workday instance.</param> public void Save(IWorkdayInfo day) { this.repository.Update(day); }