public ActionResult Register(RegisterVM registerVM) { string lang = null; HttpCookie langCookie = Request.Cookies["culture"]; if (ModelState.IsValid) { using (DbContextTransaction transaction = db.Database.BeginTransaction()) { try { //Create Customer data first and create account data string password = CommonBox.StringSecurity.SHA256Encrypt(registerVM.password); var account = new Account() { AccountName = registerVM.accountname, Password = password, RoleID = 2, CreatedDate = System.DateTime.Now, ModifiedDate = System.DateTime.Now, IsActive = false }; db.Accounts.Add(account); db.SaveChanges(); var customer = new Customer() { CustomerName = registerVM.username, CustomerAddress = registerVM.address, CustomerEmail = registerVM.email, CustomerPhoneNumber = registerVM.phonenumber, GenderID = registerVM.genderid, AccountID = account.AccountID, CustomerBirthday = registerVM.birthday }; db.Customers.Add(customer); db.SaveChanges(); transaction.Commit(); // Send mail authentication string parameterUrl = "/Account/Authentication?security1=" + account.AccountName + "&security2=" + password; string linkAuthentication = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content(parameterUrl)); //Get cookie language choosen if (langCookie != null) { lang = langCookie.Value; } MailBox.SendMailAuthentication(customer.CustomerEmail, "Authentication Account Book Management", linkAuthentication, lang); ModelState.AddModelError("", Model.Resources.Register.Active_Account_Alert); return(View("Login")); } catch { transaction.Rollback(); ModelState.AddModelError("", Model.Resources.Register.Something_Wrong); ViewBag.GenderID = new SelectList(db.Genders, "GenderID", "GenderName"); return(View("Register")); } } } if (langCookie != null) { lang = langCookie.Value; } ViewBag.Lang = lang; return(View()); }