public void saveChanges()
        {
            using (var db = new PlanningContext())
            {
                update_period data = null;

                if (!this._isCreateMode)
                {
                    var id = Convert.ToInt32(this.update_period_id.Text);
                    data = db.update_period.Where(d => d.update_period_id == id).FirstOrDefault();
                    if (data == null)
                    {
                        this._mainInterface.statusText = $"ERROR: ID '{this.update_period_id.Text}' does not exist.";
                        return;
                    }
                }
                else
                {
                    data = new update_period();
                }

                data.update_period_id = Convert.ToInt32(this.update_period_id.Text);
                data.description      = /**/ (this.description.Text);
                data.is_active        = (bool)this.is_active.IsChecked;


                if (this._isCreateMode)
                {
                    db.update_period.Add(data);
                }
                db.SaveChanges();
            }
        }
Example #2
0
        public void deleteItem(object item)
        {
            if (item == null)
            {
                return;
            }

            update_period data = item as update_period;

            if (data == null)
            {
                return;
            }

            using (var db = new PlanningContext())
            {
                db.update_period.Remove(db.update_period.Where(d => d.update_period_id == data.update_period_id).First());
                db.SaveChanges();
            }
        }
        public static DateTime getNextUpdateTime(DateTime lastUpdate, float frequency, update_period updatePeriod)
        {
            switch (updatePeriod.description)
            {
            case "Second":
                return(lastUpdate.AddSeconds(frequency));

            case "Minute":
                return(lastUpdate.AddMinutes(frequency));

            case "Hour":
                return(lastUpdate.AddHours(frequency));

            case "Day":
                return(lastUpdate.AddDays(frequency));

            case "Week":
                return(lastUpdate.AddDays(7 * frequency));

            case "Month":
                var months = (int)Math.Round(frequency);
                return(lastUpdate.AddMonths(months));

            case "Year":
                var years = (int)Math.Round(frequency);
                return(lastUpdate.AddYears(years));

            default:
                throw new Exception($"You got here via black magic. Value = {updatePeriod}");
            }
        }