Ejemplo n.º 1
0
 public Account tryLoginAccountByAccount(Account account)
 {
     using (var db = new BaseDbContext())
     {
         var     encPassword = account.MakeEncryptedPassword(account.Password);
         Account _account    = findAccountByAccountUsername(account);
         if (_account != null)
         {
             if (_account.Password == encPassword)
             {
                 if (!_account.isEnabled)
                 {
                     return(_account);
                 }
                 else if (_account.LoginFails < 3)
                 {
                     db.Entry(_account).State = EntityState.Modified;
                     _account.LastLogin       = DateTimeExtensions.GetServerTime();
                     _account.LoginFails      = 0;
                     db.SaveChanges();
                     SessionPersister.createSessionForAccount(_account);
                 }
             }
             else
             {
                 db.Entry(_account).State = EntityState.Modified;
                 _account.LoginFails      = _account.LoginFails + 1;
                 db.SaveChanges();
                 return(null);
             }
         }
         return(_account);
     }
 }
Ejemplo n.º 2
0
        public string tryUnpublishArticle(Article article, bool allLocales)
        {
            using (var db = new BaseDbContext())
            {
                var _article = article;
                if (_article == null)
                {
                    return("Item not found");
                }
                if (!_article.isApproved)
                {
                    return("Item not approved");
                }

                var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(_article);
                if (error != null)
                {
                    return(error);
                }

                deletePublishedArticlesByBaseArticle(article);

                var local = db.articleDb
                            .Local
                            .FirstOrDefault(f => f.BaseArticleID == _article.BaseArticleID);
                if (local != null)
                {
                    db.Entry(local).State = EntityState.Detached;
                }

                db.Entry(_article).State = EntityState.Modified;
                _article.isPublished     = false;
                _article.datePublished   = null;
                _article.publishedBy     = null;
                db.SaveChanges();

                if (allLocales)
                {
                    var _localeArticles = ArticleDbContext.getInstance().findAllLocaleArticlesByBaseArticleAndVersion(article, article.Lang, db);
                    foreach (var _a in _localeArticles)
                    {
                        db.Entry(_a).State = EntityState.Modified;
                        _a.isPublished     = false;
                        _a.datePublished   = null;
                        _a.publishedBy     = null;
                        db.SaveChanges();
                    }
                }

                AuditLogDbContext.getInstance().createAuditLogArticleAction(article, AuditLogDbContext.ACTION_UNPUBLISH);

                return(null);
            }
        }
Ejemplo n.º 3
0
        public String tryRequestUnapproval(Article article, bool allLocales)
        {
            var _article = findArticleByID(article.ArticleID);

            if (_article == null)
            {
                return("Item not found");
            }

            if (_article.isApproved)
            {
                return("Item is already approved");
            }

            if (_article.isUnapproved)
            {
                return("item is already unapproved");
            }

            using (var db = new BaseDbContext())
            {
                db.Entry(_article).State = EntityState.Modified;
                _article.isApproved      = false;
                _article.isUnapproved    = true;
                _article.isFrozen        = true;
                _article.dateApproved    = null;
                _article.dateUnapproved  = DateTimeExtensions.GetServerTime();
                _article.approvalRemarks = article.approvalRemarks;
                _article.approvedBy      = SessionPersister.account.AccountID;

                if (allLocales)
                {
                    var _localeArticles = findAllLocaleArticlesByBaseArticleAndVersion(article, article.Lang, db);
                    foreach (var _a in _localeArticles)
                    {
                        db.Entry(_a).State = EntityState.Modified;
                        _a.isApproved      = false;
                        _a.isUnapproved    = true;
                        _a.isFrozen        = true;
                        _a.dateApproved    = null;
                        _a.dateUnapproved  = DateTimeExtensions.GetServerTime();
                        _a.approvalRemarks = article.approvalRemarks;
                        _a.approvedBy      = SessionPersister.account.AccountID;
                    }
                }

                db.SaveChanges();

                AuditLogDbContext.getInstance().createAuditLogArticleAction(article, AuditLogDbContext.ACTION_UNAPPROVE);

                return(null);
            }
        }
        public string edit(Constant item)
        {
            List <string> modified_fields = new List <string>();

            using (var db = new BaseDbContext())
            {
                var constant = findByID(item.ConstantID);

                var result = ConstantDbContext.getInstance().findByKeyNoTracking(item.Key);
                if (result != null)
                {
                    if (item.ConstantID != result.ConstantID)
                    {
                        return("This Constant Key already exists. Please enter another Constant Key.");
                    }
                }

                var local = db.constantDb
                            .Local
                            .FirstOrDefault(f => f.ConstantID == item.ConstantID);
                if (local != null)
                {
                    if (local.Key != item.Key)
                    {
                        modified_fields.Add("Key");
                    }
                    if (local.Value != item.Value)
                    {
                        modified_fields.Add("Value");
                    }
                    if (local.isActive != item.isActive)
                    {
                        modified_fields.Add("isActive");
                    }
                    if (local.Desc != item.Desc)
                    {
                        modified_fields.Add("Desc");
                    }

                    db.Entry(local).State = EntityState.Detached;
                }

                db.Entry(constant).State = EntityState.Modified;

                constant.Value    = item.Value;
                constant.Key      = item.Key;
                constant.isActive = item.isActive;

                db.SaveChanges();
            }
            AuditLogDbContext.getInstance().createAuditLogConstantAction(item, AuditLogDbContext.ACTION_EDIT, modified_fields);
            return(null);
        }
