public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { EmailService objEmailService = new EmailService(); string ConfirmationToken = objEmailService.CreateConfirmationToken(); var user = new ApplicationUser() {Email=model.Email, UserName = model.Email,ConfirmationToken= ConfirmationToken }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { objEmailService.SendEmailConfirmation(model.Email, model.Name, ConfirmationToken); Customer objCustomer = new Customer { FirstName=model.Name,LastName=model.LastName ,Address= model.Address, Gender = model.Gender, PhoneNumber = model.PhoneNumber, City = model.City, Country =model.Country ,State = model.State ,ApplicationUserID= user.Id ,PostalCode=model.PostalCode }; db.Customer.Add(objCustomer); db.SaveChanges(); var CustomerID = db.Customer.Where(m=>m.ApplicationUserID==user.Id).FirstOrDefault().ID; PaymentInfo objPaymentInfo = new PaymentInfo() { CustomerID = CustomerID }; db.PaymentInfo.Add(objPaymentInfo); db.SaveChanges(); await this.UserManager.AddToRoleAsync(user.Id, "Customers"); await SignInAsync(user, isPersistent: false); return RedirectToAction("ConfirmAccount", "Account"); } else { AddErrors(result); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult UpdatePayment(FormCollection FormCollection) { var ApplicationUserID = User.Identity.GetUserId(); var ID = db.Customer.Where(m => m.ApplicationUserID == ApplicationUserID).FirstOrDefault().ID; PaymentInfo PaymentInfo = new PaymentInfo(); PaymentInfo.CartNumber = FormCollection["CardNumber"].ToString(); PaymentInfo.SecurityCode = FormCollection["SecurityCode"].ToString(); PaymentInfo.ExpiryDate = FormCollection["cardExpiry"].ToString(); PaymentInfo.CustomerID = ID; db.PaymentInfo.Add(PaymentInfo); db.SaveChanges(); return RedirectToAction("Dashboard"); }