/// <summary> /// /// </summary> /// <param name="model"></param> /// <returns></returns> public bool BuildNewMember(CreateMemberViewModel model) { var newMember = new Member() { DisplayName = model.DisplayName, Email = model.Email, MemberSince = DateTime.Now, MemberDetails = new MemberDetails() { MemberSince = DateTime.Now, DisplayName = model.DisplayName } }; try { UoW.Members.Add(newMember); UoW.SaveChanges(); } catch (Exception e) { TempData["message"] = "Error: " + e.InnerException + "\nError registering user. Please try again,"; return false; } TempData["message"] = "Thanks For Registering!!"; return true; }
public ActionResult EnterCreditCard(CreateCreditCardViewModel vm, FormCollection form) { var name = form["NameOnCard"]; var number = form["CardNumber"]; var expMonth = form["Month"]; var expYear = form["Year"]; string lastFour = "******" + number.Last(4); Member member = new Member(); string encryptedCardNumber = Security.EncryptCreditCard(number, "secretAgent007"); if (ModelState.IsValid) { using (db) { member = db.Members.FirstOrDefault(m => m.DisplayName == User.Identity.Name); member.MemberDetails.CreditCards.Add( new CreditCard() { CardholderName = name, CardNumber = encryptedCardNumber, ExpirationMonth = expMonth, ExpirationYear = expYear, LastFour = lastFour }); try { db.MemberDetails.AddOrUpdate(member.MemberDetails); db.SaveChanges(); TempData["toast"] = "<script> $(document).ready(function () {" + "toastr.options = { 'positionClass': 'toast-bottom-right' };" + "toastr.success('Credit card was added successfully to your account!');});</script>"; } catch (Exception e) { TempData["toast"] = "<script> $(document).ready(function () {" + "toastr.options = { 'positionClass': 'toast-bottom-right' };" + "toastr.error(' There was an error adding your credit card info to your account. Please try again.');});</script>"; } } } return RedirectToAction("AddressAndPayment", "Checkout"); }