Ejemplo n.º 5
0
        public String tryDeleteArticle(Article article, bool isRecursive)
        {
            using (var db = new BaseDbContext())
            {
                var _article = findArticleByID(article.ArticleID);
                if (_article == null)
                {
                    return("Item not found");
                }
                if (_article.isFrozen)
                {
                    return(ResHelper.S("itemisfrozen"));
                }

                var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(_article);
                if (error != null)
                {
                    return(error);
                }

                AuditLogDbContext.getInstance().createAuditLogArticleAction(_article, AuditLogDbContext.ACTION_DELETE);

                if (isRecursive)
                {
                    if (frozenArticleAlreadyPresents(_article))
                    {
                        error = ResHelper.S("itemisfrozen");
                        return(error);
                    }


                    var articlesToDelete = db.articleDb.Where((acc) => acc.BaseArticleID == _article.BaseArticleID);
                    foreach (var a in articlesToDelete)
                    {
                        db.Entry(a).State = EntityState.Deleted;
                    }
                    db.SaveChanges();
                    return(null);
                }
                else
                {
                    db.Entry(article).State = EntityState.Deleted;
                }
                db.SaveChanges();

                return(null);
            }
        }
        public string delete(Category category, bool isRecursive)
        {
            using (var db = new BaseDbContext())
            {
                var articles     = ArticleDbContext.getInstance().findArticlesByCategoryID(category.ItemID);
                var contentPages = ContentPageDbContext.getInstance().findArticlesByCategoryID(category.ItemID);

                if (articles.Count > 0 || contentPages.Count > 0)
                {
                    return("Could not delete this category when it is linked with any article / content page.");
                }

                if (isRecursive)
                {
                    // var children = findCategorysByParentID(category.parentItemID);
                    /// for (int i = children.Count() - 1; i >= 0; i--)
                    // {
                    //     delete(children.ElementAt(i), true);
                    // }
                }

                AuditLogDbContext.getInstance().createAuditLogCategoryAction(category, AuditLogDbContext.ACTION_DELETE);

                db.Entry(category).State = EntityState.Deleted;
                db.SaveChanges();

                return(null);
            }
        }
Ejemplo n.º 7
0
        public string tryEdit(Account account)
        {
            string  error    = null;
            Account _account = findAccountByID(account.AccountID);

            _account.Username = account.Username;
            _account.Email    = account.Email;

            error = tryCheckUsername(_account);
            if (error != null)
            {
                return(error);
            }

            error = tryCheckEmail(_account);
            if (error != null)
            {
                return(error);
            }


            if (_account.Password != account.Password)
            {
                var rawPassword = account.Password;
                error                    = tryChangePassword(account, rawPassword);
                _account.Password        = account.Password;
                _account.ConfirmPassword = account.ConfirmPassword;
                if (error != null)
                {
                    return(error);
                }
                else
                {
                    using (var db = new BaseDbContext())
                    {
                        db.Entry(_account).State = EntityState.Modified;
                        _account.LoginFails      = 0;

                        if (SessionPersister.account != null && _account.AccountID != SessionPersister.account.AccountID)
                        {
                            _account.NeedChangePassword = true;

                            EmailHelper.SendEmailToAccountOnPasswordReset(_account, rawPassword);
                        }

                        db.SaveChanges();
                    }
                }
            }

            error = tryChangeProfile(account);
            if (error != null)
            {
                return(error);
            }

            return(null);
        }
