//need bankaccount(IBAN), username, card() public async Task <ActionResult <MessageModel> > CreateDebitcard(DebitCardRequestModel requestModel) { var currentUser = HttpContext.User; return(await _debitCardService.CreateDebitCard(currentUser, requestModel.Username, requestModel.ChargeAccount, requestModel.Card)); }
public async Task <ActionResult <MessageModel> > CreateChargeAccount(ClaimsPrincipal currentUser, ChargeAccountRequestModel requestModel, IDebitCardsService _debitCardService) { string role = ""; var username = requestModel.Username; ChargeAccount chargeAcc = requestModel.ChargeAccount; BCryptPasswordHasher _BCrypt = new BCryptPasswordHasher(); if (currentUser.HasClaim(c => c.Type == "Roles")) { string userRole = currentUser.Claims.FirstOrDefault(currentUser => currentUser.Type == "Roles").Value; role = userRole; } if (role == "Admin") { var userAuthenticate = await dbContext.Users.FirstOrDefaultAsync(x => x.Username == username); if (userAuthenticate != null) { if (dbContext.ChargeAccounts.Where(x => x.UserId == userAuthenticate.Id).Count() < 10) { try { if (ValidateUser(userAuthenticate) && ValidateChargeAccount(chargeAcc)) { chargeAcc.UserId = userAuthenticate.Id; chargeAcc.Iban = IBANGenerator.GenerateIBANInVitoshaBank("ChargeAccount", dbContext); await dbContext.AddAsync(chargeAcc); await dbContext.SaveChangesAsync(); Card card = new Card(); await _debitCardService.CreateDebitCard(currentUser, username, chargeAcc, card); SendEmail(userAuthenticate.Email, _config); responseModel.Message = "Charge Account created succesfully"; return(StatusCode(201, responseModel)); } else if (ValidateUser(userAuthenticate) == false) { responseModel.Message = "User not found!"; return(StatusCode(404, responseModel)); } else if (ValidateChargeAccount(chargeAcc) == false) { responseModel.Message = "Invalid parameteres!"; return(StatusCode(400, responseModel)); } } catch (NullReferenceException) { responseModel.Message = "Invalid parameteres!"; return(StatusCode(400, responseModel)); } } responseModel.Message = "User already has 10 Charge Accounts!"; return(StatusCode(400, responseModel)); } else { responseModel.Message = "User not found!"; return(StatusCode(404, responseModel)); } } else { responseModel.Message = "You are not authorized to do such actions"; return(StatusCode(403, responseModel)); } }