Example #1
0
        /// <summary>
        /// Remove this object from the db permenantly
        /// </summary>
        /// <returns>success status</returns>
        public virtual bool Remove(IAccount remover, StaffRank rank)
        {
            DataAccess.FileSystem.TemplateData accessor = new DataAccess.FileSystem.TemplateData();

            try
            {
                //Not allowed to remove stuff you didn't make unless you're an admin, TODO: Make this more nuanced for guilds
                if (rank <= CreatorRank && !remover.Equals(Creator))
                {
                    return(false);
                }

                //Remove from cache first
                TemplateCache.Remove(new TemplateCacheKey(this));

                //Remove it from the file system.
                accessor.ArchiveEntity(this);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Add it to the cache and save it to the file system
        /// </summary>
        /// <returns>the object with Id and other db fields set</returns>
        public virtual IKeyedData Create(IAccount creator, StaffRank rank)
        {
            DataAccess.FileSystem.TemplateData accessor = new DataAccess.FileSystem.TemplateData();

            try
            {
                if (Created != DateTime.MinValue)
                {
                    Save(creator, rank);
                }
                else
                {
                    //reset this guy's Id to the next one in the list
                    GetNextId();
                    Created     = DateTime.Now;
                    Creator     = creator;
                    CreatorRank = rank;

                    //Figure out automated approvals, always throw reviewonly in there
                    if (rank < StaffRank.Admin && ApprovalType != ContentApprovalType.ReviewOnly)
                    {
                        switch (ApprovalType)
                        {
                        case ContentApprovalType.None:
                            ApproveMe(creator, rank);
                            break;

                        case ContentApprovalType.Leader:
                            if (rank == StaffRank.Builder)
                            {
                                ApproveMe(creator, rank);
                            }

                            break;
                        }
                    }

                    PersistToCache();
                    accessor.WriteEntity(this);
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(null);
            }

            return(this);
        }
Example #3
0
        /// <summary>
        /// Change the approval status of this thing
        /// </summary>
        /// <returns>success</returns>
        public bool ChangeApprovalStatus(IAccount approver, StaffRank rank, ApprovalState newState)
        {
            //Can't approve/deny your own stuff
            if (rank < StaffRank.Admin && Creator.Equals(approver))
            {
                return(false);
            }

            DataAccess.FileSystem.TemplateData accessor = new DataAccess.FileSystem.TemplateData();
            ApproveMe(approver, rank, newState);

            LastRevised = DateTime.Now;

            PersistToCache();
            accessor.WriteEntity(this);

            return(true);
        }
Example #4
0
        /// <summary>
        /// Remove this object from the db permenantly
        /// </summary>
        /// <returns>success status</returns>
        public virtual bool SystemRemove()
        {
            DataAccess.FileSystem.TemplateData accessor = new DataAccess.FileSystem.TemplateData();

            try
            {
                //Remove from cache first
                TemplateCache.Remove(new TemplateCacheKey(this));

                //Remove it from the file system.
                accessor.ArchiveEntity(this);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(false);
            }

            return(true);
        }
Example #5
0
        /// <summary>
        /// Update the field data for this object to the db
        /// </summary>
        /// <returns>success status</returns>
        public virtual bool SystemSave()
        {
            DataAccess.FileSystem.TemplateData accessor = new DataAccess.FileSystem.TemplateData();

            try
            {
                if (Created == DateTime.MinValue)
                {
                    SystemCreate();
                }
                else
                {
                    //only able to edit its own crap
                    if (CreatorHandle != DataHelpers.SystemUserHandle)
                    {
                        return(false);
                    }

                    State          = ApprovalState.Approved;
                    ApproverHandle = DataHelpers.SystemUserHandle;
                    ApprovedOn     = DateTime.Now;
                    ApproverRank   = StaffRank.Builder;
                    LastRevised    = DateTime.Now;

                    PersistToCache();
                    accessor.WriteEntity(this);
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(false);
            }

            return(true);
        }
Example #6
0
        /// <summary>
        /// Add it to the cache and save it to the file system made by SYSTEM
        /// </summary>
        /// <returns>the object with Id and other db fields set</returns>
        public virtual IKeyedData SystemCreate()
        {
            DataAccess.FileSystem.TemplateData accessor = new DataAccess.FileSystem.TemplateData();

            try
            {
                if (Created != DateTime.MinValue)
                {
                    SystemSave();
                }
                else
                {
                    //reset this guy's Id to the next one in the list
                    GetNextId();
                    Created       = DateTime.Now;
                    CreatorHandle = DataHelpers.SystemUserHandle;
                    CreatorRank   = StaffRank.Builder;

                    PersistToCache();
                    accessor.WriteEntity(this);
                }


                State          = ApprovalState.Approved;
                ApproverHandle = DataHelpers.SystemUserHandle;
                ApprovedOn     = DateTime.Now;
                ApproverRank   = StaffRank.Builder;
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(null);
            }

            return(this);
        }
Example #7
0
        /// <summary>
        /// Update the field data for this object to the db
        /// </summary>
        /// <returns>success status</returns>
        public virtual bool Save(IAccount editor, StaffRank rank)
        {
            DataAccess.FileSystem.TemplateData accessor = new DataAccess.FileSystem.TemplateData();

            try
            {
                if (Created == DateTime.MinValue)
                {
                    Create(editor, rank);
                }
                else
                {
                    //Not allowed to edit stuff you didn't make unless you're an admin, TODO: Make this more nuanced for guilds
                    if (ApprovalType != ContentApprovalType.None && rank < StaffRank.Admin && !editor.Equals(Creator))
                    {
                        return(false);
                    }

                    //Disapprove of things first
                    State      = ApprovalState.Pending;
                    ApprovedBy = null;
                    ApprovedOn = DateTime.MinValue;

                    //Figure out automated approvals, always throw reviewonly in there
                    if (rank < StaffRank.Admin && ApprovalType != ContentApprovalType.ReviewOnly)
                    {
                        switch (ApprovalType)
                        {
                        case ContentApprovalType.None:
                            ApproveMe(editor, rank);
                            break;

                        case ContentApprovalType.Leader:
                            if (rank == StaffRank.Builder)
                            {
                                ApproveMe(editor, rank);
                            }

                            break;
                        }
                    }
                    else
                    {
                        //Staff Admin always get approved
                        ApproveMe(editor, rank);
                    }

                    LastRevised = DateTime.Now;

                    PersistToCache();
                    accessor.WriteEntity(this);
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
                return(false);
            }

            return(true);
        }