public DtoActionResult Put(int id, EntityImpersonationAccount account) { account.Id = id; var result = _impersonationAccountService.Update(account); if (result == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return(result); }
public List <EntityImpersonationAccount> GetForDropDown() { var list = new List <EntityImpersonationAccount>(); var accounts = _uow.ImpersonationAccountRepository.Get(); foreach (var account in accounts) { var imp = new EntityImpersonationAccount(); imp.Id = account.Id; imp.Username = account.Username; list.Add(imp); } return(list); }
public DtoActionResult Update(EntityImpersonationAccount account) { var u = GetAccount(account.Id); if (u == null) { return new DtoActionResult { ErrorMessage = "Account Not Found", Id = 0 } } ; var actionResult = new DtoActionResult(); var validationResult = Validate(account, false); if (validationResult.Success) { if (!string.IsNullOrEmpty(account.Password)) { account.Password = new EncryptionServices().EncryptText(account.Password); } else { account.Password = u.Password; } _uow.ImpersonationAccountRepository.Update(account, u.Id); _uow.Save(); actionResult.Success = true; actionResult.Id = account.Id; } else { return(new DtoActionResult() { ErrorMessage = validationResult.ErrorMessage }); } return(actionResult); }
protected void buttonAddAccount_OnClick(object sender, EventArgs e) { var account = new EntityImpersonationAccount() { Username = txtUsername.Text, Password = txtPassword.Text, }; var result = Call.ImpersonationAccountApi.Post(account); if (result.Success) { EndUserMessage = "Successfully Created Account"; Response.Redirect("~/views/admin/impersonation/edit.aspx?level=2&impersonationId=" + result.Id); } else { EndUserMessage = result.ErrorMessage; } }
public DtoValidationResult Validate(EntityImpersonationAccount account, bool isNew) { var validationResult = new DtoValidationResult { Success = true }; if (string.IsNullOrEmpty(account.Username)) { validationResult.Success = false; validationResult.ErrorMessage = "Account Name Is Not Valid"; return(validationResult); } if (isNew) { if (_uow.ImpersonationAccountRepository.Exists(h => h.Username == account.Username)) { validationResult.Success = false; validationResult.ErrorMessage = "An Account With This Name Already Exists"; return(validationResult); } } else { var original = _uow.ImpersonationAccountRepository.GetById(account.Id); if (original.Username != account.Username) { if (_uow.ImpersonationAccountRepository.Exists(h => h.Username == account.Username)) { validationResult.Success = false; validationResult.ErrorMessage = "An Account With This Name Already Exists"; return(validationResult); } } } return(validationResult); }
public DtoActionResult Add(EntityImpersonationAccount account) { account.Password = new EncryptionServices().EncryptText(account.Password); var actionResult = new DtoActionResult(); var validationResult = Validate(account, true); if (validationResult.Success) { _uow.ImpersonationAccountRepository.Insert(account); _uow.Save(); actionResult.Success = true; actionResult.Id = account.Id; } else { return(new DtoActionResult() { ErrorMessage = validationResult.ErrorMessage }); } return(actionResult); }
public DtoActionResult Post(EntityImpersonationAccount user) { return(_impersonationAccountService.Add(user)); }