-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d12f29a
commit cef0ee6
Showing
16 changed files
with
549 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Danmu.Model.DataTable; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Danmu.Utils.Dao | ||
{ | ||
public partial class DanmuDao | ||
{ | ||
/// <summary> | ||
/// 获取全部弹幕的数量 | ||
/// </summary> | ||
/// <returns></returns> | ||
public async Task<int> GetAllDanmuAsync() | ||
{ | ||
return await _con.Danmu.CountAsync(); | ||
} | ||
|
||
/// <summary> | ||
/// 分页查询全部弹幕 | ||
/// </summary> | ||
/// <param name="page"></param> | ||
/// <param name="size"></param> | ||
/// <param name="descending"></param> | ||
/// <returns></returns> | ||
public async Task<DanmuTable[]> GetAllDanmuAsync(int page, int size, bool descending = true) | ||
{ | ||
var allDanmu = _con.Danmu; | ||
var order = descending | ||
? allDanmu.OrderByDescending(b => b.CreateTime) | ||
: allDanmu.OrderBy(b => b.CreateTime); | ||
return await order.Skip(size * (page - 1)).Take(size).ToArrayAsync(); | ||
} | ||
|
||
/// <summary> | ||
/// 通过id获取相应的弹幕 | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
public async Task<DanmuTable> QueryDanmuByIdAsync(string id) | ||
{ | ||
if (Guid.TryParse(id, out var guid)) | ||
return await _con.Danmu.Where(e => e.Id.Equals(guid)).Include(e => e.Video).FirstOrDefaultAsync(); | ||
return new DanmuTable(); | ||
} | ||
|
||
/// <summary> | ||
/// 编辑弹幕 | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <param name="time"></param> | ||
/// <param name="mode"></param> | ||
/// <param name="color"></param> | ||
/// <param name="text"></param> | ||
/// <returns></returns> | ||
public async Task<DanmuTable> EditDanmuAsync(Guid id, float time, int mode, int color, string text) | ||
{ | ||
var dataBase = await _con.Danmu.Where(e => e.Id.Equals(id)).FirstOrDefaultAsync(); | ||
dataBase.Data.Time = time; | ||
dataBase.Data.Mode = mode; | ||
dataBase.Data.Color = color; | ||
dataBase.Data.Text = text ?? dataBase.Data.Text; | ||
dataBase.UpdateTime = DateTime.UtcNow; | ||
_con.Update(dataBase); | ||
if (await _con.SaveChangesAsync() > 0) return dataBase; | ||
return null; | ||
} | ||
|
||
/// <summary> | ||
/// 删除弹幕 | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
public async Task<bool> DeleteDanmuAsync(string id) | ||
{ | ||
if (Guid.TryParse(id, out var guid)) | ||
{ | ||
var dataBase = await _con.Danmu.Where(e => e.Id == guid).FirstOrDefaultAsync(); | ||
dataBase.UpdateTime = DateTime.UtcNow; | ||
dataBase.IsDelete = true; | ||
_con.Danmu.Update(dataBase); | ||
return await _con.SaveChangesAsync() > 0; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/// <summary> | ||
/// 通过vid查询到的弹幕总数 | ||
/// </summary> | ||
/// <param name="vid"></param> | ||
/// <returns></returns> | ||
public async Task<int> GetDanmuByVidAsync(string vid) | ||
{ | ||
return await _con.Danmu.Where(e => e.Vid.Equals(vid)).CountAsync(); | ||
} | ||
|
||
/// <summary> | ||
/// 通过vid查询弹幕表 | ||
/// </summary> | ||
/// <param name="vid"></param> | ||
/// <param name="size"></param> | ||
/// <param name="descending"></param> | ||
/// <param name="page"></param> | ||
/// <returns></returns> | ||
public async Task<DanmuTable[]> GetDanmuByVidAsync(string vid, int page, int size, | ||
bool descending = true) | ||
{ | ||
var allDanmu = _con.Danmu.Where(e => e.Vid.Equals(vid)); | ||
var order = descending | ||
? allDanmu.OrderByDescending(b => b.CreateTime) | ||
: allDanmu.OrderBy(b => b.CreateTime); | ||
return await order.Skip(size * (page - 1)).Take(size).ToArrayAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.