public IEnumerable <Tag> Project(IEnumerable <string> input) { var tags = from slug in input select _db.SelectKey <Tag>(DBTableNames.Tags, slug); return(tags); }
public BlogPostEditViewModel Project(BlogPostEditBindingModel input) { var post = _db.SelectKey <BlogPost>(DBTableNames.BlogPosts, input.PostId); return(new BlogPostEditViewModel { BlogPost = post }); }
/// <summary> /// Gets the configuration parameter. /// </summary> /// <param name="key">The key.</param> /// <returns>The parameter value.</returns> private string GetConfigParameter(string key) { ConfigParameter configParam = m_tableIndexDB.SelectKey <ConfigParameter>(ConfigParameter.TableName, key); if (configParam != null) { return(configParam.value); } return(null); }
public string GenerateHash(string tick) { var nonhash = string.Empty; if (tick.IsNullOrWhitespace()) { return(nonhash); } var spamHash = _db.SelectKey <SpamHash>(DBTableNames.SpamHashes, tick); if (spamHash == null || spamHash.Pass || !spamHash.Hash.IsNullOrWhitespace()) { return(nonhash); } spamHash.Hash = new Random().NextDouble().ToString(); _db.Update(DBTableNames.SpamHashes, spamHash); return(spamHash.Hash); }
public CommandResult Execute(NewPostCommand command) { var markdown = new MarkdownSharp.Markdown(); //TODO:应该验证TitleSlug是否唯一 var post = new BlogPost { Id = ObjectId.NewObjectId(), AuthorEmail = command.Author.Email, AuthorDisplayName = command.Author.DisplayName, MarkDown = command.MarkDown, Content = markdown.Transform(command.MarkDown), PubDate = command.PubDate.CloneToUtc(), Status = command.Published ? PublishStatus.Published : PublishStatus.Draft, Title = command.Title, TitleSlug = command.TitleSlug.IsNullOrWhitespace() ? command.Title.Trim().ToSlug() : command.TitleSlug.Trim().ToSlug(), DateUTC = DateTime.UtcNow }; if (!command.Tags.IsNullOrWhitespace()) { var tags = command.Tags.Trim().Split(',').Select(s => s.Trim()); post.Tags = tags.Select(s => s.ToSlug()).ToArray(); foreach (var tag in tags) { var slug = tag.ToSlug(); var tagEntry = _db.SelectKey <Tag>(DBTableNames.Tags, slug); if (tagEntry == null) { tagEntry = new Tag { Slug = slug, Name = tag, PostCount = 1 }; _db.Insert(DBTableNames.Tags, tagEntry); } else { tagEntry.PostCount++; _db.Update(DBTableNames.Tags, tagEntry); } } } else { post.Tags = new string[] { } }; var result = _db.Insert(DBTableNames.BlogPosts, post); return(CommandResult.SuccessResult); } }
public CommandResult Execute(ChangePasswordCommand command) { var author = _db.SelectKey <Author>(DBTableNames.Authors, command.AuthorId); if (Hasher.GetMd5Hash(command.OldPassword) != author.HashedPassword) { return(new CommandResult("旧密码不正确!")); } author.HashedPassword = Hasher.GetMd5Hash(command.NewPassword); _db.Update(DBTableNames.Authors, author); return(CommandResult.SuccessResult); }
public AuthorProfileViewModel Project(string input) { var author = _db.SelectKey <Author>(DBTableNames.Authors, input); if (author == null) { return(null); } return(new AuthorProfileViewModel { DisplayName = author.DisplayName, Email = author.Email }); }
public CommandResult Execute(ChangeProfileCommand command) { var author = _db.SelectKey <Author>(DBTableNames.Authors, command.AuthorId); if (author == null) { return(new CommandResult("用户信息不存在")); } author.DisplayName = command.NewDisplayName; author.Email = command.NewEmail; _db.Update(DBTableNames.Authors, author); return(CommandResult.SuccessResult); }
/// <summary> /// Gets the configuration metadata. /// </summary> /// <typeparam name="T">The type of metadata. </typeparam> /// <param name="id">The identifier.</param> /// <returns></returns> public T GetConfigMetadata <T>(long id) where T : ConfigMetadata, new() { DB.AutoBox db = GetDB <T>(); if (db != null) { Type type = typeof(T); string tableName = type.Name; T item = db.SelectKey <T>(tableName, id); return(item); } return(null); }
public TaggedBlogPostsViewModel Project(TaggedBlogPostsBindingModel input) { var posts = (from p in _db.Select <BlogPost>("from " + DBTableNames.BlogPosts) where p.IsPublished && p.Tags.Contains(input.Tag) orderby p.PubDate descending select p) .ToList(); if (posts.Count == 0) { return(null); } var tagName = _db.SelectKey <Tag>(DBTableNames.Tags, posts.First().Tags[0]).Name; return(new TaggedBlogPostsViewModel { Posts = posts, Tag = tagName }); }
public CommandResult Execute(EditPostCommand command) { var post = _db.SelectKey <BlogPost>(DBTableNames.BlogPosts, command.PostId); if (post == null) { throw new ApplicationException("Post with id: {0} was not found".FormatWith(command.PostId)); } if (post.Tags != null) { foreach (var tag in post.Tags) { var slug = tag.ToSlug(); var tagEntry = _db.SelectKey <Tag>(DBTableNames.Tags, slug); if (tagEntry != null) { tagEntry.PostCount--; _db.Update(DBTableNames.Tags, tagEntry); } } } var markdown = new MarkdownSharp.Markdown(); //TODO:应该验证TitleSlug是否是除了本文外唯一的 post.MarkDown = command.MarkDown; post.Content = markdown.Transform(command.MarkDown); post.PubDate = command.PubDate.CloneToUtc(); post.Status = command.Published ? PublishStatus.Published : PublishStatus.Draft; post.Title = command.Title; post.TitleSlug = command.TitleSlug.Trim().ToSlug(); if (!command.Tags.IsNullOrWhitespace()) { var tags = command.Tags.Trim().Split(',').Select(s => s.Trim()); post.Tags = tags.Select(s => s.ToSlug()).ToArray(); foreach (var tag in tags) { var slug = tag.ToSlug(); var tagEntry = _db.SelectKey <Tag>(DBTableNames.Tags, slug); if (tagEntry == null) { tagEntry = new Tag { Slug = slug, Name = tag, PostCount = 1 }; _db.Insert(DBTableNames.Tags, tagEntry); } else { tagEntry.PostCount++; _db.Update(DBTableNames.Tags, tagEntry); } } } else { post.Tags = new string[] { } }; _db.Update(DBTableNames.BlogPosts, post); return(CommandResult.SuccessResult); } }
public Author Project(string input) { return(_db.SelectKey <Author>(DBTableNames.Authors, input)); }
public Tag Project(string input) { var tag = _db.SelectKey <Tag>(DBTableNames.Tags, input); return(tag); }
/// <summary> /// 根据主键获取数据 /// </summary> public T GetData <T>(object keyValue) where T : class, new() { return(_autoBox.SelectKey <T>(typeof(T).Name, keyValue)); }