NewGaoKaoApi/New_College.Api/Controllers/Front/MyHistoryInfoController.cs

105 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using New_College.IServices;
using New_College.Model;
using New_College.Model.ViewModels.Result;
using SqlSugar;
namespace New_College.Api.Controllers.Front
{
/// <summary>
/// 历史大学
/// </summary>
[Route("api/front/[controller]/[action]")]
[ApiController]
[Authorize]
public class MyHistoryInfoController : ControllerBase
{
private readonly ID_MyHistoryInfoServices _MyHistory;
private readonly ID_UniversityServices _UniversityServices;
public MyHistoryInfoController(ID_MyHistoryInfoServices d_MyHistoryInfoServices, ID_UniversityServices d_UniversityServices)
{
this._MyHistory = d_MyHistoryInfoServices;
this._UniversityServices = d_UniversityServices;
}
/// <summary>
/// 添加浏览记录
/// </summary>
/// <param name="requestDto"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<bool>> Add([FromBody] MyHistoryRequestDto requestDto)
{
var res = new MessageModel<bool>();
///
var status = await _MyHistory.Add(new Model.Models.D_MyHistoryInfo()
{
CreateTime = DateTime.Now,
CustomerId = requestDto.CustomerId,
Type = 0,
UId = requestDto.UId,
});
return res;
}
/// <summary>
/// 浏览历史记录列表
/// </summary>
/// <param name="CustomerId"></param>
/// <returns></returns>
[HttpGet]
public async Task<MessageModel<List<MyHistoryResponse>>> GetMyHistory([FromQuery] int CustomerId)
{
var response = new List<MyHistoryResponse>();
try
{
var query = await _MyHistory.Query(e => e.CustomerId == CustomerId);
if (query.Any())
{
var uids = query.Select(s => s.UId).ToList();
var universitysinfo = await this._UniversityServices.Query(q => SqlFunc.ContainsArray(uids, q.Id));
response = universitysinfo.Select(s => new MyHistoryResponse()
{
AreaName = s.Area_Name,
Id = s.Id,
Logo = s.Logo,
Name = s.Name,
Nature = s.Nature,
Rank = s.Rank,
Syl = s.Syl == 1 ? true : false,
Nhef = s.Nhef == 1 ? true : false,
Sff = s.Sff == 1 ? true : false
}).ToList();
}
return new MessageModel<List<MyHistoryResponse>>()
{
msg = "success",
response = response,
success = true
};
}
catch (Exception ex)
{
return new MessageModel<List<MyHistoryResponse>>()
{
msg = ex.Message
};
}
}
}
}