public async Task <IActionResult> SignUp(UserToSignUpDTO model) { ApplicationUser newUser = new ApplicationUser { Id = Guid.NewGuid().ToString(), UserName = model.Email, Email = model.Email, LastName = model.LastName, FirstName = model.FirstName, PhoneNumber = model.PhoneNumber }; var result = await _userManager.CreateAsync(newUser, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(newUser, model.Role); if (model.Role != "Admin") { UserMainCurrencyDetail mainCurrency; try { mainCurrency = new UserMainCurrencyDetail { ApplicationUserId = newUser.Id, MainCurrency = model.MainCurrency }; await _userMainCurrencyRepository.AddMainCurrency(mainCurrency); } catch (Exception e) { await _userManager.DeleteAsync(newUser); _logger.LogError(e.Message); return(BadRequest(ResponseMessage.Message("Bad request", errors: new { message = "Failed to add main currency" }))); } try { Wallet wallet = new Wallet { WalletId = Guid.NewGuid().ToString(), ApplicationUserId = newUser.Id, WalletCurrency = model.MainCurrency }; await _walletRepository.AddWallet(wallet); } catch (Exception e) { await _userManager.DeleteAsync(newUser); await _userMainCurrencyRepository.DeleteMainCurrency(mainCurrency); _logger.LogError(e.Message); return(BadRequest(ResponseMessage.Message("Bad request", errors: new { message = "Failed to add wallet" }))); } } } else { foreach (var err in result.Errors) { ModelState.AddModelError("", err.Description); } return(BadRequest(ResponseMessage.Message("Bad request", errors: new { message = ModelState }))); } return(Ok(ResponseMessage.Message("Success! User created", data: new { newUser.Id }))); }
public async Task <bool> DeleteMainCurrency(UserMainCurrencyDetail model) { _ctx.UserMainCurrencyDetails.Remove(model); return(await _ctx.SaveChangesAsync() > 0); }
public async Task <bool> UpdateMainCurrency(UserMainCurrencyDetail updateModel) { _ctx.UserMainCurrencyDetails.Update(updateModel); return(await _ctx.SaveChangesAsync() > 0); }
public async Task <bool> AddMainCurrency(UserMainCurrencyDetail model) { await _ctx.UserMainCurrencyDetails.AddAsync(model); return(await _ctx.SaveChangesAsync() > 0); }