public async Task <IActionResult> UpdateAccountAsync([FromBody] UpdateAccountRequestDto request) { var managerAccountBiz = new ManagerAccountBiz(); var accountModel = await managerAccountBiz.GetAsync(request.UserGuid); if (accountModel == null) { return(Failed(ErrorCode.UserData, "找不到数据")); } var accounts = await managerAccountBiz.GetModelsAsync(request.UserGuid, request.Account, request.Phone); if (accounts.Count() > 0) { return(Failed(ErrorCode.UserData, "账号存在或者手机号已经存在")); } accountModel.Account = request.Account; accountModel.Enable = request.Enable; accountModel.IsSuper = request.IsSuper; accountModel.LastUpdatedBy = UserID; accountModel.LastUpdatedDate = DateTime.Now; accountModel.OrganizationGuid = request.OrganizationGuid; if (!string.IsNullOrWhiteSpace(request.Password)) { accountModel.Password = CryptoHelper.AddSalt(request.UserGuid, request.Password); } accountModel.Birthday = request.Birthday; accountModel.Email = request.Email; accountModel.Gender = request.Gender; accountModel.NickName = request.UserName; accountModel.Phone = request.Phone; accountModel.PortraitGuid = request.PortraitGuid; accountModel.UserName = request.UserName; accountModel.WechatOpenid = request.WechatOpenid; var accountRoleModels = new List <AccountRoleModel>(); foreach (var item in request.Roles) { accountRoleModels.Add(new AccountRoleModel { Arguid = Guid.NewGuid().ToString("N"), CreatedBy = UserID, CreationDate = DateTime.Now, Enable = request.Enable, LastUpdatedBy = UserID, OrgGuid = string.Empty, LastUpdatedDate = DateTime.Now, RoleGuid = item, UserGuid = request.UserGuid, }); } if (!await new ManagerAccountBiz().UpdateAsync(accountModel, accountRoleModels)) { return(Failed(ErrorCode.UserData, "修改失败")); } return(Success()); }
public async Task <IActionResult> AddAccountAsync([FromBody] AddAccountRequestDto request) { var managerAccountBiz = new ManagerAccountBiz(); var accounts = await managerAccountBiz.GetModelsAsync(request.Account, request.Phone); if (accounts.Count() > 0) { return(Failed(ErrorCode.UserData, "账号存在或者手机号已存在")); } string userGuid = Guid.NewGuid().ToString("N"); var accountModel = new AccountModel { Account = request.Account, UserGuid = userGuid, CreatedBy = UserID, CreationDate = DateTime.Now, Enable = request.Enable, IsSuper = request.IsSuper, LastUpdatedBy = UserID, LastUpdatedDate = DateTime.Now, OrganizationGuid = request.OrganizationGuid, OrgGuid = string.Empty, Password = CryptoHelper.AddSalt(userGuid, request.Password), Birthday = request.Birthday, Email = request.Email, Gender = request.Gender, NickName = request.UserName, Phone = request.Phone, PortraitGuid = request.PortraitGuid, UserName = request.UserName, WechatOpenid = request.WechatOpenid }; List <AccountRoleModel> accountRoleModels = new List <AccountRoleModel>(); foreach (var item in request.Roles) { accountRoleModels.Add(new AccountRoleModel { Arguid = Guid.NewGuid().ToString("N"), CreatedBy = UserID, CreationDate = DateTime.Now, Enable = request.Enable, LastUpdatedBy = UserID, OrgGuid = string.Empty, LastUpdatedDate = DateTime.Now, RoleGuid = item, UserGuid = userGuid, }); } if (!await new ManagerAccountBiz().AddAsync(accountModel, accountRoleModels)) { return(Failed(ErrorCode.UserData, "添加失败")); } return(Success()); }