public static ConstantDbContext getInstance() { if (context == null) { context = new ConstantDbContext(); } return(context); }
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); }
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); }
public bool ALLOW_EDIT_AFTER_PUBLISH() { return(ConstantDbContext.getInstance().findActiveByKeyNoTracking("ALLOW_EDIT_AFTER_PUBLISH") != null); }
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); } }
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); } }