public static Account ToAccount(this AccountCreateModel entity) { if (entity == null) { return(null); } return(new Account { // TODO: Id = entity.Id - BLL (+mappers) Number = entity.Number, InvoiceAmount = entity.Balance, Owner = new Person { FirstName = entity.Owner.FirstName, SecondName = entity.Owner.MiddleName, LastName = entity.Owner.LastName }, AccountType = new AccountType { Name = entity.AccountType.Name, DepositCost = entity.AccountType.DepositCost, WithdrawCost = entity.AccountType.WithdrawCost } }); }
public async Task Setup() { var model = new AccountCreateModel { BirthDate = new DateTime(1990, 1, 1), Balance = initialBalance }; var lastName = "Фамилия"; var firstName = "Имя"; var middleName = "Отчество"; // Creating accounts for (int i = 1; i <= accountsNumber; i++) { model.LastName = lastName + i.ToString(); model.FirstName = firstName + i.ToString(); model.MiddleName = middleName + i.ToString(); var requestContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); var response = await this.Client.PostAsync("api/accounts", requestContent); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created)); var content = await response.Content.ReadAsStringAsync(); var account = JsonConvert.DeserializeObject <Account>(content); this.accounts.Add(account); } }
public IActionResult CreateComprador() { var userID = this.userManager.GetUserId(User); AccountCreateModel model = new AccountCreateModel(); return(View(model)); }
public async Task <Account> CreateAccount([FromBody] AccountCreateModel data) { var entity = _accountRepository.Add(new Account(data.Name, data.Email, AccountStatus.Created)); await _accountRepository.UnitOfWork.SaveEntitiesAsync(); return(entity); }
public void NewAccountCreateTest() { //Arrange string accountNum = "7777"; string pin = "7777"; int accountType = 1; decimal startingBalance = 7777; int customerId = 1; AccountCreateModel newAccount = new AccountCreateModel { AccountNumber = accountNum, Pin = pin, AccountType = accountType, Balance = startingBalance, CustomerId = customerId }; //Act newAccount.AccountNumber = "7777"; newAccount.Pin = "7777"; newAccount.AccountType = 1; newAccount.Balance = 7777; newAccount.CustomerId = 1; //Assert Assert.AreEqual(newAccount.AccountNumber, accountNum); Assert.AreEqual(newAccount.Pin, pin); Assert.AreEqual(newAccount.AccountType, accountType); Assert.AreEqual(newAccount.Balance, startingBalance); Assert.AreEqual(newAccount.CustomerId, customerId); }
public async Task <ActionResult> Create(AccountCreateModel account) { return(await PostResult( async() => await accountService.Create(account), accountId => new { Id = accountId }, nameof(account) )); }
public async Task <IActionResult> Create(AccountCreateModel accountModel) { HttpResponseMessage response = await HttpClient.PostAsJsonAsync(AccountsAPIEndpoint, accountModel); if (response.IsSuccessStatusCode) { return(RedirectToAction(nameof(AccountsController.Index), "Accounts")); } ModelState.AddModelError("", "Could not create new Account"); return(View()); }
public async Task <ActionResult> Create() { var model = new AccountCreateModel { UsePersonalStorage = true }; var personalStorages = (await _storageDbCommand.GetListByOwnerAsync(User.Identity.Name, 0, int.MaxValue)).Where(x => x.StorageType == StorageType.Personal).ToArray(); model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); }
public async Task <IActionResult> CreateProdutor(AccountCreateModel model) { var userID = this.userManager.GetUserId(User); if (ModelState.IsValid) { var produtor = model.GetAccountCreateModelProdutor(userID); await produtorHandler.Inserir(produtor); return(RedirectToAction("Index", "Home")); } return(View(model)); }
public async Task TestRegister() { var model = new AccountCreateModel { LastName = "Смирнов", FirstName = "Николай", MiddleName = "Васильевич", BirthDate = new DateTime(1987, 10, 26), Balance = 200 }; // Test account registration var requestContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); var response = await this.Client.PostAsync("api/accounts", requestContent); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.Created)); var content = await response.Content.ReadAsStringAsync(); var account = JsonConvert.DeserializeObject <Account>(content); Assert.That(account.LastName, Is.EqualTo("Смирнов")); Assert.That(account.FirstName, Is.EqualTo("Николай")); Assert.That(account.MiddleName, Is.EqualTo("Васильевич")); Assert.That(account.BirthDate, Is.EqualTo(new DateTime(1987, 10, 26))); Assert.That(account.Balance, Is.EqualTo(200)); // Test getting account by id response = await this.Client.GetAsync($"/api/accounts/{account.Id}"); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK)); content = await response.Content.ReadAsStringAsync(); account = JsonConvert.DeserializeObject <Account>(content); Assert.That(account.LastName, Is.EqualTo("Смирнов")); Assert.That(account.FirstName, Is.EqualTo("Николай")); Assert.That(account.MiddleName, Is.EqualTo("Васильевич")); Assert.That(account.BirthDate, Is.EqualTo(new DateTime(1987, 10, 26))); Assert.That(account.Balance, Is.EqualTo(200)); // Test deleting account response = await this.Client.DeleteAsync($"/api/accounts/{account.Id}"); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NoContent)); // Test getting removed account by id response = await this.Client.GetAsync($"/api/accounts/{account.Id}"); Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound)); }
public IActionResult Create([FromBody] AccountCreateModel model) { if (!_accountDomainService.CheckIfUserExistsFromHeader(HttpContext.Request)) { return(Unauthorized()); } else { var account = new Account(model.Name); _accountRepository.Create(account); return(Ok()); } }
public bool CreateAccount(AccountCreateModel model) { using (var ctx = new BankEntities()) { var entity = new Account { AccountNumber = model.AccountNumber, AccountType = model.AccountType, Balance = model.Balance, Pin = model.Pin, CustomerID = model.CustomerId, CreatedUtc = DateTime.Now }; ctx.Accounts.Add(entity); return(ctx.SaveChanges() == 1); } }
/// <summary> /// Account Create Methods /// </summary> /// <param name="id"></param> public static void CreateAccountConsole(int id) { string accountNum = CreateRandomAccountDialogue(); string pin = CreateAccountDialogue(); int accountType = CreateAccountTypeDialogue(); decimal startingBalance = CreateStartingBalanceDialogue(); AccountCreateModel newAccount = new AccountCreateModel { AccountNumber = accountNum, Pin = pin, AccountType = accountType, Balance = startingBalance, CustomerId = id }; accountService.CreateAccount(newAccount); }
public void CreateAccount(AccountCreateModel model) { using (var session = Dao.SessionFactory.OpenSession()) using (var tx = session.BeginTransaction()) { var level = session.QueryOver <AccountLevelEntity>().Where(l => l.Identity == model.Levelidentity).List().FirstOrDefault(); var community = session.QueryOver <AccountCommunityEntity>().Where(c => c.Identity == model.CommunityIdentity).List().FirstOrDefault(); if (level == null || community == null) { return; } var salt = DateTime.Now.ToString("yy-MM-dd").Md5Hash(); var passEncrypted = model.Password.Md5Hash(salt); var account = new AccountEntity { Community = community, Level = level, Profile = new AccountProfileEntity { Pseudo = model.Pseudo, SecretAnswer = model.SecretAnswer, SecretQuestion = model.SecretQuestion }, Trace = new AccountTraceEntity { LastConnectionDate = DateTime.Now, LastConnectionHost = "" }, State = new AccountStateEntity { BannedAt = DateTime.Now, Identity = 0, SubscribedAt = DateTime.Now }, Username = model.Username, Salt = salt, Password = passEncrypted }; session.Save(account); tx.Commit(); } }
/// <summary> /// This API is used to create an account in Cloud Storage. This API bypass the normal email verification process and manually creates the user. <br><br>In order to use this API, you need to format a JSON request body with all of the mandatory fields /// </summary> /// <param name="accountCreateModel">Model Class containing Definition of payload for Account Create API</param> /// <param name="fields">The fields parameter filters the API response so that the response only includes a specific set of fields</param> /// <returns>Response containing Definition for Complete profile data</returns> /// 18.1 public ApiResponse <Identity> CreateAccount(AccountCreateModel accountCreateModel, string fields = "") { if (accountCreateModel == null) { throw new ArgumentException(BaseConstants.ValidationMessage, nameof(accountCreateModel)); } var queryParameters = new QueryParameters { { "apiKey", ConfigDictionary[LRConfigConstants.LoginRadiusApiKey] }, { "apiSecret", ConfigDictionary[LRConfigConstants.LoginRadiusApiSecret] } }; if (!string.IsNullOrWhiteSpace(fields)) { queryParameters.Add("fields", fields); } var resourcePath = "identity/v2/manage/account"; return(ConfigureAndExecute <Identity>(HttpMethod.POST, resourcePath, queryParameters, ConvertToJson(accountCreateModel))); }
public IActionResult Create(AccountCreateModel model) { var accounts = _accounts.OrderByDescending(account => account.Id); var accountWithBiggestId = accounts.FirstOrDefault(); var id = accountWithBiggestId?.Id ?? 1; id += 1; var account = new Account { Id = id, Name = model.Name, Balance = model.Balance }; _accounts.Add(account); return(Ok(new { account.Id })); }
public async Task <IActionResult> ApproveRegistry([FromBody] MemberRegistryApproveModel model) { var accountMicroService = new AccountMicroService(_AppConfig.APIGatewayServer, Token); var mapping = new Func <MemberRegistry, Task <MemberRegistry> >(async(entity) => { entity.IsApprove = true; entity.Approver = CurrentAccountId; return(await Task.FromResult(entity)); }); var afterUpdated = new Func <MemberRegistry, Task>(async(entity) => { var user = new AccountCreateModel(); user.Mail = GuidGen.NewGUID();//使用guid作为邮件,以防邮件重复创建用户失败 user.Phone = entity.Phone; user.Name = entity.Name; user.Password = AppConst.NormalPassword; user.Description = entity.Description; user.ActivationTime = DateTime.Now; user.ExpireTime = DateTime.Now.AddYears(1); var dto = await accountMicroService.CreateAccount(user); //创建会员基本信息 if (dto != null) { var member = new Member(); member.AccountId = dto.Id; member.Province = entity.Province; member.City = entity.City; member.County = entity.County; member.Company = entity.Company; member.BusinessCard = entity.BusinessCard; member.Inviter = entity.Inviter; member.Superior = entity.Inviter; await _MemberRepository.CreateAsync(member, CurrentAccountId); } }); return(await _PutRequest(model.Id, mapping, afterUpdated)); }
public async Task <IActionResult> Create(AccountCreateModel Model) { if (!this.ModelState.IsValid) { return(View(Model ?? new AccountCreateModel())); // Fix your errors please } UserCreateResponse createResponse = await this.userRepository.CreateUserAsync(new UserCreateRequest { Email = Model.Email, Password = Model.Password }); if (!createResponse.Success) { foreach (var error in createResponse.Errors) { this.ModelState.AddModelError(error.Field, error.Message); } return(View(Model)); } return(RedirectToAction("CreateSuccess")); }
public async Task <ActionResult <Account> > Register(AccountCreateModel model) { if (model.Balance < 0) { this.ModelState.AddModelError(nameof(model.Balance), "Balance can not be negative!"); } if (this.ModelState.IsValid) { var account = new Account { FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName, BirthDate = model.BirthDate?.Date, Balance = model.Balance }; this.context.Accounts.Add(account); await this.context.SaveChangesAsync(); return(CreatedAtAction(nameof(Get), new { id = account.Id }, account)); } return(this.BadRequest(this.ModelState)); }
public virtual async Task <(string, ServiceModelState)> Create( AccountCreateModel model) { var account = new Account { Id = Guid.NewGuid().ToString(), }; model.Attach(account); await UpdateUsuallyUsed(account); account.DispOrder = ( await context.Accounts.AsNoTracking() .Where(a => a.FinanceDiv == account.FinanceDiv) .MaxAsync(a => (int?)a.DispOrder) ?? 0) + 1; await context.Accounts.AddAsync(account); await context.SaveChangesAsync(); return(account.Id, null); }
public async Task<ActionResult> CreateAccount(AccountCreateModel accountCM) { //Check role List<string> roles = accountCM.Roles.ToList(); foreach (var i in roles) { //Not allow to add Admin , Doctor , Nurse if ( //i.ToLower().Equals(nameof(UserRoles.Admin).ToLower()) || i.ToLower().Equals(nameof(UserRoles.Doctor).ToLower()) || i.ToLower().Equals(nameof(UserRoles.Nurse).ToLower()) || i.ToLower().Equals(nameof(UserRoles.Customer).ToLower())) return BadRequest("Role can not contains Admin , Doctor , Nurse, Customer"); } try { MyUser user = accountCM.Adapt<MyUser>(); user.IsActive = true; user.IsCustomer = false; user.DateCreated = DateTime.Now; var currentUser = await _userManager.CreateAsync(user, accountCM.Password); if (currentUser.Succeeded) { await _userManager.AddToRolesAsync(user, accountCM.Roles); return StatusCode(201); } else { return BadRequest(currentUser.Errors); } } catch (Exception e) { return BadRequest(e.Message); } }
public async Task <IActionResult> CreateAccountAsync([FromBody] AccountCreateModel model) { if (string.IsNullOrWhiteSpace(model.Password)) { throw new IsRequiredException("password"); } 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 (await _accountRepository.AnyByEmailAsync(model.Email)) { throw new AlreadyExistsException("email"); } } if (model.Phone != null) { if (!model.Phone.IsMobile()) { throw new PhoneIsInvalidException(); } if (await _accountRepository.AnyByPhoneAsync(model.Phone)) { throw new AlreadyExistsException("phone"); } } if (string.IsNullOrWhiteSpace(model.AccountId)) { throw new IsRequiredException("accountId"); } if (model.AccountId.Length > 20) { throw new AccountIdIsInvalidException(); } if (await _accountRepository.AnyByIdAsync(model.AccountId)) { throw new AlreadyExistsException("account"); } if (model.WardId.HasValue) { if (!await _wardRepository.AnyByIdAsync(model.WardId.Value)) { throw new NotFound400Exception("ward"); } } var now = DateTime.Now; var account = new Account { AccountId = model.AccountId, GroupId = 4, WardId = model.WardId.HasValue ? model.WardId.Value : 0, Password = model.Password, Name = model.Name != null ? model.Name : null, Gender = model.Gender.HasValue ? model.Gender.Value : null, BirthDate = model.BirthDate.HasValue ? model.BirthDate : null, Address = model.Address != null ? model.Address : null, Email = model.Email != null ? model.Email : null, Phone = model.Phone != null ? model.Phone : null, CreatedDate = now, UpdatedDate = now }; await _accountRepository.CreateAccountAsync(account); return(Ok(AccountDTO.GetFrom(account))); }
private void CreateUser(AccountCreateModel accountCreateModel) { this._actionResult = this._accountController.Create(accountCreateModel); }
public void WhenTryToCreateAccountWithNameAndPassword(Table table) { _accountCreateModel = GetAccountCreateModel(table); GetAccountController(); CreateUser(_accountCreateModel); }
public async Task <ActionResult> Create(AccountCreateModel model) { var personalStorages = (await _storageDbCommand.GetListByOwnerAsync(User.Identity.Name, 0, int.MaxValue)).Where(x => x.StorageType == StorageType.Personal).ToArray(); if (!ModelState.IsValid) { model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } if (Account.IsReservedName(model.Name)) { ModelState.AddModelError("Name", "この名前は使用できません。"); model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } if (await _accountDbCommand.ExistsAsync(model.Name)) { ModelState.AddModelError("Name", "この名前はすでに使用されています。"); model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } if (model.UsePersonalStorage && string.IsNullOrWhiteSpace(model.PersonalStorageId)) { ModelState.AddModelError("PersonalStorageId", @"個別ストレージを使用する場合は、ストレージを選択する必要があります。 選択リストに出てこない場合は、ストレージタブから新しい個別ストレージを登録してください。"); model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } Account account; if (model.UsePersonalStorage) { var storage = personalStorages.FirstOrDefault(x => x.Id == model.PersonalStorageId); if (storage == null) { ModelState.AddModelError("PersonalStorageId", @"ストレージの選択が不正なようです。もう一度ストレージを選び直してください。"); model.PersonalSorages = personalStorages.Select(x => new SelectListItem { Text = x.Name, Value = x.Id }).ToList(); return(View("Create", model)); } account = Account.NewAccount(model.Name, User.Identity.Name, StorageType.Personal); account.Storages.Add(storage); Mapper.Map(model, account); } else { account = Account.NewAccount(model.Name, User.Identity.Name, StorageType.Common); Mapper.Map(model, account); } await _accountDbCommand.CreateAsync(account); return(RedirectToAction("Index")); }
public User MapFromViewModelToDomain(AccountCreateModel model) { return AutoMapper.Mapper.Map<AccountCreateModel, User>(model); }
/// <summary> /// Creates account. /// </summary> /// <param name="accessToken"> /// The access token. /// </param> /// <returns> /// The account. /// </returns> private static async Task <AccountGetModel> CreateAccount(string accessToken) { // Generate a unique dummy name, to make sure there is no conflict with existing accounts. var accountName = $"imqa-api{CreateRandomString(4)}"; var login = $"imqa-api@{accountName}.com"; // Use Intermedia's HQ address - for demonstartion purposes only. // Please use real enduser address, or your own legal address for real accounts. var address = new AddressModel { Country = "United States", State = "California", City = "Mountain View", Street = "825 E. Middlefield Rd", Zip = "94043-4025" }; var accountToCreate = new AccountCreateModel { // Program is always 'Account' for regular partners. // You only need to specify 'Partner' when you create sub-partners in Distributor model. Programs = new[] { AccountProgramModel.Account }, General = new AccountGeneralModel { AccountName = accountName, // Account owner, the contact who has full access to account. Owner = new AccountOwnerModel { // Create new account contact. // Existent ContactID can be used instead. Contact = new AccountOwnerCreateModel { // Credentials: Login = login, Password = $"{CreateRandomString(8)}_!@#", // In Distributor model, you have to specify the sub-parent partner customer id, to create account within its container. // You do not need this in regular partner model - by default, accounts are created in your container. // ParentCustomerID = "0158A13EF5D74E2D8CCD34C0E87F5034", // Account contact owner data: Name = $"Account Owner for {accountName}", Email = $"{accountName}@qa.qa" } } }, Company = new CompanyModel { Name = accountName, Phone = "1234567890", Address = address }, Payment = new PaymentModel { Name = accountName, Phone = "1234567890", Address = address, Type = PaymentTypeModel.PaperCheck /* * * You should use credit cards only if you process account payments through Intermedia-provided payment processor. * Please contact your Customer Service representative if you would like to set one up. * * Type = PaymentTypeModel.CreditCard, * CreditCard = new PaymentCreditCardModel * { * Type = "VISA", * CardNumber = "4111111111111111", * ExpirationDate = "04/18", * SecurityCode = "111" * } */ }, // Plan name is required for account program. // We use the most popular one here. PlanName = "E2016_Exch_1" }; // Please take a look at online documentation: // https://cp.serverdata.net/webservices/restapi/docs-ui/index#!/Account_management/AccountsV1_PostAccount return(await CallUsingHttpClientAsync <AccountCreateModel, AccountGetModel>( $"{ResourceServerEndpointAddress}/accounts", HttpMethod.Post, accessToken, accountToCreate)); }