public static void AddItem(BlogSystemContext dataBaseContext, string name) { FormatVerificationHelper.FormatVerification(name, FormatVerificationHelper.FormatType.ArticleLabelName, new ParametersFormatErrorException("标签格式错误。")); dataBaseContext.ArticleLabels.AddRange(new ArticleLabel() { Name = name }); }
public static void AddItem(BlogSystemContext dataBaseContext, string name) { FormatVerificationHelper.FormatVerification(name, FormatVerificationHelper.FormatType.TemplateName, new ParametersFormatErrorException("模板名称格式错误。")); dataBaseContext.Templates.Add(new Template() { Guid = Guid.NewGuid(), Name = name }); }
public static void EditItem(BlogSystemContext dataBaseContext, Guid guid, string name) { FormatVerificationHelper.FormatVerification(name, FormatVerificationHelper.FormatType.TemplateName, new ParametersFormatErrorException("模板名称格式错误。")); var template = dataBaseContext.Templates.FirstOrDefault(q => q.Guid == guid); if (template != null) { template.Name = name; } }
public static void EditItem(BlogSystemContext dataBaseContext, Guid guid, string name) { FormatVerificationHelper.FormatVerification(name, FormatVerificationHelper.FormatType.ArticleLabelName, new ParametersFormatErrorException("标签格式错误。")); var articleLabel = dataBaseContext.ArticleLabels.FirstOrDefault(q => q.Guid == guid); if (articleLabel != null) { articleLabel.Name = name; } }
public static void AddItem(BlogSystemContext dataBaseContext, string name, Guid?parentArticleTypeGuid, uint sequence) { FormatVerificationHelper.FormatVerification(name, FormatVerificationHelper.FormatType.ArticleTypeName, new ParametersFormatErrorException("类别格式错误。")); dataBaseContext.ArticleTypes.AddRange(new ArticleType() { Name = name, ParentArticleTypeGuid = parentArticleTypeGuid, Sequence = sequence }); }
public static void EditItem(BlogSystemContext dataBaseContext, Guid guid, string name, Guid?parentArticleTypeGuid, uint sequence) { FormatVerificationHelper.FormatVerification(name, FormatVerificationHelper.FormatType.ArticleTypeName, new ParametersFormatErrorException("类别格式错误。")); var articleType = dataBaseContext.ArticleTypes.FirstOrDefault(q => q.Guid == guid); if (articleType == null) { return; } articleType.Name = name; articleType.ParentArticleTypeGuid = parentArticleTypeGuid; articleType.Sequence = sequence; }
public static Guid?EditItem(BlogSystemContext dataBaseContext, Guid guid, string virtualPath) { FormatVerificationHelper.FormatVerification(virtualPath, FormatVerificationHelper.FormatType.VirtualPath, new ParametersFormatErrorException("虚拟路径格式错误。")); if (dataBaseContext.TemplateFiles.Any(q => q.VirtualPath == virtualPath)) { throw new TemplateFileAddItemVirtualPathIsExistException("此虚拟路径已经存在。"); } var templateFile = dataBaseContext.TemplateFiles.FirstOrDefault(q => q.Guid == guid); if (templateFile == null) { return(null); } templateFile.VirtualPath = virtualPath; return(templateFile.TemplateGuid); }
public static void AddItem(BlogSystemContext dataBaseContext, string name, Guid articleTypeGuid, IEnumerable <Guid> articleLabelGuids, string content) { FormatVerificationHelper.FormatVerification(name, FormatVerificationHelper.FormatType.ArticleName, new ParametersFormatErrorException("文章名格式错误。")); var article = new Article() { Name = name, ArticleTypeGuid = articleTypeGuid, Content = content }; dataBaseContext.Articles.Add(article); dataBaseContext.ArticleLabelArticles.AddRange(articleLabelGuids.Select(o => new ArticleLabelArticle { ArticleLabelGuid = o, Article = article })); }
public static void AddItem(BlogSystemContext dataBaseContext, IHostingEnvironment hostingEnvironment, string virtualPath, Guid templateGuid, AddItemSaveFilesDelegate saveFiles) { FormatVerificationHelper.FormatVerification(virtualPath, FormatVerificationHelper.FormatType.VirtualPath, new ParametersFormatErrorException("虚拟路径格式错误。")); if (dataBaseContext.TemplateFiles.Any(q => q.VirtualPath == virtualPath)) { throw new TemplateFileAddItemVirtualPathIsExistException("此虚拟路径已经存在。"); } var formFileInfos = saveFiles(dataBaseContext, hostingEnvironment); dataBaseContext.TemplateFiles.AddRange(formFileInfos.Select(formFile => new TemplateFile() { MIME = formFile.MIME, Name = formFile.FileName, UploadedFile = formFile.UploadedFile, TemplateGuid = templateGuid, VirtualPath = virtualPath })); }
public static void EditItem(BlogSystemContext dataBaseContext, Guid guid, string name, Guid articleTypeGuid, IEnumerable <Guid> articleLabelGuids, string content) { FormatVerificationHelper.FormatVerification(name, FormatVerificationHelper.FormatType.ArticleName, new ParametersFormatErrorException("文章名格式错误。")); var article = dataBaseContext.Articles.FirstOrDefault(q => q.Guid == guid); if (article == null) { return; } article.Name = name; article.ArticleTypeGuid = articleTypeGuid; article.Content = content; dataBaseContext.ArticleLabelArticles.RemoveRange( dataBaseContext.ArticleLabelArticles.Where(o => o.Article == article)); dataBaseContext.ArticleLabelArticles.AddRange(articleLabelGuids.Select(o => new ArticleLabelArticle { ArticleLabelGuid = o, Article = article })); }
internal static void Seed(BlogSystemContext dataBaseContext, IDistributedCache cache, IHostingEnvironment hostingEnvironment, Configs configs) { FormatVerificationHelper.FormatVerification( configs.Email, FormatVerificationHelper.FormatType.Email, new ParametersFormatErrorException("邮箱格式错误。")); FormatVerificationHelper.FormatVerification( configs.Password, FormatVerificationHelper.FormatType.Password, new ParametersFormatErrorException("密码格式错误。")); FormatVerificationHelper.FormatVerification( configs.BlogName, FormatVerificationHelper.FormatType.BlogName, new ParametersFormatErrorException("博客名称格式错误。")); FormatVerificationHelper.FormatVerification( configs.UserName, FormatVerificationHelper.FormatType.UserName, new ParametersFormatErrorException("昵称格式错误。")); dataBaseContext.Database.EnsureDeleted(); dataBaseContext.Database.EnsureCreated(); using (var transaction = dataBaseContext.Database.BeginTransaction()) { Config(dataBaseContext, cache, configs); TemplateFile(dataBaseContext, hostingEnvironment); transaction.Commit(); } }