Ejemplo n.º 1
0
 /// <summary>
 /// Saves the current states and values.
 /// </summary>
 public void Save()
 {
     using (var access = new WorkdayAccess(this.database))
     {
         access.Save(this.AllDaysInMonth);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads all available days of the month into memory.
        /// </summary>
        /// <param name="year">The year for which the work day information are collected.</param>
        /// <param name="month">The month for which the work day information are collected.</param>
        private void GetAllDays(int year, int month)
        {
            using (var access = new WorkdayAccess(this.database))
            {
                var workdayInfos = this.GetOrCreate(year, month, access);

                this.AssignToUi(workdayInfos);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fetches already existing work day objects from the data source or creates them as needed.
        /// </summary>
        /// <param name="year">The current year for which the data is retreved.</param>
        /// <param name="month">The current month for which the data is retreved.</param>
        /// <param name="access">The data source collection.</param>
        /// <returns>Returns all available work day objects for the specified
        /// <paramref name="year"/> and <paramref name="month"/>.</returns>
        private IWorkdayInfo[] GetOrCreate(int year, int month, WorkdayAccess access)
        {
            // TODO: This method might be better suited for a dedicated data access class.
            // TODO: Move into another class.
            var workdayInfos = access.GetDays(year, month)
                               .ToArray();

            var expectedNumberOfDays = DateTime.DaysInMonth(year, month);

            if (workdayInfos.Length != expectedNumberOfDays)
            {
                workdayInfos = access.CreateMonth(
                    year,
                    month,
                    this.appSettings.DefaultWorkLength,
                    this.appSettings.DefaultBreakLength)
                               .ToArray();
            }

            return(workdayInfos);
        }