Ejemplo n.º 8
0
        public string tryChangePassword(Account account, String newPassword, bool shouldInvalidateResetPasswordNeeds = false)
        {
            var     encPassword = account.MakeEncryptedPassword(newPassword);
            Account _account    = findAccountByID(account.AccountID);

            if (_account != null)
            {
                var passwords = _account.historyPasswordList();

                // check if this password is already used in the list
                // if yes, then return error message
                for (var i = 0; i < passwords.Count; i++)
                {
                    var pass = passwords[i];
                    if (pass == encPassword)
                    {
                        return("New password must be different from your 9 previously used passwords");
                    }
                }



                using (var db = new BaseDbContext())
                {
                    db.Entry(_account).State        = EntityState.Modified;
                    _account.Password               = encPassword;
                    _account.ConfirmPassword        = encPassword;
                    _account.LastPasswordModifiedAt = DateTimeExtensions.GetServerTime();

                    if (shouldInvalidateResetPasswordNeeds)
                    {
                        _account.NeedChangePassword = false;
                    }

                    passwords.Add(encPassword);
                    while (passwords.Count > 9)
                    {
                        passwords.RemoveAt(0);
                    }

                    _account.historyPasswords = _account.historyPasswordsFromList(passwords);
                    db.SaveChanges();

                    SessionPersister.updateSessionForAccount();

                    account.Password        = _account.Password;
                    account.ConfirmPassword = _account.ConfirmPassword;
                }

                AuditLogDbContext.getInstance().createAuditLogAccountAction(account, AuditLogDbContext.ACTION_CHANGE_PASSWORD);
                return(null);
            }
            else
            {
                return("Change password failed: Account not found");
            }
        }
        public string editNotification(SystemMaintenanceNotification item)
        {
            List<string> modified_fields = new List<string>();

            using (var db = new BaseDbContext())
            {
                var local = db.systemMaintenanceNotificationDb
                            .Local
                            .FirstOrDefault(f => f.NotificationID == item.NotificationID);

                if (local != null)
                {
                    if (local.name_en != item.name_en) { modified_fields.Add("name_en"); }
                    if (local.name_zh != item.name_zh) { modified_fields.Add("name_zh"); }
                    if (local.name_cn != item.name_cn) { modified_fields.Add("name_cn"); }
                    if (local.desc_en != item.desc_en) { modified_fields.Add("desc_en"); }
                    if (local.desc_zh != item.desc_zh) { modified_fields.Add("desc_zh"); }
                    if (local.desc_cn != item.desc_cn) { modified_fields.Add("desc_cn"); }
                    if (local.startDate != item.startDate) { modified_fields.Add("startDate"); } 
                    if (local.endDate != item.endDate) { modified_fields.Add("endDate"); }
                    if (local.isActive != item.isActive) { modified_fields.Add("isActive"); }
                  //  if (local.level != item.level) { modified_fields.Add("level"); }

                    db.Entry(local).State = EntityState.Detached;
                }

                var startDate = item.startDate;
                if (startDate == null)
                {
                    return "Start Date must be set for creating scheduled notification.";
                }

                var endDate = item.endDate;
                if (endDate == null)
                {
                    return "End Date must be set for creating scheduled notification.";
                }

                db.Entry(item).State = EntityState.Modified;
                db.SaveChanges();
            }
            AuditLogDbContext.getInstance().createAuditLogSystemMaintenanceNotificationAction(item, AuditLogDbContext.ACTION_EDIT, modified_fields);
            return null;
        }
        // ARTICLE PUBLISHER ONLY

        public string tryPublishArticle(ContentPage article, bool allLocales)
        {
            var _article = ContentPageDbContext.getInstance().findArticleByVersionAndLang(article.BaseArticleID, article.Version, "en");

            if (_article == null)
            {
                return("Item not found");
            }
            if (!_article.isApproved)
            {
                return("Item not approved");
            }

            var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(_article);

            if (error != null)
            {
                return(error);
            }

            deletePublishedArticlesByBaseArticle(article);
            addArticleToPublished(article);

            db.Entry(_article).State = EntityState.Modified;
            _article.isPublished     = true;
            _article.datePublished   = DateTimeExtensions.GetServerTime();
            _article.publishedBy     = SessionPersister.account.AccountID;

            if (allLocales)
            {
                var _localeArticles = ContentPageDbContext.getInstance().findAllLocaleArticlesByBaseArticleAndVersion(article, article.Lang);
                foreach (var _a in _localeArticles)
                {
                    db.Entry(_a).State = EntityState.Modified;
                    _a.isPublished     = true;
                    _a.datePublished   = DateTimeExtensions.GetServerTime();
                    _a.publishedBy     = SessionPersister.account.AccountID;
                }
            }

            db.SaveChanges();

            return(null);
        }
