Exemplo n.º 1
0
        /// <summary>
        /// The BeforeDelete callback marks the Poco as deleted and prevent the execution of the actual deletion
        /// </summary>
        /// <param name="toDelete">The Poco object that will be soft deleted</param>
        /// <param name="parameters">You can specify true under [soft-deletable][disable] to delete for real</param>
        /// <returns></returns>
        public override bool?BeforeDelete(Poco toDelete, BusinessParameters parameters)
        {
            if (parameters != null && (parameters.GetDeepValue("soft-deletable.disable") as bool?) == true)
            {
                return(true);
            }

            //Marks the object as deleted
            toDelete.DeletedAt = DateTime.Now;
            business.Save(toDelete);

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// The after find callback filters the Find results so only the rows that aren't marked as deleted are returned
        /// </summary>
        /// <param name="type">The type of find</param>
        /// <param name="parameters">
        /// Can be used to adapt the functionality of AfterFind depending on the value of ["soft-deletable]["mode"]:
        ///   -If null (the default) or "not-deleted", than AfterFind will only return the rows that aren't marked as deleted
        ///   -If "only-deleted, the AfterFind will only return the rows that are marked as deleted
        ///   -If any other value (suggested is "all"), than all rows are returned regardless of their deletion status
        /// </param>
        /// <param name="results">The result obtained by the find</param>
        /// <returns>The filtered out results</returns>
        public override IQueryable <Poco> AfterFind(string type, BusinessParameters parameters, IQueryable <Poco> results = null)
        {
            string mode = parameters != null?parameters.GetDeepValue("soft-deletable.mode") as string : null;

            if (mode == null)
            {
                mode = "not-deleted";
            }

            if (mode == "not-deleted")
            {
                return(results.Where(m => m.DeletedAt == null));
            }
            else if (mode == "only-deleted")
            {
                return(results.Where(m => m.DeletedAt != null));
            }


            return(results);
        }