-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlogController.cs
71 lines (65 loc) · 3.27 KB
/
BlogController.cs
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
using System;
using System.Threading.Tasks;
using BlogWeb.Attributes;
using BlogWeb.Models;
using BusinessLayer.Abstract;
using CoreLayer.Utilities.Results.ComplexTypes;
using EntityLayer.ComplexTypes;
using EntityLayer.Concrete;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace BlogWeb.Controllers
{
public class BlogController : Controller
{
private readonly IBlogService _blogService;
private readonly BlogRightSideBarWidgetOptions _blogRightSideBarWidgetOptions;
public BlogController(IBlogService blogService, IOptionsSnapshot<BlogRightSideBarWidgetOptions> blogRightSideBarWidgetOptions)
{
_blogService = blogService;
_blogRightSideBarWidgetOptions = blogRightSideBarWidgetOptions.Value;
}
[HttpGet]
public async Task<IActionResult> Search(string keyword, int currentPage = 1, int pageSize = 6, bool isAscending = false)
{
var searchResult = await _blogService.SearchAsync(keyword, currentPage, pageSize, isAscending);
if (searchResult.ResultStatus == ResultStatus.Success)
{
return View(new BlogSearchViewModel
{
BlogListDto = searchResult.Data,
Keyword = keyword
});
}
return NotFound();
}
[HttpGet]
[ViewCountFilter] //Bu attribute bizim tarafimizdan yazildi ve asagidaki Action her calistiginda buradaki filtre de calicasaktir.
public async Task<IActionResult> Detail(int blogId)
{
var blogResult = await _blogService.GetAsync(blogId);
if (blogResult.ResultStatus == ResultStatus.Success)
{
//var userBlogs = await _blogService.GetAllByUserIdOnFilter(blogResult.Data.Blog.UserId,
// FilterBy.Category, OrderBy.Date, false, 10, blogResult.Data.Blog.CategoryId, DateTime.Now,
// DateTime.Now, 0, 99999, 0, 99999);
var userBlogs = await _blogService.GetAllByUserIdOnFilter(blogResult.Data.Blog.UserId,
_blogRightSideBarWidgetOptions.FilterBy, _blogRightSideBarWidgetOptions.OrderBy, _blogRightSideBarWidgetOptions.IsAscending, _blogRightSideBarWidgetOptions.TakeSize, _blogRightSideBarWidgetOptions.CategoryId, _blogRightSideBarWidgetOptions.StartAt,
_blogRightSideBarWidgetOptions.EndAt, _blogRightSideBarWidgetOptions.MinViewCount, _blogRightSideBarWidgetOptions.MaxViewCount, _blogRightSideBarWidgetOptions.MinCommentCount, _blogRightSideBarWidgetOptions.MaxCommentCount);
//await _blogService.IncreaseViewCountAsync(blogId);
return View(new BlogDetailViewModel
{
BlogDto = blogResult.Data,
BlogDetailRightSideBarViewModel = new BlogDetailRightSideBarViewModel
{
BlogListDto = userBlogs.Data,
//Header = "Kullanıcının Aynı Kategori Üzerindeki En Çok Okunan Makaleleri",
Header = _blogRightSideBarWidgetOptions.Header,
User = blogResult.Data.Blog.User
}
});
}
return NotFound();
}
}
}