Ejemplo n.º 11
0
        // ARTICLE EDITOR & APPROVER ONLY

        #region "Approval"

        // ARTICLE EDITOR REQUEST FOR APPROVAL

        public String trySubmitRequestForApproval(Article article, bool allLocales)
        {
            var _article = findArticleByID(article.ArticleID);

            if (_article == null)
            {
                return("Item not found");
            }
            if (_article.isFrozen)
            {
                return(ResHelper.S("itemisfrozen"));
            }

            var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(_article);

            if (error != null)
            {
                return(error);
            }

            using (var db = new BaseDbContext())
            {
                db.Entry(_article).State      = EntityState.Modified;
                _article.isRequestingApproval = true;
                _article.isFrozen             = true;

                if (allLocales)
                {
                    var _localeArticles = findAllLocaleArticlesByBaseArticleAndVersion(article, article.Lang, db);
                    foreach (var _a in _localeArticles)
                    {
                        db.Entry(_a).State            = EntityState.Modified;
                        _article.isRequestingApproval = true;
                        _article.isFrozen             = true;
                    }
                }

                db.SaveChanges();

                AuditLogDbContext.getInstance().createAuditLogArticleAction(article, AuditLogDbContext.ACTION_SUBMIT_FOR_APPROVAL);

                return(null);
            }
        }
 public string delete(Constant item)
 {
     using (var db = new BaseDbContext())
     {
         db.Entry(item).State = EntityState.Deleted;
         db.SaveChanges();
     }
     AuditLogDbContext.getInstance().createAuditLogConstantAction(item, AuditLogDbContext.ACTION_DELETE);
     return(null);
 }
 public string deactivateNotification(SystemMaintenanceNotification item)
 {
     using (var db = new BaseDbContext())
     {
         db.Entry(item).State = EntityState.Modified;
         item.isActive = false;
         db.SaveChanges();
     }
     AuditLogDbContext.getInstance().createAuditLogSystemMaintenanceNotificationAction(item, AuditLogDbContext.ACTION_DEACTIVATE);
     return null;
 }
Ejemplo n.º 14
0
        public String tryCreateNewLocaleArticle(Article article)
        {
            var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(article);

            if (error != null)
            {
                return(error);
            }

            if (article.BaseArticleID != 0)
            {
                if (article.Version == 0)
                {
                    var latestArticle = findLatestArticleByBaseArticle(article, article.Lang);
                    article.Version = latestArticle.Version;

                    error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(latestArticle);
                    if (error != null)
                    {
                        return(error);
                    }
                }
            }

            if (articleWithSameVersionAndLangAlreadyPresents(article))
            {
                return("Article with the same version and language already presents");
            }

            using (var db = new BaseDbContext())
            {
                article.createdBy = SessionPersister.account.AccountID;

                if (article.Desc != null)
                {
                    article.Desc = article.Desc.Replace("cms/ckfinder/userfiles", "ckfinder/userfiles");
                }

                db.articleDb.Add(article);
                db.SaveChanges();


                if (article.BaseArticleID == 0)
                {
                    db.Entry(article).State = EntityState.Modified;
                    article.BaseArticleID   = article.ArticleID;
                    db.SaveChanges();
                }
            }

            return(null);
        }
Ejemplo n.º 15
0
        public string edit(AccountGroup item)
        {
            var accountGroup = findGroupByID(item.AccountGroupID);

            var result = AccountGroupDbContext.getInstance().findGroupsByNameNoTracking(item.Name);

            if (result != null && result.Count > 0)
            {
                foreach (var res in result)
                {
                    if (item.AccountGroupID != res.AccountGroupID)
                    {
                        return("This Account Group Name already exists. Please enter another Account Group Name.");
                    }
                }
            }

            item.AccessibleCategories         = String.Join(",", item.getAccessibleCategoryList().ToArray());
            accountGroup.AccessibleCategories = item.AccessibleCategories;

            using (var db = new BaseDbContext())
            {
                var local = db.accountGroupDb
                            .Local
                            .FirstOrDefault(f => f.AccountGroupID == item.AccountGroupID);
                if (local != null)
                {
                    db.Entry(local).State = EntityState.Detached;
                }

                db.Entry(accountGroup).State = EntityState.Modified;

                db.SaveChanges();
                return(null);
            }
        }
