public async Task <IHttpActionResult> Register(RegisterBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (!result.Succeeded) { return(GetErrorResult(result)); } var accountservice = new AccountService(); var userId = Guid.Parse(accountservice.GetGuid(user.Email)); var walletService = new WalletService(userId); var wallet = new WalletCreate { WalletBalance = 50000 }; if (!walletService.CreateWallet(wallet)) { return(InternalServerError(new Exception("Error creating Wallet."))); } var currencyService = new CurrencyService(); var currencies = currencyService.GetCurrencies(); foreach (var currency in currencies) { var holdingService = new HoldingService(userId); var holding = new HoldingCreate() { CryptoHoldingBalance = 0, CurrencyId = currency.CurrencyId, WalletId = walletService.GetWalletId() }; if (!holdingService.CreateHolding(holding)) { return(InternalServerError(new Exception($"Error creating entry for Holding: {holding.CurrencyId}"))); } } return(Ok()); }
public IHttpActionResult Post(HoldingCreate model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateHoldingService(); if (!service.CreateHolding(model)) { return(InternalServerError()); } return(Ok()); }
public bool CreateHolding(HoldingCreate model) { var entity = new Holding() { WalletId = model.WalletId, CryptoHoldingBalance = model.CryptoHoldingBalance, CurrencyId = model.CurrencyId }; using (var ctx = new ApplicationDbContext()) { ctx.Holdings.Add(entity); return(ctx.SaveChanges() == 1); } }