public ActionResult Create(DocRegisterViewModel docRegVM) { ModelState.Clear(); if (ModelState.IsValid) { var cUserEmail = db.UserLogins.FirstOrDefault(x => x.EmailID == docRegVM.Userlogins.EmailID); if (ReferenceEquals(cUserEmail, null)) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { docRegVM.RoleId = 4; generatepassword genpass = new generatepassword(); var TempPassword = genpass.generate_password(); //Take the password for email string password = TempPassword.ToString(); docRegVM.Userlogins.Password = password; //Insert data in Userlogins Table docregistor.InsertDoctor(docRegVM.Userlogins, docRegVM); docregistor.Save(); //Insert data in Login_Role Table var newUserRole = db.UserLoginRoles.Create(); docregistor.InsertDoctorRoles(newUserRole, docRegVM); docregistor.Save(); //if (registerVM.SpecialityID!=0) //{ //Insert data in Login_Speciality Table var newUserspeciality = db.UserLoginSpecialitys.Create(); docregistor.DocLoginSpecialitys(newUserspeciality, docRegVM); docregistor.Save(); // } dbContextTransaction.Commit(); // ViewBag.StatusMessage = " User Name with " + docRegVM.Userlogins.UserName + " having Email Id " + docRegVM.Userlogins.EmailID + " is created successfully"; // ViewBag.Status = 1; @TempData["SuccessMessage"] = " User Name with " + docRegVM.Userlogins.FirstName + " " + docRegVM.Userlogins.LastName + " having Email Id " + docRegVM.Userlogins.EmailID + " is created successfully"; //var callbackUrl = Url.Action("ConfirmEmail", "Account",new { userId = user.Id, code = code },protocol: Request.Url.Scheme); //get user emailid var emailid = docRegVM.Userlogins.EmailID; //send mail string subject = "MyCityMyDoctor Registration"; string body = "Dear " + docRegVM.Userlogins.FirstName + " " + docRegVM.Userlogins.LastName + "<br/> <br/>" + System.Environment.NewLine + System.Environment.NewLine + "You have been successfully registered at MyCityMyDoctor , Your login credentials are given below<br/><br/>" + "<br/><br/>Password" + " : " + password + "<br/><br/><br/>Thank You" + "<br/>Admin" + "<br/>Edox"; //edit it try { SendEMail sendemail = new SendEMail(); sendemail.Send_EMail(emailid, subject, body); @TempData["SuccessMessage"] = "User has been created Successfully. Email sent to " + docRegVM.Userlogins.EmailID + ""; } catch (Exception ex) { //ViewBag.StatusMessage = "User has been created successfully but Error occurred while sending email. Error:" + ex.Message; @TempData["Message"] = "User has been created successfully but Error occurred while sending email. Error:" + ex.Message; } } catch (DbEntityValidationException) { dbContextTransaction.Rollback(); } } } else { @TempData["Message"] = "Email ID Already Exist"; } } return(RedirectToAction("Create")); }
public ActionResult PatientForgotPassword(ForgetPasswordModel forgetPatient) { if (ModelState.IsValid) { using (db) { //check user existance var count = db.patientlogins.Count(u => u.EmailID == forgetPatient.EmailId); if (count == 0) { //ModelState.AddModelError("", "Entered Email does not exist."); @TempData["ErrorMessage"] = "Entered Email does not exist."; } else { generatepassword genPass = new generatepassword(); var TempPassword = genPass.generate_password(); //generate password token var crypto = new SimpleCrypto.PBKDF2(); var token = crypto.Compute(TempPassword); var newUser = db.patientlogins.Where(a => a.EmailID == forgetPatient.EmailId).FirstOrDefault(); if (newUser != null) { newUser.PasswordVerificationToken = token; newUser.PasswordVerificationTokenExpirationDate = System.DateTime.Now.AddHours(48); } db.SaveChanges(); //create url with above token var resetLink = "<a href='" + Url.Action("ResetPasswordPatient", "Account", new { unp = forgetPatient.EmailId, rtp = token }, "http") + "'>Reset Password</a>"; //var resetLink = Url.Action("ResetPassword", "Account", new { un = email, rt = token }, "http"); //get user emailid var emailid = (from i in db.patientlogins where i.EmailID == forgetPatient.EmailId select i.EmailID).FirstOrDefault(); //send mail string subject = "Password Reset Token"; string body = "<b>You have requested to change the password by Forgot Password option, Please find the Password Reset Token in this mail, You can click on the link or copy and paste the link in you browser</b><br/>" + resetLink; //edit it try { SendEMail sendemail = new SendEMail(); sendemail.Send_EMail(emailid, subject, body); // ViewBag.StatusMessage = "An email has been sent to the email address you registered with. Follow the instruction in this email to complete your password reset."; @TempData["Message"] = "An email has been sent to the email address you registered with. Follow the instruction in this email to complete your password reset."; } catch (Exception ex) { // ViewBag.StatusMessage = "Error occured while sending email." + ex.Message; @TempData["ErrorMessage"] = "Error occured while sending email." + ex.Message; } ViewBag.Status = 1; return(View()); } } } return(View(forgetPatient)); }