Ejemplo n.º 16
0
        public string delete(AccountGroup item)
        {
            var accounts = AccountDbContext.getInstance().findAccountsByAccountGroup(item);

            if (accounts.Count > 0)
            {
                return("Cannot delete account group which exists account(s).");
            }

            using (var db = new BaseDbContext())
            {
                db.Entry(item).State = EntityState.Deleted;
                db.SaveChanges();
                return(null);
            }
        }
Ejemplo n.º 17
0
        public string tryDeleteAccount(Account account)
        {
            AuditLogDbContext.getInstance().createAuditLogAccountAction(account, AuditLogDbContext.ACTION_DELETE);

            Account _account = findAccountByID(account.AccountID);

            if (_account != null)
            {
                using (var db = new BaseDbContext())
                {
                    db.Entry(_account).State = EntityState.Modified;
                    _account.isEnabled       = false;
                    _account.isRemoved       = true;
                    _account.Username        = _account.Username + "(deleted)";
                    //db.accountDb.Remove(_acc);
                    //db.Entry(_acc).State = EntityState.Deleted;
                    db.SaveChanges();
                }
            }

            return(null);
        }
        public string edit(Category category)
        {
            using (var db = new BaseDbContext())
            {
                if (category.parentItemID == category.ItemID)
                {
                    return("Parent Item ID should not be the same as its own item ID.");
                }

                var _category = findCategoryByIDNoTracking(category.ItemID);
                category.created_at = _category.created_at;

                var local = db.infrastructureCategoryDb
                            .Local
                            .FirstOrDefault(f => f.ItemID == category.ItemID);
                if (local != null)
                {
                    db.Entry(local).State = EntityState.Detached;
                }


                List <string> modified_fields = new List <string>();

                if (_category.url != category.url)
                {
                    modified_fields.Add("url");
                }
                if (_category.name_en != category.name_en)
                {
                    modified_fields.Add("name_en");
                }
                if (_category.name_zh != category.name_zh)
                {
                    modified_fields.Add("name_zh");
                }
                if (_category.name_cn != category.name_cn)
                {
                    modified_fields.Add("name_cn");
                }
                if (_category.iconPath != category.iconPath)
                {
                    modified_fields.Add("iconPath");
                }
                if (_category.thumbPath != category.thumbPath)
                {
                    modified_fields.Add("thumbPath");
                }
                if (_category.imagePath != category.imagePath)
                {
                    modified_fields.Add("imagePath");
                }
                if (_category.remarks != category.remarks)
                {
                    modified_fields.Add("remarks");
                }
                if (_category.pageClassName != category.pageClassName)
                {
                    modified_fields.Add("pageClassName");
                }
                if (_category.isEnabled != category.isEnabled)
                {
                    modified_fields.Add("isEnabled");
                }
                if (_category.isContentPage != category.isContentPage)
                {
                    modified_fields.Add("isContentPage");
                }
                if (_category.isArticleList != category.isArticleList)
                {
                    modified_fields.Add("isArticleList");
                }
                if (_category.isVisibleToVisitorOnly != category.isVisibleToVisitorOnly)
                {
                    modified_fields.Add("isVisibleToVisitorOnly");
                }
                if (_category.isVisibleToMembersOnly != category.isVisibleToMembersOnly)
                {
                    modified_fields.Add("isVisibleToMembersOnly");
                }
                if (_category.isVisibleToTradingOnly != category.isVisibleToTradingOnly)
                {
                    modified_fields.Add("isVisibleToTradingOnly");
                }
                if (_category.isHeaderMenu != category.isHeaderMenu)
                {
                    modified_fields.Add("isHeaderMenu");
                }
                if (_category.isHeaderMenuRight != category.isHeaderMenuRight)
                {
                    modified_fields.Add("isHeaderMenuRight");
                }
                if (_category.isFooterMenu != category.isFooterMenu)
                {
                    modified_fields.Add("isFooterMenu");
                }
                if (_category.isBottomMenu != category.isBottomMenu)
                {
                    modified_fields.Add("isBottomMenu");
                }
                if (_category.isShortcut != category.isShortcut)
                {
                    modified_fields.Add("isShortcut");
                }
                if (_category.isJumbotron != category.isJumbotron)
                {
                    modified_fields.Add("isJumbotron");
                }
                if (_category.isBanner != category.isBanner)
                {
                    modified_fields.Add("isBanner");
                }
                if (_category.pageShouldShowTopbarmenu != category.pageShouldShowTopbarmenu)
                {
                    modified_fields.Add("pageShouldShowTopbarmenu");
                }
                if (_category.pageShouldHideTopTitle != category.pageShouldHideTopTitle)
                {
                    modified_fields.Add("pageShouldHideTopTitle");
                }
                if (_category.pageShouldHideFromHorizontalMenu != category.pageShouldHideFromHorizontalMenu)
                {
                    modified_fields.Add("pageShouldHideFromHorizontalMenu");
                }
                if (_category.isUseNewsArticleDetailsTemplate != category.isUseNewsArticleDetailsTemplate)
                {
                    modified_fields.Add("isUseNewsArticleDetailsTemplate");
                }



                if (category.parentItemID < 0)
                {
                    category.parentItemID = null;
                }

                if (category.iconPath != null && category.iconPath.Equals("____EMPTY"))
                {
                    category.iconPath = null;
                }
                else if (category.iconPath == null)
                {
                    category.iconPath = _category.iconPath;
                }

                if (category.thumbPath != null && category.thumbPath.Equals("____EMPTY"))
                {
                    category.thumbPath = null;
                }
                else if (category.thumbPath == null)
                {
                    category.thumbPath = _category.thumbPath;
                }

                if (category.imagePath != null && category.imagePath.Equals("____EMPTY"))
                {
                    category.imagePath = null;
                }
                else if (category.imagePath == null)
                {
                    category.imagePath = _category.imagePath;
                }

                AuditLogDbContext.getInstance().createAuditLogCategoryAction(category, AuditLogDbContext.ACTION_EDIT, modified_fields);

                db.Entry(category).State = EntityState.Modified;
                db.SaveChanges();
                return(null);
            }
        }
