示例#1
0
 public void Delete(IEnumerable <T> entities)
 {
     if (entities?.Count() > 0)
     {
         try
         {
             using (unitOfWork.BeginTransaction())
             {
                 dbContext.RemoveRange(entities);
                 unitOfWork.SaveChange();
                 unitOfWork.Commit();
             }
         }
         catch (Exception)
         {
             unitOfWork.Rollback();
             throw;
         }
     }
 }
示例#2
0
        public ResponseData AccountrRegirst(AccountRegirstDto accountRegirstDto)
        {
            AccountModel accountModel = accountRepository.FindEntity(c => c.AccountName == accountRegirstDto.AccountName);

            if (accountModel != null)
            {
                return(new ResponseData {
                    MsgCode = 400, Message = "账号已注册"
                });
            }
            else
            {
                IdentityUser identityUser = mapper.Map <AccountRegirstDto, IdentityUser>(accountRegirstDto);
                accountModel = this.mapper.Map <AccountRegirstDto, AccountModel>(accountRegirstDto);
                accountModel.AccountPasswdEncrypt = Md5Helper.MD5Encrypt64(accountRegirstDto.AccountPasswd);
                IDbContextTransaction dbContextTransaction = null;
                try
                {
                    using (dbContextTransaction = unitwork.BeginTransaction())
                    {
                        userRepository.Insert(identityUser);
                        accountRepository.Insert(accountModel);
                        dbContextTransaction.Commit();
                    }
                    return(new ResponseData {
                        MsgCode = 200, Message = "账号注册成功"
                    });
                }
                //aop异常日志记录
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                }
            }
            return(new ResponseData {
                MsgCode = 400, Message = "账号注册失败"
            });
        }