using Blog.Core.Common; using Blog.Core.IRepository.Base; using Blog.Core.IServices; using Blog.Core.Model.Models; using Blog.Core.Services.BASE; using System.Linq; using System.Threading.Tasks; namespace Blog.Core.Services { /// /// UserRoleServices /// public class UserRoleServices : BaseServices, IUserRoleServices { /// /// /// /// /// /// public async Task SaveUserRole(long uid, long rid) { UserRole userRole = new UserRole(uid, rid); UserRole model = new UserRole(); var userList = await base.Query(a => a.UserId == userRole.UserId && a.RoleId == userRole.RoleId); if (userList.Count > 0) { model = userList.FirstOrDefault(); } else { var id = await base.Add(userRole); model = await base.QueryById(id); } return model; } [Caching(AbsoluteExpiration = 30)] public async Task GetRoleIdByUid(long uid) { return ((await base.Query(d => d.UserId == uid)).OrderByDescending(d => d.Id).LastOrDefault()?.RoleId).ObjToInt(); } } }