public IActionResult Billing() { UserEntity ue = _usersRepo.GetUserByUsername(User.Identity.Name); BillingInformationModel billingInformation = _mapper.Map <BillingInformationModel>(ue); return(View(billingInformation)); }
public async Task <IActionResult> Billing([FromForm] BillingInformationModel billingInfo) { try { if (ModelState.IsValid) { UserEntity ue = _usersRepo.GetUserByUsername(User.Identity.Name); ue.CreditCardCompany = billingInfo.CreditCardCompany; ue.CreditCardNumber = billingInfo.CreditCardNumber; await _usersRepo.SaveAllAsync(); this.AddInformationMessage("Billing information saved!"); } else { return(View(billingInfo)); } } catch (Exception ex) { _logger.LogError(ex.Message, ex); } return(RedirectToAction("Index", "Home")); }
public async Task <BillingInformationModel> Validate(BillingInformationModel model) { if (model.NameOnCard == null || model.NameOnCard == string.Empty) { throw new BillingInformationNameOnCardIsRequiredException(); } if (model.CardNumber == null || model.NameOnCard == string.Empty) { throw new BillingInformationNameOnCardIsRequiredException(); } if (!Helpers.IsCreditCardNumberValid(model.CardNumber)) { throw new BillingInformationCardNumberIsInvalidException(); } if (model.CardSecurityValue == null || model.CardSecurityValue == string.Empty) { throw new BillingInformationCardSecurityNumberIsRequiredException(); } if (!int.TryParse(model.CardSecurityValue, out int csv)) { throw new BillingInformationCardSecurityNumberIsInvalidException(); } model.Address = await _addressService.Validate(model.Address); return(model); }
// Create entity from model. public BillingInformation(BillingInformationModel model) { Id = Guid.NewGuid().ToString(); NameOnCard = model.NameOnCard; CardNumber = model.CardNumber; CardSecurityValue = model.CardSecurityValue; ExpirationMonth = model.ExpirationMonth; ExpirationYear = model.ExpirationYear; Address = new SystemAddress(model.Address); }