You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

93 lines
3.2 KiB

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
{
/// <summary>
///
/// </summary>
public class UserService : BaseService<User, UserOutputDto, long>, IUserService
{
private readonly IUserRepository _dcUserRepository;
public UserService(IUserRepository repository
) : base(repository)
{
_dcUserRepository = repository;
}
public async Task<PageResult<UserOutputDto>> 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<UserOutputDto> list = await _dcUserRepository.UserPagerAsync(where, pagerInfo, search.Sort, order);
foreach (var item in list)
{
item.AvatarUrl = CommonConst.Default_Image_Prefix + item.AvatarUrl;
}
PageResult<UserOutputDto> pageResult = new PageResult<UserOutputDto>
{
CurrentPage = pagerInfo.CurrenetPageIndex,
Items = list,
ItemsPerPage = pagerInfo.PageSize,
TotalItems = pagerInfo.RecordCount
};
return pageResult;
}
/// <summary>
/// �޸��û�״̬
/// </summary>
/// <param name="id"></param>
/// <param name="status">״̬</param>
/// <returns></returns>
public async Task<CommonResult> 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;
}
}
}