public ActionResult ForgotPassword(ForgotPasswordModel model, int? Id) { if (model != null) { if (Id == 1) { var objLandlore = dbContext.LandlordRegistrations.FirstOrDefault(r => r.Email == model.EmailId && r.IsActive == true); if (objLandlore != null) { var guid = Convert.ToString(Guid.NewGuid()); objLandlore.TokenId = guid; dbContext.Entry(objLandlore).State = EntityState.Modified; dbContext.SaveChanges(); SendResetPasswordLink(objLandlore.Email, guid, Convert.ToString(Id)); return RedirectToAction("ForgotPasswordMessage"); } } else if (Id == 2) { var reg = dbContext.TenantRegistrations.FirstOrDefault(r => r.Email == model.EmailId && r.IsActive == true); if (reg != null) { var guid = Convert.ToString(Guid.NewGuid()); reg.TokenId = guid; dbContext.Entry(reg).State = EntityState.Modified; dbContext.SaveChanges(); SendResetPasswordLink(reg.Email, guid, Convert.ToString(Id)); return RedirectToAction("ForgotPasswordMessage"); } } } ViewBag.id = Id; ModelState.AddModelError("", "Invalid Email Id."); return View(); }
public ActionResult ResetPassword(ForgotPasswordModel model, string token, string id) { if (!string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(id)) { if (id == "1") { var reg = dbContext.LandlordRegistrations.FirstOrDefault(r => r.TokenId == token && r.IsActive == true); if (reg != null) { reg.Password = model.NewPassword; reg.TokenId = null; dbContext.Entry(reg).State = EntityState.Modified; dbContext.SaveChanges(); return RedirectToAction("ResetPasswordConfirmation"); } } if (id == "2") { var reg = dbContext.TenantRegistrations.FirstOrDefault(r => r.TokenId == token && r.IsActive == true); if (reg != null) { reg.Password = model.NewPassword; reg.TokenId = null; dbContext.Entry(reg).State = EntityState.Modified; dbContext.SaveChanges(); return RedirectToAction("ResetPasswordConfirmation"); } } } ModelState.AddModelError("", "Invalid token id"); return View(); }