Beispiel #1
0
        /// <summary>
        /// Validate and save person
        /// throws exception on validation/save problem
        /// </summary>
        /// <returns>new rowID</returns>
        public long SavePerson(ExtPerson person)
        {
            //validate
            string message = person.Person.Validate();

            if (message != null)
            {
                throw new Exception("Invalid person record: " + message);
            }

            //save
            DBUtil.WriteAny(person.Person, null, db =>
            {
                DBUtil.WritePersonIndex(db, person.Person);
                DBUtil.SavePersonCats(db, person.Person.RowId, person.SelectedCatIds);
            });

            //update cache
            return(person.Person.RowId);
        }
Beispiel #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);
        }