public async Task <ActionResult> UpdateAccountDetail(string AccountId, string Mainphone, string Fax, string Tollfree, string Webaddress, string Type, string Address1, string Address2, string Suburb, string State, string PostalCode, string Billing_Method, string Billable_Rate, string Service_Rage) { ClaimTeamLoginModel client = (ClaimTeamLoginModel)Session[SessionHelper.claimTeamLogin]; AccountUpdateModel model = new AccountUpdateModel(); model.AccountId = AccountId; model.Mainphone = Mainphone; model.Fax = Fax; model.Tollfree = Tollfree; model.Webaddress = Webaddress; model.Type = Type; model.Address1 = Address1; model.Address2 = Address2; model.Suburb = Suburb; model.State = State; model.PostalCode = PostalCode; model.Billing_Method = Billing_Method; model.Billable_Rate = Billable_Rate; model.Service_Rage = Service_Rage; AccountListRepo accountListRepo = new AccountListRepo(); bool result = await accountListRepo.UpdateAccount(model, client.UserId); return(RedirectToAction("Index")); }
public async Task UpdateAccountsAmount(AccountUpdateModel accountUpdateModel) { var transactionMessageModel = new TransactionMessageModel { TransactionId = accountUpdateModel.TransactionId, SenderAccountId = accountUpdateModel.SenderAccountId, ReceiverAccountId = accountUpdateModel.ReceiverAccountId, Amount = accountUpdateModel.Amount }; if (await IsTransactionPermitted(accountUpdateModel)) { try { var senderAccount = await _mediator.Send( new GetAccountByIdQuery(accountUpdateModel.SenderAccountId) ); var receiverAccount = await _mediator.Send( new GetAccountByIdQuery(accountUpdateModel.ReceiverAccountId) ); if (senderAccount != null && receiverAccount != null) { if (senderAccount.Amount >= accountUpdateModel.Amount) { senderAccount.Amount -= accountUpdateModel.Amount; receiverAccount.Amount += accountUpdateModel.Amount; await _mediator.Send(new UpdateAccountCommand(senderAccount.Id, senderAccount)); await _mediator.Send(new UpdateAccountCommand(receiverAccount.Id, receiverAccount)); transactionMessageModel.Status = "Finished"; transactionMessageModel.Info = "The transaction was successful"; _transactionUpdateSender.UpdateTransaction(transactionMessageModel); } else { transactionMessageModel.Status = "Failed"; transactionMessageModel.Info = "The account balance is too low"; _transactionUpdateSender.UpdateTransaction(transactionMessageModel); } } } catch (Exception ex) { transactionMessageModel.Status = "Failed"; transactionMessageModel.Info = "Account number not found. The operation has failed"; _transactionUpdateSender.UpdateTransaction(transactionMessageModel); } } else { transactionMessageModel.Status = "Failed"; transactionMessageModel.Info = "Operation prohibited"; _transactionUpdateSender.UpdateTransaction(transactionMessageModel); } }
public ActionResult Account(AccountUpdateModel model) { if (ModelState.IsValid) { accountInformation.UpdateAccount(model); } return(View()); }
public async Task <IResultModel> Update(AccountUpdateModel model) { var entity = await _accountRepository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("账户不存在!")); } if (entity.IsLock) { return(ResultModel.Failed("账户锁定,不允许修改")); } var account = _mapper.Map(model, entity); var exists = await Exists(account); if (!exists.Successful) { return(exists); } using (var tran = _accountRepository.BeginTransaction()) { var result = await _accountRepository.UpdateAsync(account, tran); if (result) { result = await _accountRoleRepository.DeleteByAccount(account.Id, tran); if (result) { if (model.Roles != null && model.Roles.Any()) { var accountRoleList = model.Roles.Select(m => new AccountRoleEntity { AccountId = account.Id, RoleId = m }).ToList(); if (await _accountRoleRepository.AddAsync(accountRoleList, tran)) { tran.Commit(); ClearPermissionListCache(account.Id); return(ResultModel.Success()); } } else { tran.Commit(); ClearPermissionListCache(account.Id); return(ResultModel.Success()); } } } } return(ResultModel.Failed()); }
public async Task <ActionResult> Update( [FromRoute] string id, [FromBody] AccountUpdateModel account) { return(await PatchResult( async() => await accountService.Update(id, account), nameof(account) )); }
public async Task <IResultModel> Update(AccountUpdateModel model) { var user = _accountRepository.FindEntity(model.Uid); if (user == null) { return(ResultModel.Failed("账户不存在!")); } if (user.LoginName != model.LoginName)//改了用户名 { if (await _accountRepository.ExistsLoginName(model.LoginName)) { return(ResultModel.Failed("用户名已存在")); } } if (user.Phone != model.Phone)//改了手机号码 { if (await _accountRepository.ExistsPhone(model.Phone)) { return(ResultModel.Failed("手机号已存在")); } } var account = _mapper.Map(model, user); var exists = await Exists(account); if (!exists.Successful) { return(exists); } _accountRepository.BeginTrans(); int result = await _accountRepository.UpdateAsync(account); if (result > 0) { result = _accountRoleRepository.Delete(a => a.Uid == account.Uid); if (result > 0) { //插入角色绑定信息 if (model.RoleList != null && model.RoleList.Count > 0) { var accountRoleList = model.RoleList.Select(m => new AccountRoleEntity { Uid = account.Uid, RoleId = m }).ToList(); await _accountRoleRepository.InsertAsync(accountRoleList); } _accountRepository.Commit(); return(ResultModel.Success()); } } return(ResultModel.Failed()); }
public async Task <IResultModel> Update(AccountUpdateModel model) { var entity = await _accountRepository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("账户不存在!")); } if (entity.IsLock) { return(ResultModel.Failed("账户锁定,不允许修改")); } var account = _mapper.Map(model, entity); var exists = await Exists(account); if (!exists.Successful) { return(exists); } using (var uow = _dbContext.NewUnitOfWork()) { var result = await _accountRepository.UpdateAsync(account, uow); if (result) { result = await _accountRoleRepository.DeleteByAccount(account.Id, uow); if (result) { if (model.Roles != null && model.Roles.Any()) { var accountRoleList = model.Roles.Select(m => new AccountRoleEntity { AccountId = account.Id, RoleId = m }).ToList(); result = await _accountRoleRepository.AddAsync(accountRoleList, uow); } if (result) { uow.Commit(); await ClearPermissionListCache(account.Id); await ClearCache(true, entity.Id); return(ResultModel.Success()); } } } } return(ResultModel.Failed()); }
private async Task <bool> IsTransactionPermitted(AccountUpdateModel accountUpdateModel) { var senderAccountByUserId = await _mediator.Send( new GetAccountByUserIdQuery(accountUpdateModel.UserId)); var senderAccountBySenderId = await _mediator.Send( new GetAccountByIdQuery(accountUpdateModel.SenderAccountId)); return(senderAccountByUserId.Id == senderAccountBySenderId.Id); }
public ActionResult UpdateAccount(int Id) { AccountService service = new AccountService(); AccountUpdateModel model = new AccountUpdateModel(); model = service.GetAccountUpdateById(Id); model.ListRole = DefaultValues.ListRole(); return(View(model)); }
public async Task <ActionResult> UpdateAccount([FromBody] AccountUpdateModel account) { try { if (!ModelState.IsValid) { return(BadRequest()); } if (string.IsNullOrWhiteSpace(account.title)) { throw new Exception("first name is required"); } var cus = await _dBRepository.accounts.Where(l => l.id == account.id).FirstOrDefaultAsync(); if (cus == null) { throw new Exception("there is no account with this id that passed in."); } cus.title = account.title; cus.first_name = account.first_name; cus.last_name = account.last_name; cus.birth_date = account.birth_date; cus.gender = account.Gender; cus.mobile = account.mobile; cus.tel = account.tel; cus.postal_code = account.postal_code; cus.email = account.email; cus.telegram = account.telegram; cus.instagram = account.instagram; cus.address = account.address; cus.membership_join_type_id = account.membership_join_type_id; cus.jobinfo_id = account.jobinfo_id; cus.contract_file_path = account.contract_file_path; await _dBRepository.SaveChangesAsync(); return(Ok(new CoreResponse() { is_success = true, data = cus })); } catch (Exception ex) { return(Ok(new CoreResponse() { is_success = false, data = null, dev_message = ex.Message })); } }
public IActionResult Update(int id, [FromBody] AccountUpdateModel model) { var account = _accounts.FirstOrDefault(account => account.Id == id); if (account == null) { return(NotFound()); } account.Name = model.Name; return(Ok()); }
private void HandleMessage(AccountUpdateModel accountUpdateModel) { if (accountUpdateModel.Message == "ExecuteTransaction") { _accountUpdateService.UpdateAccountsAmount(accountUpdateModel); } else if (accountUpdateModel.Message == "DeleteAccount") { _accountUpdateService.DeleteAccount(accountUpdateModel); } else if (accountUpdateModel.Message == "CreateAccount") { _accountUpdateService.CreateAccount(accountUpdateModel); } }
public async Task DeleteAccount(AccountUpdateModel accountUpdateModel) { try { var accountToDelete = await _mediator.Send( new GetAccountByUserIdQuery(accountUpdateModel.UserId) ); await _mediator.Send( new DeleteAccountCommand(accountToDelete.Id)); } catch (Exception e) { Debug.WriteLine(e.Message); } }
public async Task CreateAccount(AccountUpdateModel accountUpdateModel) { try { await _mediator.Send(new CreateAccountCommand { Amount = 3000, UserId = accountUpdateModel.UserId }); } catch (Exception e) { Console.WriteLine(e); throw; } }
public async Task<ActionResult> UpdateAccount(AccountUpdateModel accountUM) { try { if (accountUM.Roles.Contains(nameof(UserRoles.Admin))) { return BadRequest("Can not update to role Admin!"); } MyUser user = await _userManager.FindByNameAsync(accountUM.UserName); if (user != null) { user = accountUM.Adapt(user); //Chuyen data tu View -> Model var roles = await _userManager.GetRolesAsync(user); if(roles.Contains(nameof(UserRoles.Doctor))) { accountUM.Roles.Add(nameof(UserRoles.Doctor)); } if (roles.Contains(nameof(UserRoles.Nurse))) { accountUM.Roles.Add(nameof(UserRoles.Nurse)); } await _userManager.RemoveFromRolesAsync(user, roles); await _userManager.AddToRolesAsync(user, accountUM.Roles); user.DateUpdated = DateTime.Now; var currentAccount = await _userManager.UpdateAsync(user); if (currentAccount.Succeeded) { return Ok(); } else { return BadRequest(currentAccount.Errors); } } else { return NotFound(); } } catch (Exception e) { return BadRequest(e.Message); } }
public async Task <IActionResult> UpdateAccount(int accountId, [FromBody] AccountUpdateModel body) { var account = await _accountRepository.GetAsync(accountId); if (account == null) { return(NotFound($"Account {accountId} not found.")); } account.Name = body.Name; account.Email = body.Email; await _accountRepository.UpdateAsync(account); await _accountRepository.UnitOfWork.SaveEntitiesAsync(); return(Ok()); }
public ActionResult UpdateAccount(AccountUpdateModel model) { model.ListRole = DefaultValues.ListRole(); if (!IsAdmin()) { model.Message = Configs.ALERT_NOT_ALLOW; model.Code = (int)EnumError.ROLE_WRONG; model.Result = false; model.Redirect = Url.Action("Index", "Word"); return(Redirect("~")); } if (ModelState.IsValid) { AccountService service = new AccountService(); AccountModel accModel = new AccountModel(); model.Mapping(model, ref accModel); int result = service.UpdateAccount(accModel); if (result > 0) { model.Result = true; model.Message = Configs.SUCCESS_UPDATE; model.Redirect = Url.Action("ListAccount", "User"); SetTempData(model.Message, model.Redirect); return(View(model)); } else { model.Result = false; model.Message = GetErrorMessage(result); SetTempData(model.Message); return(View(model)); } } else { var errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); } return(View(model)); }
public virtual async Task <(AccountViewModel, ServiceModelState)> Update( string id, AccountUpdateModel model) { var edit = await context.Accounts .WhereById(id) .SingleOrDefaultAsync(); if (edit == null) { return(null, null); } model.Attach(edit); await UpdateUsuallyUsed(edit); await context.SaveChangesAsync(); return(AccountViewModel.Of(edit), null); }
public bool UpdateAccount(AccountUpdateModel model) { using (var context = new HallAutomationSystemEntities()) { AddressInformation addressInformation = new AddressInformation(); int id = addressInformation.GetStudentId(model.UserName); var account = context.Account.FirstOrDefault(x => x.StudentId == id); if (account != null) { if (account.Due > 0) { int minus = Math.Min((int)account.Due, (int)model.Balance); model.Balance -= minus; account.Due -= minus; } account.Balance += model.Balance; } context.SaveChanges(); return(true); } }
public Task <IResultModel> Update(AccountUpdateModel model) { return(_service.Update(model)); }
public async Task <IActionResult> UpdateAccountAsync([FromRoute] string accountId, [FromBody] AccountUpdateModel model) { var functions = GetCurrentAccountFunctionCodes(); if (!functions.Contains("Account_Full")) { if (accountId != CurrentAccountId) { throw new ForbiddenException(); } } var account = await _accountRepository.GetAccountByIdAsync(accountId); if (account == null) { throw new NotFound404Exception("account"); } if (model.Password != null) { if (model.Password.Length < 8 || model.Password.Length > 20) { throw new PasswordIsInvalidException(); } } if (model.Name != null) { if (model.Name.Length > 50) { throw new NameIsInvalidException(); } } if (model.BirthDate.HasValue) { if (model.BirthDate.Value.Year < Constants.MinBirthDate.Year || model.BirthDate.Value.Year > DateTime.Now.Year - Constants.MinAge) { throw new BirthDateIsInvalidException(); } } if (model.Email != null) { if (!model.Email.IsEmail()) { throw new EmailIsInvalidException(); } if (model.Email != account.Email && await _accountRepository.AnyByEmailAsync(model.Email)) { throw new AlreadyExistsException("email"); } } if (model.Phone != null) { if (!model.Phone.IsMobile()) { throw new PhoneIsInvalidException(); } if (model.Phone != account.Phone && await _accountRepository.AnyByPhoneAsync(model.Phone)) { throw new AlreadyExistsException("phone"); } } if (model.WardId.HasValue) { if (!await _wardRepository.AnyByIdAsync(model.WardId.Value)) { throw new NotFound400Exception("ward"); } } // bind data account.WardId = model.WardId.HasValue ? model.WardId.Value : account.WardId; account.Password = model.Password != null ? model.Password : account.Password; account.Name = model.Name != null ? model.Name : account.Name; account.Gender = model.Gender.HasValue ? model.Gender.Value : account.Gender; account.BirthDate = model.BirthDate.HasValue ? model.BirthDate : account.BirthDate; account.Address = model.Address != null ? model.Address : account.Address; account.Email = model.Email != null ? model.Email : account.Email; account.Phone = model.Phone != null ? model.Phone : account.Phone; account.Avatar = model.Avatar != null ? model.Avatar : account.Avatar; account.Description = model.Description != null ? model.Description : account.Description; account.UpdatedDate = DateTime.Now; await _accountRepository.UpdateAccountAsync(account); return(Ok(AccountDTO.GetFrom(account))); }
public async Task <JsonResult> UpdateUser(AccountUpdateModel model) { var tenant = await this._dbContext.Tenants.FindAsync(model.TenantId); var user = this._dbContext.Users.Find(model.Id); this.saveToAvatar(model.Avatar, user.UserName); user.GivenName = model.GivenName; user.Email = model.Email; user.PhoneNumber = model.PhoneNumber; user.TenantId = model.TenantId; user.TenantName = tenant.Name; user.TenantDb = tenant.ConnectionStrings; user.AvatarUrl = $"{user.UserName}.png"; await this._dbContext.SaveChangesAsync(); var clamins = await this._userManager.GetClaimsAsync(user); var tenantclamin = clamins.Where(x => x.Type == "http://schemas.microsoft.com/identity/claims/tenantid").FirstOrDefault(); if (tenantclamin != null) { await this._userManager.RemoveClaimAsync(user, tenantclamin); } var emailclamin = clamins.Where(x => x.Type == System.Security.Claims.ClaimTypes.Email).FirstOrDefault(); if (emailclamin != null) { await this._userManager.RemoveClaimAsync(user, emailclamin); } var phoneclamin = clamins.Where(x => x.Type == System.Security.Claims.ClaimTypes.MobilePhone).FirstOrDefault(); if (phoneclamin != null) { await this._userManager.RemoveClaimAsync(user, phoneclamin); } var nameclamin = clamins.Where(x => x.Type == System.Security.Claims.ClaimTypes.GivenName).FirstOrDefault(); if (nameclamin != null) { await this._userManager.RemoveClaimAsync(user, nameclamin); } var avatarclamin = clamins.Where(x => x.Type == "http://schemas.microsoft.com/identity/claims/avatarurl").FirstOrDefault(); if (avatarclamin != null) { await this._userManager.RemoveClaimAsync(user, avatarclamin); } await this._userManager.AddClaimAsync(user, new System.Security.Claims.Claim("http://schemas.microsoft.com/identity/claims/tenantid", user.TenantId.ToString())); await this._userManager.AddClaimAsync(user, new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.GivenName, user.GivenName ?? "")); await this._userManager.AddClaimAsync(user, new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.Email, user.Email)); await this._userManager.AddClaimAsync(user, new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.MobilePhone, user.PhoneNumber ?? "")); await this._userManager.AddClaimAsync(user, new System.Security.Claims.Claim("http://schemas.microsoft.com/identity/claims/avatarurl", user.AvatarUrl ?? "")); return(Json(new { success = true })); }