Skip to content

Commit

Permalink
修复查询失效问题
Browse files Browse the repository at this point in the history
  • Loading branch information
MonoLogueChi committed Oct 18, 2019
1 parent d509486 commit de53cbe
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 32 deletions.
17 changes: 6 additions & 11 deletions Danmaku/Controllers/Dplayer/DanmakuList/DanmakuListController.cs
@@ -1,4 +1,5 @@
using Danmaku.Controllers.Base;
using System.Threading.Tasks;
using Danmaku.Controllers.Base;
using Danmaku.Utils.Dao;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -14,21 +15,15 @@ public DanmakuListController(IDanmakuDao danmakuDao) : base(danmakuDao)
}


public ActionResult Index()
public async Task<ActionResult> Index(int page = 1, int size = 10)
{
return View(Dao.DanmakuBaseQuery(1, 10));
return View(await Dao.DanmakuBaseQuery(page, size));
}

// [HttpPost]
// public ActionResult Index(int page, int size = 10)
// {
// return View(Dao.DanmakuBaseQuery(page, size));
// }

[HttpPost]
public ActionResult Index(string vid)
public async Task<ActionResult> Index([FromForm] string vid, [FromForm] int page = 1, [FromForm] int size = 10)
{
return View(Dao.DanmakuBasesQueryByVid(vid, 1, 10));
return View(await Dao.DanmakuBasesQueryByVid(vid, page, size));
}
}
}
5 changes: 3 additions & 2 deletions Danmaku/Controllers/Dplayer/V3/DplayerController.cs
@@ -1,5 +1,6 @@
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Danmaku.Controllers.Base;
using Danmaku.Model;
using Danmaku.Utils.Dao;
Expand All @@ -17,10 +18,10 @@ public DplayerController(IDanmakuDao danmakuDao) : base(danmakuDao)

// GET: api/dplayer/v3/
[HttpGet]
public string Get()
public async Task<string> Get()
{
string id = Request.Query["id"];
return string.IsNullOrEmpty(id) ? new DanmakuWebResult(1) : new DanmakuWebResult(Dao.DanmakuQuery(id));
return string.IsNullOrEmpty(id) ? new DanmakuWebResult(1) : new DanmakuWebResult(await Dao.DanmakuQuery(id));
}

// POST: api/dplayer/v3/
Expand Down
6 changes: 6 additions & 0 deletions Danmaku/Startup.cs
Expand Up @@ -30,10 +30,16 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//全局配置文件
services.AddSingleton<IAppConfiguration>(s => new AppConfiguration(Configuration));

//数据库
services.AddDbContext<DanmakuContext>();

//http请求
services.AddHttpClient("gzip").ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler{AutomaticDecompression = DecompressionMethods.GZip});
services.AddHttpClient("deflate").ConfigurePrimaryHttpMessageHandler(() => new SocketsHttpHandler{AutomaticDecompression = DecompressionMethods.Deflate});

services.AddSingleton<IBiliBiliHelp, BiliBiliHelp>();
services.AddSingleton<IDanmakuDao, DanmakuDao>();
services.AddControllersWithViews();
Expand Down
24 changes: 13 additions & 11 deletions Danmaku/Utils/Dao/DanmakuDao.cs
@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Danmaku.Model;
using Danmaku.Utils.AppConfiguration;
using Microsoft.EntityFrameworkCore;

namespace Danmaku.Utils.Dao
{
Expand All @@ -14,10 +16,10 @@ public DanmakuDao(IAppConfiguration configuration)
_configuration = configuration;
}

public List<DanmakuData> DanmakuQuery(string id)
public async Task<List<DanmakuData>> DanmakuQuery(string id)
{
using var con = new DanmakuContext(_configuration);
return con.Danmaku.Where(e => e.Vid == id && e.IsDelete == false).Select(s => s.DanmakuData).ToList();
await using var con = new DanmakuContext(_configuration);
return await con.Danmaku.Where(e => e.Vid == id && e.IsDelete == false).Select(s => s.DanmakuData).ToListAsync();
}

public int DanmakuInsert(DanmakuDataInsert date)
Expand All @@ -28,22 +30,22 @@ public int DanmakuInsert(DanmakuDataInsert date)
return con.SaveChanges();
}

public List<DanmakuDataBase> DanmakuBaseQuery(int page, int size)
public async Task<List<DanmakuDataBase>> DanmakuBaseQuery(int page, int size)
{
using var con = new DanmakuContext(_configuration);
return con.Danmaku
await using var con = new DanmakuContext(_configuration);
return await con.Danmaku
.OrderBy(b => b.Vid).ThenByDescending(b => b.Date)
.Skip(size * (page - 1)).Take(size)
.ToList();
.ToListAsync();
}

public List<DanmakuDataBase> DanmakuBasesQueryByVid(string vid, int page, int size)
public async Task<List<DanmakuDataBase>> DanmakuBasesQueryByVid(string vid, int page, int size)
{
using var con = new DanmakuContext(_configuration);
return con.Danmaku.Where(e => e.Vid == vid)
await using var con = new DanmakuContext(_configuration);
return await con.Danmaku.Where(e => e.Vid == vid)
.OrderByDescending(b => b.Date)
.Skip(size * (page - 1)).Take(size)
.ToList();
.ToListAsync();
}
}
}
7 changes: 4 additions & 3 deletions Danmaku/Utils/Dao/IDanmakuDao.cs
@@ -1,15 +1,16 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Danmaku.Model;

namespace Danmaku.Utils.Dao
{
public interface IDanmakuDao
{
List<DanmakuData> DanmakuQuery(string id);
Task<List<DanmakuData>> DanmakuQuery(string id);

int DanmakuInsert(DanmakuDataInsert date);

List<DanmakuDataBase> DanmakuBaseQuery(int page, int size);
List<DanmakuDataBase> DanmakuBasesQueryByVid(string vid, int page, int size);
Task<List<DanmakuDataBase>> DanmakuBaseQuery(int page, int size);
Task<List<DanmakuDataBase>> DanmakuBasesQueryByVid(string vid, int page, int size);
}
}
19 changes: 14 additions & 5 deletions Danmaku/Views/DanmakuList/Index.cshtml
Expand Up @@ -29,11 +29,20 @@
</table>

<form asp-controller="DanmakuList" asp-action="Index" method="post" class="form-horizontal" role="form">
<div class="form-group">
<label class="col-md-2 control-label">Vid</label>
<div class="col-md-10">
<input type="text" name="vid" />
</div>
<div class="form-group">
<label class="col-md-2 control-label">Vid</label>
<div class="col-md-10">
<input type="text" name="vid" />
</div>
<label class="col-md-2 control-label">Page</label>
<div class="col-md-10">
<input type="text" name="page" value="1" />
</div>

<label class="col-md-2 control-label">Size</label>
<div class="col-md-10">
<input type="text" name="size" value="10" />
</div>
</div>

<div class="form-group">
Expand Down

0 comments on commit de53cbe

Please sign in to comment.