Ejemplo n.º 1
0
        /// <summary>
        /// Reload the links in a box; to be called after the UI records changes in links
        /// </summary>
        public void UpdateLinks(ExtBox ebox)
        {
            using var db = new SystematizerContext();
            var links = DBUtil.LoadLinksFor(db, ebox.Box).ToList();

            ebox.Links = links;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validate and save box, keeping cache up to date.
        /// Saves from ExtBox.Repeats, instead of directly from Box.RepeatInfo!
        /// throws exception on validation/save problem
        /// </summary>
        /// <returns>new rowID</returns>
        public long SaveBox(ExtBox ebox, bool propagageToUI)
        {
            //validate
            string message = ebox.Box.Validate();

            if (message != null)
            {
                throw new Exception("Invalid task/note: " + message);
            }
            if (!Globals.AllowTasks && ebox.Box.TimeType != Constants.TIMETYPE_NONE)
            {
                throw new Exception("cannot store scheduled task in database not allowing tasks");
            }
            if (ebox.Box.TimeType != Constants.TIMETYPE_NONE && string.IsNullOrEmpty(ebox.Box.BoxTime))
            {
                throw new Exception("Scheduled tasks must have the date/time set");
            }

            //finalize storage formats
            ebox.Box.RepeatInfo = ebox.Repeats?.PackForStorage();

            //save
            DBUtil.WriteAny(ebox.Box, db =>
            {
                if (DBUtil.HasCircularParentage(db, ebox.Box.RowId, ebox.Box.ParentId))
                {
                    return(false);
                }
                return(true);
            },
                            db =>
            {
                DBUtil.WriteBoxIndex(db, ebox.Box);
            });

            //update cache
            var changes = Globals.BoxEditingPool.CheckIn(ebox.Box);

            Globals.BoxCache.UpdateCacheAfterSave(ebox.Box, changes, propagageToUI);
            return(ebox.Box.RowId);
        }