Ejemplo n.º 19
0
        public String tryEditArticleProperties(Article article, bool allLocales)
        {
            if (article.categoryID == -1)
            {
                article.categoryID = null;
            }

            var _article = findArticleByID(article.ArticleID);

            if (_article == null)
            {
                return("Item not found");
            }
            if (_article.isFrozen)
            {
                if (!ConstantDbContext.getInstance().ALLOW_EDIT_AFTER_PUBLISH())
                {
                    return(ResHelper.S("itemisfrozen"));
                }
            }

            var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(_article);

            if (error != null)
            {
                return(error);
            }

            List <string> modified_fields = new List <string>();

            using (var db = new BaseDbContext())
            {
                db.Entry(_article).State = EntityState.Modified;

                if (_article.Url != article.Url)
                {
                    modified_fields.Add("Url");
                }
                if (_article.Slug != article.Slug)
                {
                    modified_fields.Add("Slug");
                }
                if (_article.categoryID != article.categoryID)
                {
                    modified_fields.Add("categoryID");
                }

                _article.Url        = article.Url;
                _article.Slug       = article.Slug;
                _article.categoryID = article.categoryID;

                if (allLocales)
                {
                    var _localeArticles = findAllLocaleArticlesByBaseArticleAndVersion(article, article.Lang, db);
                    foreach (var _a in _localeArticles)
                    {
                        db.Entry(_a).State = EntityState.Modified;

                        if (_a.Url != article.Url)
                        {
                            modified_fields.Add("Url");
                        }
                        if (_a.Slug != article.Slug)
                        {
                            modified_fields.Add("Slug");
                        }
                        if (_a.categoryID != article.categoryID)
                        {
                            modified_fields.Add("categoryID");
                        }

                        _a.Url        = article.Url;
                        _a.Slug       = article.Slug;
                        _a.categoryID = article.categoryID;
                    }
                }

                db.SaveChanges();

                AuditLogDbContext.getInstance().createAuditLogArticleAction(article, AuditLogDbContext.ACTION_EDIT_PROPERTIES, modified_fields);

                return(null);
            }
        }
