Beispiel #1
0
        public HangerdResult <AccountDto> GetAccountForLogin(string loginName, string password)
        {
            return(Try(() =>
            {
                using (UnitOfWorkManager.Begin <IRepositoryContext>())
                {
                    if (string.IsNullOrWhiteSpace(loginName) || string.IsNullOrWhiteSpace(password))
                    {
                        throw new HangerdException("用户名或密码为空");
                    }

                    var spec = DeletableSpecifications <Account> .NotDeleted() & AccountSpecifications.LoginNameEquals(loginName);
                    var account = _accountRepository.Get(spec, false);

                    Requires.NotNull(account, "用户名不存在");

                    if (!account.ValidatePassword(password))
                    {
                        throw new HangerdException("密码错误");
                    }

                    return Mapper.Map <Account, AccountDto>(account);
                }
            }, "登录成功"));
        }
Beispiel #2
0
        public IEnumerable <AccountDto> GetAccounts(int pageIndex, int pageSize, ref int totalCount)
        {
            using (UnitOfWorkManager.Begin <IRepositoryContext>())
            {
                var accounts = _accountRepository.GetAll(DeletableSpecifications <Account> .NotDeleted(), false)
                               .OrderByDescending(a => a.CreateTime)
                               .Paging(pageIndex, pageSize, ref totalCount);

                return(Mapper.Map <IEnumerable <Account>, IEnumerable <AccountDto> >(accounts));
            }
        }
Beispiel #3
0
        public bool ExistLoginName(string loginName)
        {
            var spec = DeletableSpecifications <Account> .NotDeleted() & AccountSpecifications.LoginNameEquals(loginName);

            return(GetAll(spec, false).Any());
        }