91 lines
2.9 KiB
C#
91 lines
2.9 KiB
C#
|
|
using LangGuan.Command.Model;
|
|||
|
|
using LangGuan.Command.Model.EntityModel;
|
|||
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Linq.Expressions;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace LangGuan.Services
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
public class VideoService : BaseService<Video>
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="config"></param>
|
|||
|
|
public VideoService(IConfiguration config) : base(config, nameof(Video))
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 首页取全部
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public async Task<object> GetAll()
|
|||
|
|
{
|
|||
|
|
Expression<Func<Video, bool>> exp = num => true;
|
|||
|
|
var query = await base.GetListWithExp(exp);
|
|||
|
|
var reslut = query.OrderByDescending(s => s.CreateDateTime)
|
|||
|
|
.Select(s => new { s.GroupName, s.Url, }).ToList();
|
|||
|
|
if (reslut.Count > 0)
|
|||
|
|
{
|
|||
|
|
return reslut;
|
|||
|
|
}
|
|||
|
|
return Task.FromResult(new { });
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 分页数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="request"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public async Task<ApiResult> GetList(RqeustPaging request)
|
|||
|
|
{
|
|||
|
|
request.pageSize = request.pageSize == 0 ? 10 : request.pageSize;
|
|||
|
|
Expression<Func<Video, bool>> exp = num => true;
|
|||
|
|
var query = await base.GetListWithExp(exp);
|
|||
|
|
var total = query.Count();
|
|||
|
|
var items = query.OrderByDescending(s => s.CreateDateTime)
|
|||
|
|
.Skip(request.pageSize * (request.current - 1)).Take(request.pageSize)
|
|||
|
|
.Select(s => new { s.Id, s.GroupName, s.Url, }).ToList();
|
|||
|
|
return new ApiResult()
|
|||
|
|
{
|
|||
|
|
code = 0,
|
|||
|
|
data = new { total = total, items = items }
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="video"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public async Task<ApiResult> Add(Video video)
|
|||
|
|
{
|
|||
|
|
await base.CreateAsync(video);
|
|||
|
|
return new ApiResult() { code = 0, msg = "" };
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 更新
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="video"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public async Task<ApiResult> Update(Video video)
|
|||
|
|
{
|
|||
|
|
var entity = await base.GetAsync(video.Id);
|
|||
|
|
if (entity != null)
|
|||
|
|
{
|
|||
|
|
entity.GroupName = video.GroupName;
|
|||
|
|
entity.Url = video.Url;
|
|||
|
|
await base.UpdateAsync(video.Id, entity);
|
|||
|
|
return new ApiResult() { code = 0, msg = "" };
|
|||
|
|
}
|
|||
|
|
return new ApiResult() { code = 1, msg = "修改失败" };
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|