Ejemplo n.º 20
0
        public String tryEditArticle(Article article)
        {
            var _article = findArticleByID(article.ArticleID);

            if (_article == null)
            {
                return("Item not found");
            }
            if (_article.isFrozen)
            {
                if (!ConstantDbContext.getInstance().ALLOW_EDIT_AFTER_PUBLISH())
                {
                    return(ResHelper.S("itemisfrozen"));
                }
            }

            var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(_article);

            if (error != null)
            {
                return(error);
            }

            using (var db = new BaseDbContext())
            {
                List <string> modified_fields = new List <string>();

                if (_article.Name != article.Name)
                {
                    modified_fields.Add("Name");
                }
                if (_article.Desc != article.Desc)
                {
                    modified_fields.Add("Desc");
                }
                if (_article.Slug != article.Slug)
                {
                    modified_fields.Add("Slug");
                }
                if (_article.Keywords != article.Keywords)
                {
                    modified_fields.Add("Keywords");
                }
                if (_article.MetaData != article.MetaData)
                {
                    modified_fields.Add("MetaData");
                }
                if (_article.MetaKeywords != article.MetaKeywords)
                {
                    modified_fields.Add("MetaKeywords");
                }
                if (_article.Excerpt != article.Excerpt)
                {
                    modified_fields.Add("Excerpt");
                }


                db.Entry(_article).State = EntityState.Modified;
                _article.Name            = article.Name;
                _article.Desc            = article.Desc;
                if (_article.Desc != null)
                {
                    _article.Desc = _article.Desc.Replace("cms/ckfinder/userfiles", "ckfinder/userfiles");
                }
                _article.Slug         = article.Slug;
                _article.Keywords     = article.Keywords;
                _article.MetaData     = article.MetaData;
                _article.MetaKeywords = article.MetaKeywords;
                _article.Excerpt      = article.Excerpt;
                db.SaveChanges();

                AuditLogDbContext.getInstance().createAuditLogArticleAction(article, AuditLogDbContext.ACTION_EDIT, modified_fields);

                return(null);
            }
        }
Ejemplo n.º 21
0
        // ARTICLE EDITOR ONLY

        #region "Create"

        public String tryCreateNewArticle(Article article)
        {
            var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(article);

            if (error != null)
            {
                return(error);
            }

            Article latestArticle = null;

            if (article.categoryID == -1)
            {
                article.categoryID = null;
            }

            if (article.BaseArticleID != 0)
            {
                if (String.IsNullOrEmpty(article.Lang))
                {
                    article.Lang = "en";
                }

                if (!article.Lang.Equals("en"))
                {
                    return(tryCreateNewLocaleArticle(article));
                }

                latestArticle     = findLatestArticleByBaseArticle(article, null);
                article           = latestArticle.makeNewArticleByCloningContent();
                article.Version   = latestArticle.Version;
                article.Version   = article.Version + 1;
                article.createdBy = SessionPersister.account.AccountID;
            }
            else
            {
                article.Version = 1;
            }

            if (String.IsNullOrEmpty(article.Lang))
            {
                article.Lang = "en";
            }

            if (articleWithSameVersionAndLangAlreadyPresents(article))
            {
                return("Article already presents");
            }

            using (var db = new BaseDbContext())
            {
                article.createdBy = SessionPersister.account.AccountID;

                if (article.Desc != null)
                {
                    article.Desc = article.Desc.Replace("cms/ckfinder/userfiles", "ckfinder/userfiles");
                }

                db.articleDb.Add(article);
                db.SaveChanges();


                if (article.BaseArticleID == 0)
                {
                    db.Entry(article).State = EntityState.Modified;
                    article.BaseArticleID   = article.ArticleID;
                    db.SaveChanges();
                }


                // try clone new locale for this new article
                if (latestArticle != null && article != null)
                {
                    tryCloningNewLocaleArticleForNewArticleVersion(latestArticle, article);
                }

                if (article.Version == 1)
                {
                    AuditLogDbContext.getInstance().createAuditLogArticleAction(article, AuditLogDbContext.ACTION_CREATE);
                }
                else
                {
                    AuditLogDbContext.getInstance().createAuditLogArticleAction(article, AuditLogDbContext.ACTION_CREATE_NEW_VERSION);
                }
            }
            return(null);
        }
