using System.Collections.Generic; using System.Threading.Tasks; using Znyc.Admin.Commons.Const; using Znyc.Admin.Commons.Entitys; using Znyc.Admin.Commons.Mapping; using Znyc.Admin.Commons.Pages; using Znyc.Admin.Commons.Services; using Znyc.Admin.Security.Dtos; using Znyc.Admin.Security.Entitys; using Znyc.Admin.Security.IRepositories; using Znyc.Admin.Security.IServices; namespace Znyc.Admin.Security.Services { /// /// /// public class UserService : BaseService, IUserService { private readonly IUserRepository _dcUserRepository; public UserService(IUserRepository repository ) : base(repository) { _dcUserRepository = repository; } public async Task> FindWithPagerSearchAsync(SearchUserModel search) { bool order = search.Order != "asc"; string where = GetDataPrivilege(false); if (!string.IsNullOrEmpty(search.Keywords)) { @where += string.Format(" and (UserName like '%{0}%' or Account like '%{0}%' )", search.Keywords); } //if (search.Status > (int)CommonStatus.DELETED) //{ // @where += string.Format(" and Status={0}", search.Status); //} if (!string.IsNullOrEmpty(search.StartTime)) { @where += " and CreatedTime >='" + search.StartTime + " 00:00:00'"; } if (!string.IsNullOrEmpty(search.EndTime)) { @where += " and CreatedTime <='" + search.EndTime + " 23:59:59'"; } PagerInfo pagerInfo = new PagerInfo { CurrenetPageIndex = search.CurrenetPageIndex, PageSize = search.PageSize }; List list = await _dcUserRepository.UserPagerAsync(where, pagerInfo, search.Sort, order); foreach (var item in list) { item.AvatarUrl = CommonConst.Default_Image_Prefix + item.AvatarUrl; } PageResult pageResult = new PageResult { CurrentPage = pagerInfo.CurrenetPageIndex, Items = list, ItemsPerPage = pagerInfo.PageSize, TotalItems = pagerInfo.RecordCount }; return pageResult; } /// /// 修改用户状态 /// /// /// 状态 /// public async Task UpdateStatusAsync(long id, int status) { CommonResult result = new CommonResult(); User info = await _dcUserRepository.GetAsync(id); if (!(info?.Id > 0)) { result.Success = false; result.ErrMsg = "用户信息不存在"; return result; } info.Status = status; await _dcUserRepository.UpdateAsync(info, info.Id).ConfigureAwait(false); result.Success = true; return result; } } }