forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlogArticleServices.cs
More file actions
104 lines (87 loc) · 2.97 KB
/
BlogArticleServices.cs
File metadata and controls
104 lines (87 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Blog.Core.Common;
using Blog.Core.IRepository;
using Blog.Core.IServices;
using Blog.Core.Model.Models;
using Blog.Core.Model.VeiwModels;
using Blog.Core.Services.BASE;
namespace Blog.Core.Services
{
public class BlogArticleServices : BaseServices<BlogArticle>, IBlogArticleServices
{
IBlogArticleRepository dal;
IMapper IMapper;
public BlogArticleServices(IBlogArticleRepository dal, IMapper IMapper)
{
this.dal = dal;
base.baseDal = dal;
this.IMapper = IMapper;
}
/// <summary>
/// 获取视图博客详情信息
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<BlogViewModels> getBlogDetails(int id)
{
var bloglist = await dal.Query(a => a.bID > 0, a => a.bID);
var idmin = bloglist.FirstOrDefault() != null ? bloglist.FirstOrDefault().bID : 0;
var idmax = bloglist.LastOrDefault() != null ? bloglist.LastOrDefault().bID : 1;
var idminshow = id;
var idmaxshow = id;
BlogArticle blogArticle = new BlogArticle();
blogArticle = (await dal.Query(a => a.bID == idminshow)).FirstOrDefault();
BlogArticle prevblog = new BlogArticle();
while (idminshow > idmin)
{
idminshow--;
prevblog = (await dal.Query(a => a.bID == idminshow)).FirstOrDefault();
if (prevblog != null)
{
break;
}
}
BlogArticle nextblog = new BlogArticle();
while (idmaxshow < idmax)
{
idmaxshow++;
nextblog = (await dal.Query(a => a.bID == idmaxshow)).FirstOrDefault();
if (nextblog != null)
{
break;
}
}
blogArticle.btraffic += 1;
await dal.Update(blogArticle, new List<string> { "btraffic" });
//注意就是这里
BlogViewModels models = IMapper.Map<BlogViewModels>(blogArticle);
if (nextblog != null)
{
models.next = nextblog.btitle;
models.nextID = nextblog.bID;
}
if (prevblog != null)
{
models.previous = prevblog.btitle;
models.previousID = prevblog.bID;
}
return models;
}
/// <summary>
/// 获取博客列表
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[Caching(AbsoluteExpiration = 10)]
public async Task<List<BlogArticle>> getBlogs()
{
var bloglist = await dal.Query(a => a.bID > 0, a => a.bID);
return bloglist;
}
}
}