예제 #1
0
        /// <summary>
        /// Get private category
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static Category GetPrivateCategory(int userId)
        {
            var category = new Category()
            {
                Id       = 0,
                UserId   = userId,
                IsPublic = false,
                CanEdit  = true,
                Name     = "Private"
            };

            category.CanView   = PermissionBussiness.CanView(category, userId);
            category.Documents = category.CanView ? DocumentBussiness.GetUserPrivateDocument(userId) : new List <Document>();

            return(category);
        }
예제 #2
0
        /// <summary>
        /// Loads the document.
        /// </summary>
        /// <param name="id">The identifier of document.</param>
        /// <param name="userId">The user identifier.</param>
        /// <returns>Document.</returns>
        public static Document Load(Guid id, int userId)
        {
            var doc = DataAccess.Load(id);

            // Load the document data
            doc = doc.LoadDocumentData();
            // check permission
            doc.CanEdit = doc.UserId == userId;
            // check can edit
            if (doc.CategoryId != null)
            {
                doc.CanEdit = doc.CanEdit || PermissionBussiness.CanEdit(doc.CategoryId.Value, userId);
            }
            // check is private
            doc.IsPrivate = doc.CategoryId == null && doc.UserId == userId;
            return(doc);
        }
예제 #3
0
        /// <summary>
        ///     Get all public categories and user private docs
        /// </summary>
        /// <param name="userId">userId for permission</param>
        /// <returns></returns>
        public static List <Category> GetPublicCategories(int userId)
        {
            // get all public categories
            var categories = DataAccess.GetAllCategories().ToList();

            // get all data in categories
            foreach (var category in categories)
            {
                // get view permission
                category.CanView = PermissionBussiness.CanView(category, userId);

                // do not get documents if don't have view permission
                if (!category.CanView)
                {
                    category.Documents = new List <Document>();
                    continue;
                }

                // get documents
                var documents = DocumentBussiness.GetDocumentInCategory(category.Id, userId);

                // check permission
                var canEdit = PermissionBussiness.CanEdit(category.Id, userId);

                // replace reference documents
                if (canEdit)
                {
                    documents = documents.GetReferenceDocuments(userId).ToList();
                }

                category.Documents = documents;
            }

            // add private category
            categories.Add(GetPrivateCategory(userId));

            return(categories);
        }