public List <StudentModel> FetchRecord() { List <StudentModel> students = new List <StudentModel>(); try { using (MyDatabaseEntities1 myDatabase = new MyDatabaseEntities1()) { List <student> sm = new List <student>(); sm = (from temp in myDatabase.students select temp).ToList(); foreach (var item in sm) { StudentModel studentModels = new StudentModel(); studentModels.PersonId = item.id; studentModels.FirstName = item.FirstName; studentModels.LastName = item.LastName; studentModels.Gender = item.Gender; studentModels.City = item.City; studentModels.Email = item.Email; students.Add(studentModels); } } } catch (Exception) { throw; } return(students); }
public StudentModel FetchRecordId(int id) { StudentModel sm = new StudentModel(); try { using (MyDatabaseEntities1 myDatabase = new MyDatabaseEntities1()) { student student = new student(); var temp1 = (from temp in myDatabase.students where temp.id == id select temp).FirstOrDefault(); if (temp1 != null) { sm.FirstName = temp1.FirstName; sm.LastName = temp1.LastName; sm.Gender = temp1.Gender; sm.City = temp1.City; sm.Email = temp1.Email; } } } catch (Exception) { throw; } return(sm); }
public ActionResult ResetPassword(ResetPasswordModel model) { var message = ""; if (ModelState.IsValid) { using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { var user = dc.Users.Where(a => a.ResetPasswordCode == model.ResetCode).FirstOrDefault(); if (user != null) { user.Password = Crypto.Hash(model.NewPassword); user.ResetPasswordCode = ""; dc.Configuration.ValidateOnSaveEnabled = false; dc.SaveChanges(); message = "New password updated successfully"; } } } else { message = "Something invalid"; } ViewBag.Message = message; return(View(model)); }
public string InsertRecordInStudentTable(StudentModel studentModel) { string message = string.Empty; using (MyDatabaseEntities1 myDatabase = new MyDatabaseEntities1()) { var temp = (from temp1 in myDatabase.students where temp1.Email == studentModel.Email select temp1).FirstOrDefault(); if (temp == null) { student sm = new student(); sm.FirstName = studentModel.FirstName; sm.LastName = studentModel.LastName; sm.Gender = studentModel.Gender; sm.City = studentModel.City; sm.Email = studentModel.Email; myDatabase.students.Add(sm); myDatabase.SaveChanges(); } else { message = "Email address already exixts"; } } return(message); }
public ActionResult ResetPassword(string id) { //Verify the password link //Find account associated with this link //Redirect to reset password page if (string.IsNullOrWhiteSpace(id)) { return(HttpNotFound()); } using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { var user = dc.Users.Where(a => a.ResetPasswordCode == id).FirstOrDefault(); if (user != null) { ResetPasswordModel model = new ResetPasswordModel(); model.ResetCode = id; return(View(model)); } else { return(HttpNotFound()); } } }
public ActionResult ForgotPassword(string EmailID) { //Verify Email ID //Generate Reset Password link //Send Email string message = ""; //bool status = false; using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { var account = dc.Users.Where(a => a.EmailID == EmailID).FirstOrDefault(); if (account != null) { //Send email for reset password string resetCode = Guid.NewGuid().ToString(); SendVerificationLinkEmail(account.EmailID, resetCode, "ResetPassword"); account.ResetPasswordCode = resetCode; //This line Ihave added here to avoid confirm password not match issue, as we had added a confirm password property dc.Configuration.ValidateOnSaveEnabled = false; dc.SaveChanges(); message = "Reset password link has been sent to your email id."; } else { message = "Account not found"; } } ViewBag.Message = message; return(View()); }
public bool IsEmailExist(string emailID) { using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { var v = dc.Users.Where(user => user.EmailID == emailID).FirstOrDefault(); return(v != null); } }
public JsonResult GetEvents() { using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { var v = dc.Events.OrderBy(a => a.StartAt).ToList(); return(new JsonResult { Data = v, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode")] User user) { bool Status = false; string message = ""; // // Model Validation if (ModelState.IsValid) { #region //Email is already Exist var isExist = IsEmailExist(user.EmailID); if (isExist) { ModelState.AddModelError("EmailExist", "Email already exist"); return(View(user)); } #endregion #region Generate Activation Code user.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing user.Password = Crypto.Hash(user.Password); user.ConfirmPassword = Crypto.Hash(user.ConfirmPassword); // #endregion user.IsEmailVerified = false; #region Save to Database using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { dc.Users.Add(user); dc.SaveChanges(); //Send Email to User //SendVerificationLinkEmail(user.EmailID, user.ActivationCode.ToString()); message = "Registration successfully done. Account activation link " + " has been sent to your email id:" + user.EmailID; Status = true; } #endregion } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(user)); }
public ActionResult Index() { var emailId = User.Identity.Name; using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { var accountLogin = dc.Users.Where(user => user.EmailID == emailId).FirstOrDefault(); if (accountLogin != null) { return(View()); } } return(HttpNotFound()); }
public ActionResult Login(UserLogin login, string ReturnUrl = "") { string message = ""; using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { var v = dc.Users.Where(a => a.EmailID == login.EmailID).FirstOrDefault(); if (v != null) { /*if (!v.IsEmailVerified) * { * ViewBag.Message = "Please verify your email first"; * return View(); * }*/ if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0) { int timeout = login.RememberMe ? 525600 : 20; // 525600 min = 1 year var ticket = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Index", "Home")); } } else { message = "Invalid credential provided"; } } else { message = "Invalid credential provided"; } } ViewBag.Message = message; return(View()); }
public void DeleteRecord(int id) { try { using (MyDatabaseEntities1 myDatabase = new MyDatabaseEntities1()) { var fetchRecord = (from temp in myDatabase.students where temp.id == id select temp).FirstOrDefault(); myDatabase.students.Remove(fetchRecord); myDatabase.SaveChanges(); } } catch (Exception) { throw; } }
public ActionResult Login(UserLogin login, string ReturnUrl = "") { string message = ""; using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { var accountLogin = dc.Users.Where(user => user.EmailID == login.EmailID).FirstOrDefault(); if (accountLogin != null) { if (string.Compare(Crypto.Hash(login.Password), accountLogin.Password) == 0) { int timeout = login.RememberMe ? 525600 : 1; var ticket = new FormsAuthenticationTicket(login.EmailID, login.RememberMe, timeout); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(timeout); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("WrongPassword", "Password is not correct!"); } } else { ModelState.AddModelError("EmailNotExist", "Email dont exist"); } ViewBag.Message = message; return(View()); } }
public ActionResult Login(UserLogin login, string ReturnUrl) { string message = ""; ViewBag.Message = message; using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { var v = dc.Users.Where(a => a.Email == login.Email).FirstOrDefault(); if (v != null) { if (string.Compare(Crypto.Hash(login.Password), v.Password) == 0) { int timeout = login.RememberMe ? 525600 : 1; var ticket = new FormsAuthenticationTicket(login.Email, login.RememberMe, timeout); string encrypt = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypt); cookie.Expires = DateTime.Now.AddMinutes(timeout); Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { message = "Invalid credential provided"; } } else { message = "Invalid credential provided"; } } ViewBag.Message = message; return(View()); }
public ActionResult VerifyAccount(string id) { bool Status = false; using (MyDatabaseEntities1 dc = new MyDatabaseEntities1()) { dc.Configuration.ValidateOnSaveEnabled = false; //This line i have added here to avoid confirm password does not match issue on save changes var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault(); if (v != null) { v.IsEmailVerified = true; dc.SaveChanges(); Status = true; } else { ViewBag.Message = "Invalid Request"; } } ViewBag.Status = Status; return(View()); }
public void updateRecord(StudentModel model) { try { using (MyDatabaseEntities1 myDatabase = new MyDatabaseEntities1()) { var temp = (from temp1 in myDatabase.students where temp1.Email == model.Email select temp1).FirstOrDefault(); if (temp != null) { temp.FirstName = model.FirstName; temp.LastName = model.LastName; temp.Gender = model.Gender; temp.City = model.City; myDatabase.SaveChanges(); } } } catch (Exception) { throw; } }