Ejemplo n.º 1
0
        /// <summary>
        /// 新增标签日志
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > InsertSignatureLog(SignatureLogDto dto)
        {
            using (var uow = UnitOfWorkManager.Begin())
            {
                var output = new ActionOutput <string>();

                var log = new SignatureLog
                {
                    Name = dto.Name,
                    Type = dto.Type,
                    Url  = dto.Url,
                    Ip   = dto.Ip,
                    Time = DateTime.Now
                };

                var result = await _signatureLogRepository.InsertAsync(log);

                await uow.CompleteAsync();

                if (result.IsNull())
                {
                    output.AddError("新增标签出错了~~~");
                }
                else
                {
                    output.Result = "success";
                }

                return(output);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新分类
        /// </summary>
        /// <param name="id"></param>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > UpdateCategory(int id, CategoryDto dto)
        {
            using (var uow = UnitOfWorkManager.Begin())
            {
                var output = new ActionOutput <string>();

                var category = new Category
                {
                    Id           = id,
                    CategoryName = dto.CategoryName,
                    DisplayName  = dto.DisplayName
                };

                var result = await _categoryRepository.UpdateAsync(category);

                await uow.CompleteAsync();

                if (result.IsNull())
                {
                    output.AddError("更新分类出错了~~~");
                }
                else
                {
                    output.Result = "success";
                }

                return(output);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 批量添加热榜
        /// </summary>
        /// <param name="dtos"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > BulkInsertHotNews(IList <InsertHotNewsInput> dtos)
        {
            using (var uow = UnitOfWorkManager.Begin())
            {
                var output = new ActionOutput <string>();

                await _hotNewsRepository.DeleteAsync(x => x.SourceId == dtos.FirstOrDefault().SourceId);

                var hotNews = dtos.Select(x => new Core.Domain.HotNews.HotNews
                {
                    Id       = GenerateGuid(),
                    Title    = x.Title,
                    Url      = x.Url,
                    SourceId = x.SourceId,
                    Time     = DateTime.Now
                }).ToList();

                var result = await _hotNewsRepository.BulkInsertHotNewsAsync(hotNews);

                await uow.CompleteAsync();

                if (result)
                {
                    output.Result = "success";
                }
                else
                {
                    output.AddError("新增HotNews出错了~~~");
                }

                return(output);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 根据Id获取文章详细数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ActionOutput <GetPostForAdminDto> > GetPostForAdmin(int id)
        {
            var output = new ActionOutput <GetPostForAdminDto>();

            using (var uow = UnitOfWorkManager.Begin())
            {
                var post = await _postRepository.FirstOrDefaultAsync(x => x.Id == id);

                if (post.IsNull())
                {
                    output.AddError("找了找不到了~~~");
                    return(output);
                }

                var tags = from post_tags in await _postTagRepository.GetAllListAsync()
                           join tag in await _tagRepository.GetAllListAsync()
                           on post_tags.TagId equals tag.Id
                               where post_tags.PostId == post.Id
                           select tag.TagName;

                await uow.CompleteAsync();

                var result = post.MapTo <GetPostForAdminDto>();
                result.Tags = string.Join(",", tags);
                result.Url  = result.Url.Split("/").Where(x => x.IsNotNullOrEmpty()).Last();

                output.Result = result;

                return(output);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 新增好文
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > InsertNiceArticle(NiceArticleDto dto)
        {
            using (var uow = UnitOfWorkManager.Begin())
            {
                var output = new ActionOutput <string>();

                var niceArticle = new Core.Domain.NiceArticle.NiceArticle
                {
                    Title      = dto.Title,
                    Author     = dto.Author,
                    Source     = dto.Source,
                    Url        = dto.Url,
                    CategoryId = dto.CategoryId,
                    Time       = dto.Time
                };

                var result = await _niceArticleRepository.InsertAsync(niceArticle);

                await uow.CompleteAsync();

                if (result.IsNull())
                {
                    output.AddError("新增标签出错了~~~");
                }
                else
                {
                    output.Result = "success";
                }

                return(output);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 批量新增好文
        /// </summary>
        /// <param name="dtos"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > BulkInsertNiceArticle(IList <NiceArticleDto> dtos)
        {
            using (var uow = UnitOfWorkManager.Begin())
            {
                var output = new ActionOutput <string>();

                var niceArticle = dtos.Select(x => new Core.Domain.NiceArticle.NiceArticle
                {
                    Title      = x.Title,
                    Author     = x.Author,
                    Source     = x.Source,
                    Url        = x.Url,
                    CategoryId = x.CategoryId,
                    Time       = x.Time
                }).ToList();

                var result = await _niceArticleRepository.BulkInsertNiceArticleAsync(niceArticle);

                await uow.CompleteAsync();

                if (result)
                {
                    output.Result = "success";
                }
                else
                {
                    output.AddError("新增标签出错了~~~");
                }

                return(output);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 新增友链
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > InsertFriendLink(FriendLinkDto dto)
        {
            using (var uow = UnitOfWorkManager.Begin())
            {
                var output = new ActionOutput <string>();

                var friendLink = new FriendLink
                {
                    Id      = GenerateGuid(),
                    Title   = dto.Title,
                    LinkUrl = dto.LinkUrl
                };

                var result = await _friendLinkRepository.InsertAsync(friendLink);

                await uow.CompleteAsync();

                if (result.IsNull())
                {
                    output.AddError("新增友链出错了~~~");
                }
                else
                {
                    output.Result = "success";
                }

                return(output);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 更新标签
        /// </summary>
        /// <param name="id"></param>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > UpdateTag(int id, TagDto dto)
        {
            using (var uow = UnitOfWorkManager.Begin())
            {
                var output = new ActionOutput <string>();

                var tag = new Tag
                {
                    Id          = id,
                    TagName     = dto.TagName,
                    DisplayName = dto.DisplayName
                };

                var result = await _tagRepository.UpdateAsync(tag);

                await uow.CompleteAsync();

                if (result.IsNull())
                {
                    output.AddError("更新标签出错了~~~");
                }
                else
                {
                    output.Result = "success";
                }

                return(output);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 批量保存Commit记录
        /// </summary>
        /// <param name="dtos"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > BulkInsertCommits(IList <CommitDto> dtos)
        {
            using (var uow = UnitOfWorkManager.Begin())
            {
                var output = new ActionOutput <string>();

                var commits = dtos.Select(x => new Core.Domain.Commits.Commit
                {
                    Id      = GenerateGuid(),
                    Sha     = x.Sha,
                    Message = x.Message,
                    Date    = x.Date.ToDateTime()
                }).ToList();

                var allCommits = await _commitRepository.GetAllListAsync();

                commits = commits.Where(x => !allCommits.Select(c => c.Sha).Contains(x.Sha)).ToList();

                if (!commits.Any())
                {
                    output.AddError("没有新的Commit记录");
                    return(output);
                }

                var result = await _commitRepository.BulkInsertCommitAsync(commits);

                await uow.CompleteAsync();

                if (result)
                {
                    output.Result = "success";
                }
                else
                {
                    output.AddError("新增Commit出错了~~~");
                }

                return(output);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 获取文章
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public async Task <ActionOutput <GetPostDto> > GetPost(string url)
        {
            var output = new ActionOutput <GetPostDto>();

            using (var uow = UnitOfWorkManager.Begin())
            {
                var post = await _postRepository.FirstOrDefaultAsync(x => x.Url == url);

                if (post.IsNull())
                {
                    output.AddError("找了找不到了~~~");
                    return(output);
                }

                var category = await _categoryRepository.FirstOrDefaultAsync(x => x.Id == post.CategoryId);

                var tags = (from post_tags in await _postTagRepository.GetAllListAsync()
                            join tag in await _tagRepository.GetAllListAsync()
                            on post_tags.TagId equals tag.Id
                            where post_tags.PostId == post.Id
                            select new TagDto
                {
                    TagName = tag.TagName,
                    DisplayName = tag.DisplayName
                }).ToList();

                var previous = _postRepository.GetAll()
                               .Where(x => x.CreationTime > post.CreationTime)
                               .Take(1)
                               .FirstOrDefault();

                var next = _postRepository.GetAll()
                           .Where(x => x.CreationTime < post.CreationTime)
                           .OrderByDescending(x => x.CreationTime)
                           .Take(1)
                           .FirstOrDefault();

                await uow.CompleteAsync();

                var result = post.MapTo <GetPostDto>();
                result.CreationTime = Convert.ToDateTime(result.CreationTime).ToString("MMMM dd, yyyy HH:mm:ss", new CultureInfo("en-us"));
                result.Category     = category.MapTo <CategoryDto>();
                result.Tags         = tags;
                result.Previous     = previous.MapTo <PostForPagedDto>();
                result.Next         = next.MapTo <PostForPagedDto>();

                output.Result = result;

                return(output);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取分类名称
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > GetCategory(string name)
        {
            var output = new ActionOutput <string>();

            var category = await _categoryRepository.FirstOrDefaultAsync(x => x.DisplayName == name);

            if (category.IsNull())
            {
                output.AddError("找了找不到了~~~");
                return(output);
            }

            output.Result = category.CategoryName;

            return(output);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取标签名称
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task <ActionOutput <string> > GetTag(string name)
        {
            var output = new ActionOutput <string>();

            var tag = await _tagRepository.FirstOrDefaultAsync(x => x.DisplayName == name);

            if (tag.IsNull())
            {
                output.AddError("找了找不到了~~~");
                return(output);
            }

            output.Result = tag.TagName;

            return(output);
        }