Exemplo n.º 1
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.º 2
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);
            }
        }
Exemplo n.º 5
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);
        }
        // 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.º 7
0
        public String tryEditArticle(ContentPage article)
        {
            if (article.categoryID == -1)
            {
                article.categoryID = null;
            }

            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);
            }

            db.Entry(_article).State = EntityState.Modified;
            _article.Name            = article.Name;
            _article.Desc            = article.Desc;
            _article.Url             = article.Url;
            _article.Keywords        = article.Keywords;
            _article.MetaData        = article.MetaData;
            _article.MetaKeywords    = article.MetaKeywords;
            _article.Excerpt         = article.Excerpt;
            db.SaveChanges();

            AuditLogDbContext.getInstance().createAuditLogContentPageAction(_article, AuditLogDbContext.ACTION_EDIT);

            return(null);
        }
Exemplo n.º 8
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.º 9
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.º 10
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);
        }
Exemplo n.º 11
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");
            }
        }
        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);
            }
        }
Exemplo n.º 13
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);
            }
        }