using New_College.Common; using New_College.IRepository.Base; using New_College.IServices; using New_College.Model.Models; using New_College.Services.BASE; using System.Linq; using System.Threading.Tasks; namespace New_College.Services { /// /// UserRoleServices /// public class UserRoleServices : BaseServices, IUserRoleServices { IBaseRepository _dal; public UserRoleServices(IBaseRepository dal) { this._dal = dal; base.BaseDal = dal; } /// /// /// /// /// /// public async Task SaveUserRole(int uid, int 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(int uid) { return ((await base.Query(d => d.UserId == uid)).OrderByDescending(d => d.Id).LastOrDefault()?.RoleId).ObjToInt(); } } }