Exemplo 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);
     }
 }
Exemplo 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);
            }
        }
Exemplo n.º 3
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);
        }
        public string deletePublishedArticlesByBaseArticle(ContentPage article)
        {
            var targetBaseArticleID = article.BaseArticleID;

            getArticlePublishedDb().RemoveRange(
                getArticlePublishedDb().Where(acc =>
                                              acc.BaseArticleID == targetBaseArticleID
                                              )
                );
            db.SaveChanges();

            return(null);
        }
Exemplo 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);
            }
        }
Exemplo n.º 6
0
        protected string addArticleToPublished(Article article)
        {
            using (var db = new BaseDbContext())
            {
                var _article = ArticlePublished.makeNewArticleByCloningContentAndVersion(article);
                _article.isPublished      = true;
                _article.datePublished    = DateTimeExtensions.GetServerTime();
                _article.datePublishStart = article.datePublishStart;
                _article.datePublishEnd   = article.datePublishEnd;
                _article.publishedBy      = SessionPersister.account.AccountID;
                db.articlePublishedDb.Add(_article);

                var articles = ArticleDbContext.getInstance().findAllLocaleArticlesByBaseArticleAndVersion(article);
                foreach (var __article in articles)
                {
                    var ___article = ArticlePublished.makeNewArticleByCloningContentAndVersion(__article);
                    ___article.isPublished      = true;
                    ___article.datePublished    = DateTimeExtensions.GetServerTime();
                    ___article.datePublishStart = article.datePublishStart;
                    ___article.datePublishEnd   = article.datePublishEnd;
                    ___article.publishedBy      = SessionPersister.account.AccountID;
                    db.articlePublishedDb.Add(___article);
                }
                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);
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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");
            }
        }
Exemplo n.º 10
0
        public string createAuditLog(AuditLog item)
        {
            using (var db = new BaseDbContext())
            {
                db.auditLogDb.Add(item);
                db.SaveChanges();

                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;
 }
        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);
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
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);
            }
        }
        public string create(Constant item)
        {
            using (var db = new BaseDbContext())
            {
                var result = ConstantDbContext.getInstance().findByKeyNoTracking(item.Key);
                if (result != null)
                {
                    return("This Constant Key already exists. Please enter another Constant Key.");
                }

                db.constantDb.Add(item);
                db.SaveChanges();
            }
            AuditLogDbContext.getInstance().createAuditLogConstantAction(item, AuditLogDbContext.ACTION_CREATE);
            return(null);
        }
Exemplo n.º 17
0
        public string create(AccountGroup item)
        {
            var result = AccountGroupDbContext.getInstance().findGroupsByNameNoTracking(item.Name);

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

            using (var db = new BaseDbContext())
            {
                db.accountGroupDb.Add(item);
                db.SaveChanges();
                return(null);
            }
        }
Exemplo n.º 18
0
 void tryCloningNewLocaleArticleForNewArticleVersion(Article latestArticle, Article newArticle)
 {
     using (var db = new BaseDbContext())
     {
         // try clone new locale for this new article
         var articles = findAllLocaleArticlesByBaseArticleAndVersion(latestArticle, latestArticle.Lang);
         foreach (var _a in articles)
         {
             Article _new = _a.makeNewArticleByCloningContent();
             _new.Version   = newArticle.Version;
             _new.createdBy = SessionPersister.account.AccountID;
             db.articleDb.Add(_new);
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 19
0
        protected string deletePublishedArticlesByBaseArticle(Article article)
        {
            var targetBaseArticleID = article.BaseArticleID;

            using (var db = new BaseDbContext())
            {
                db.articlePublishedDb.RemoveRange(
                    db.articlePublishedDb.Where(acc =>
                                                acc.BaseArticleID == targetBaseArticleID
                                                )
                    );
                db.SaveChanges();

                return(null);
            }
        }
Exemplo n.º 20
0
        public string tryRegisterAccount(Account account, bool isSeeding = false)
        {
            var error = tryCheckUsername(account);

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

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

            var rawPassword = account.Password;
            var encPassword = account.MakeEncryptedPassword(account.Password);

            account.Password               = encPassword;
            account.ConfirmPassword        = encPassword;
            account.LastPasswordModifiedAt = DateTimeExtensions.GetServerTime();
            account.historyPasswords       = account.Password;

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

            account.NeedChangePassword = true;

            if (!isSeeding)
            {
                EmailHelper.SendEmailToAccountOnPasswordCreate(account, rawPassword);
            }

            using (var db = new BaseDbContext())
            {
                db.accountDb.Add(account);
                db.SaveChanges();
            }
            AuditLogDbContext.getInstance().createAuditLogAccountAction(account, AuditLogDbContext.ACTION_CREATE);
            return(null);
        }
Exemplo n.º 21
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 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;
        }
        public string create(Category category)
        {
            using (var db = new BaseDbContext())
            {
                var categorys = findCategorysByParentID(category.parentItemID);
                int maxOrder  = 0;
                for (int i = 0; i < categorys.Count(); i++)
                {
                    var item = categorys.ElementAt(i);
                    if (item.order > maxOrder)
                    {
                        maxOrder = item.order;
                    }
                }
                category.order = maxOrder + 1;
                if (category.parentItemID < 0)
                {
                    category.parentItemID = null;
                }

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

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

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

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

                db.infrastructureCategoryDb.Add(category);
                db.SaveChanges();
                return(null);
            }
        }
        // edit

        public string createScheduledNotification(SystemMaintenanceNotification item)
        {
            using (var db = new BaseDbContext())
            {
                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.systemMaintenanceNotificationDb.Add(item);
                db.SaveChanges();
            }
            AuditLogDbContext.getInstance().createAuditLogSystemMaintenanceNotificationAction(item, AuditLogDbContext.ACTION_CREATE);
            return null;
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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);
            }
        }
Exemplo n.º 27
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);
            }
        }
Exemplo n.º 28
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");
            }
        }
Exemplo n.º 29
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);
            }
        }
Exemplo n.º 30
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);
        }