Пример #1
0
        /// <summary>
        /// Update all attributes to be what is passed in
        /// </summary>
        /// <param name="data"></param>
        /// <returns>Null or updated data</returns>
        public SchoolCalendarModel Update(SchoolCalendarModel data)
        {
            if (data == null)
            {
                return(null);
            }

            // Set date as modified
            data.Modified = true;

            // See if the updates make it match default, if so, need to clear the modified flag...
            var myDefault = new SchoolCalendarModel(data.Date);

            myDefault = SchoolCalendarBackendHelper.SetDefault(myDefault);

            if (myDefault.TimeEnd == data.TimeEnd && myDefault.TimeStart == data.TimeStart)
            {
                // It is back to defaults, so turn off the modified flag.
                data.Modified = false;
            }

            if (myDefault.SchoolDay != data.SchoolDay)
            {
                data.Modified = true;
            }

            var myReturn = DataSource.Update(data);

            return(myReturn);
        }
Пример #2
0
        /// <summary>
        /// Walks each existing date in the calendar, and resets the dates based on the defaults.
        /// </summary>
        public void ResetDefaults()
        {
            var startDate = DataSourceBackend.Instance.SchoolDismissalSettingsBackend.GetDefault().DayFirst; //school year start date
            var endDate   = DataSourceBackend.Instance.SchoolDismissalSettingsBackend.GetDefault().DayLast;  //school year end date
            var today     = UTCConversionsBackend.UtcToKioskTime(DateTimeHelper.Instance.GetDateTimeNowUTC()).Date;

            var currentDate = startDate;  //loop variable

            while (currentDate.CompareTo(endDate) <= 0)
            {
                var currentCalendarModel = ReadDate(currentDate);

                //if the calendar model for that date does not exit yet, create a new one
                if (currentCalendarModel == null)
                {
                    currentCalendarModel = new SchoolCalendarModel(currentDate);
                    currentCalendarModel = SchoolCalendarBackendHelper.SetDefault(currentCalendarModel);  //use current default settings
                    Create(currentCalendarModel);
                }

                //if the calendar model for that date is not modified, and is after today, reset to default
                if (!currentCalendarModel.Modified && currentDate.CompareTo(today) > 0)
                {
                    currentCalendarModel = SchoolCalendarBackendHelper.SetDefault(currentCalendarModel);  //use current default settings
                    Update(currentCalendarModel);
                }

                currentDate = currentDate.AddDays(1);
            }
        }
Пример #3
0
        /// <summary>
        /// Returns this record to default settings
        /// </summary>
        /// <returns>Null or valid data</returns>
        public SchoolCalendarModel SetDefault(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(null);
            }

            var myData = Read(id);

            if (myData == null)
            {
                return(null);
            }

            SchoolCalendarBackendHelper.SetDefault(myData);  //use current default settings

            var myReturn = Update(myData);

            return(myReturn);
        }
Пример #4
0
        /// <summary>
        /// Get the Default data set, and then add it to the current
        /// </summary>
        private void CreateDataSetDefault()
        {
            var startDate   = SchoolDismissalSettingsBackend.Instance.GetDefault().DayFirst; //school year start date
            var endDate     = SchoolDismissalSettingsBackend.Instance.GetDefault().DayLast;  //school year end date
            var currentDate = startDate;                                                     //loop variable

            while (currentDate.CompareTo(endDate) <= 0)
            {
                var newCalendarModel = new SchoolCalendarModel(currentDate);
                Create(newCalendarModel);

                SchoolCalendarBackendHelper.SetDefault(newCalendarModel);  //use default settings
                Update(newCalendarModel);

                currentDate = currentDate.AddDays(1);
            }

            //sort by date
            DataList = DataList.OrderBy(x => x.Date).ToList();
        }