Ejemplo n.º 22
0
        public string tryChangeProfile(Account account)
        {
            List <string> modified_fields = new List <string>();

            Account _account = findAccountByID(account.AccountID);

            if (_account != null)
            {
                using (var db = new BaseDbContext())
                {
                    db.Entry(_account).State = EntityState.Modified;

                    if (account.RoleList != null)
                    {
                        account.Role = String.Join(",", account.RoleList);
                    }
                    else if (account.Role == null)
                    {
                        account.Role = "";
                    }


                    if (_account.Role != account.Role)
                    {
                        modified_fields.Add("Role");
                    }
                    if (_account.Username != account.Username)
                    {
                        modified_fields.Add("Username");
                    }
                    if (_account.Email != account.Email)
                    {
                        modified_fields.Add("Email");
                    }
                    if (_account.Firstname != account.Firstname)
                    {
                        modified_fields.Add("Firstname");
                    }
                    if (_account.Lastname != account.Lastname)
                    {
                        modified_fields.Add("Lastname");
                    }
                    if (_account.GroupID != account.GroupID)
                    {
                        modified_fields.Add("GroupID");
                    }
                    if (_account.isEnabled != account.isEnabled)
                    {
                        modified_fields.Add("isEnabled");
                    }



                    _account.Role      = account.Role;
                    _account.Username  = account.Username;
                    _account.Email     = account.Email;
                    _account.Firstname = account.Firstname;
                    _account.Lastname  = account.Lastname;
                    _account.GroupID   = account.GroupID;
                    _account.isEnabled = account.isEnabled;

                    SessionPersister.updateSessionForAccount();
                    db.SaveChanges();
                }

                AuditLogDbContext.getInstance().createAuditLogAccountAction(account, AuditLogDbContext.ACTION_EDIT, modified_fields);

                return(null);
            }
            else
            {
                return("Change password failed: Account not found");
            }
        }
Ejemplo n.º 23
0
        // ARTICLE PUBLISHER ONLY

        #region "Publish / Unpublish"

        public string tryPublishArticle(Article article, bool allLocales)
        {
            using (var db = new BaseDbContext())
            {
                var _article = article;
                if (_article == null)
                {
                    return("Item not found");
                }
                if (!_article.isApproved)
                {
                    return("Item not approved");
                }

                var error = AccountGroupBaseArticlePermissionHelper.tryCatchAccountGroupPermissionError(_article);
                if (error != null)
                {
                    return(error);
                }

                deletePublishedArticlesByBaseArticle(article);
                addArticleToPublished(article);

                var local = db.articleDb
                            .Local
                            .FirstOrDefault(f => f.BaseArticleID == _article.BaseArticleID);
                if (local != null)
                {
                    db.Entry(local).State = EntityState.Detached;
                }
            }

            using (var db = new BaseDbContext())
            {
                var _article = article;
                db.Entry(_article).State  = EntityState.Modified;
                _article.isPublished      = true;
                _article.datePublished    = DateTimeExtensions.GetServerTime();
                _article.datePublishStart = article.datePublishStart;
                _article.datePublishEnd   = article.datePublishEnd;
                _article.publishedBy      = SessionPersister.account.AccountID;

                if (allLocales)
                {
                    var _localeArticles = ArticleDbContext.getInstance().findAllLocaleArticlesByBaseArticleAndVersion(article, article.Lang, db);
                    foreach (var _a in _localeArticles)
                    {
                        db.Entry(_a).State  = EntityState.Modified;
                        _a.isPublished      = true;
                        _a.datePublished    = DateTimeExtensions.GetServerTime();
                        _a.datePublishStart = article.datePublishStart;
                        _a.datePublishEnd   = article.datePublishEnd;
                        _a.publishedBy      = SessionPersister.account.AccountID;
                    }
                }


                var allArticles = ArticleDbContext.getInstance().findArticlesGroupByBaseVersionApproved(_article.BaseArticleID, "en", db);
                foreach (Article a in allArticles)
                {
                    if (_article.ArticleID == a.ArticleID)
                    {
                        continue;
                    }

                    db.Entry(a).State = EntityState.Modified;
                    a.isPublished     = false;
                    a.datePublished   = null;
                    a.publishedBy     = null;

                    if (allLocales)
                    {
                        var _localeArticles = ArticleDbContext.getInstance().findAllLocaleArticlesByBaseArticleAndVersion(a, a.Lang, db);
                        foreach (var _a in _localeArticles)
                        {
                            db.Entry(_a).State = EntityState.Modified;
                            _a.isPublished     = false;
                            _a.datePublished   = null;
                            _a.publishedBy     = null;
                        }
                    }
                }



                db.SaveChanges();

                AuditLogDbContext.getInstance().createAuditLogArticleAction(article, AuditLogDbContext.ACTION_PUBLISH);

                return(null);
            }
        }