public ActionResult Login(User objUser) { User UserExist = objContext.ContextUser.SingleOrDefault(s => s.Email == objUser.Email && s.Password == objUser.Password && s.Status == 1); if (UserExist != null) { Session["UserId"] = UserExist.Id; return RedirectToAction("Home"); } TempData.Remove("Message"); TempData.Add("Message", "Login failed"); return View(objUser); }
public ActionResult SignUp(User objUser) { int stat = 0; if (string.IsNullOrEmpty(objUser.Name)) { ModelState.AddModelError("Name", "Please enter the Name"); } if (string.IsNullOrEmpty(objUser.Email)) { ModelState.AddModelError("Email", "Please enter the email"); } if (string.IsNullOrEmpty(objUser.Password)) { stat = 1; ModelState.AddModelError("Password", "Enter password"); } if (string.IsNullOrEmpty(objUser.ConfirmPwd)) { stat = 1; ModelState.AddModelError("ConfirmPwd", "Enter confirm password"); } if (stat == 0 && objUser.Password != objUser.ConfirmPwd) { ModelState.AddModelError("ConfirmPwd", "Password missmatch"); } if(ModelState.Values.SelectMany(s=>s.Errors).Count()>0) { return View(objUser); } User objUserCheck = objContext.ContextUser.SingleOrDefault(s => s.Email == objUser.Email && s.Status == 1); if (objUserCheck != null) { TempData.Remove("Message"); TempData.Add("Message", "User already exists"); return View(objUser); } objUser.CreatedDtm = DateTime.Now; objUser.Status = 1; objContext.ContextUser.Add(objUser); objContext.SaveChanges(); Session["UserId"] = objUser.Id; return RedirectToAction("Home"); }
public ActionResult EditPreference(User objUser) { objUser.PreferencesList = objContext.ContextPreferences.Where(s => s.Status == 1).ToList(); if (objUser.SelectedPreferences == null) objUser.SelectedPreferences = new int[] { }; try { User objUserExist = objContext.ContextUser.Include("UserPreferencesList").SingleOrDefault(s => s.Id == objUser.Id); objContext.ContextUserPreferences.RemoveRange(objUserExist.UserPreferencesList); objUserExist.UserPreferencesList = new List<UserPreferences>(); UserPreferences objUserPreferences; foreach (int id in objUser.SelectedPreferences) { objUserPreferences = new UserPreferences(); objUserPreferences.Preferences = objContext.ContextPreferences.Find(id); objUserExist.UserPreferencesList.Add(objUserPreferences); } objContext.SaveChanges(); return RedirectToAction("Home"); } catch { } return View(objUser); }
public ActionResult EditProfile(User objUser) { if (string.IsNullOrEmpty(objUser.Name)) { ModelState.AddModelError("Name", "Enter name"); } if (ModelState.Values.SelectMany(s => s.Errors).Count() > 0) { return View(objUser); } User objUserExist = objContext.ContextUser.Find(objUser.Id); objUserExist.Name = objUser.Name; objContext.SaveChanges(); return RedirectToAction("Home"); }
public ActionResult ForgotPassword(User objUser) { if (string.IsNullOrEmpty(objUser.Email)) { ModelState.AddModelError("Email", "Please enter the email"); } if (ModelState.Values.SelectMany(s => s.Errors).Count() > 0) { return View(objUser); } User UserExist = objContext.ContextUser.SingleOrDefault(s => s.Email == objUser.Email); if(UserExist!=null) { string str = System.IO.File.ReadAllText(Server.MapPath("/MailTemplate/ForgotPassword.html")); str = str.Replace("<%firstname%>", UserExist.Name); str = str.Replace("<%loginid%>", UserExist.Email); str = str.Replace("<%password%>", UserExist.Password); str = str.Replace("<%URL%>", CONST.URL); CommonFunctions objCommon = new CommonFunctions(); int i = objCommon.SendMailByDynamicSMTP(UserExist.Email, "Login Details for DineOutEasy.com", str); if(i==1) { TempData.Remove("Message"); TempData.Add("Message", "Password sent to your email address, please check your mail."); return RedirectToAction("Index"); } else { TempData.Remove("Message"); TempData.Add("Message", "Error occured, please try again later"); return RedirectToAction("Index"); } } TempData.Remove("Message"); TempData.Add("Message", "User does not exist"); return View(objUser); }
public ActionResult ResetPassword(User ObjUser) { int stat = 0; if (string.IsNullOrEmpty(ObjUser.Password)) { ModelState.AddModelError("Password", "Enter the current password"); } if (string.IsNullOrEmpty(ObjUser.NewPwd)) { stat = 1; ModelState.AddModelError("NewPwd", "Enter new password"); } if (string.IsNullOrEmpty(ObjUser.ConfirmPwd)) { stat = 1; ModelState.AddModelError("ConfirmPwd", "Enter confirm password"); } if (stat == 0 && ObjUser.NewPwd != ObjUser.ConfirmPwd) { ModelState.AddModelError("ConfirmPwd", "Password missmatch"); } if (ModelState.Values.SelectMany(s => s.Errors).Count() > 0) { return View(ObjUser); } if (Session["UserId"] != null) { int uid=Convert.ToInt32(Session["UserId"]); if (ObjUser.NewPwd == ObjUser.ConfirmPwd) { User objUserExist = objContext.ContextUser.SingleOrDefault(s => s.Id == uid && s.Password == ObjUser.Password); if (objUserExist != null) { objUserExist.Password = ObjUser.NewPwd; objContext.SaveChanges(); return RedirectToAction("Home"); } } } TempData.Remove("Message"); TempData.Add("Message", "Failed to reset password"); return View(ObjUser); }
public ActionResult SearchByRestaurant(User objUser) { int id = 0; List<MenuPreferences> objMenuPrefList; SearchResult objResult; objUser.SearchResult = new List<SearchResult>(); objUser.PreferencesList = objContext.ContextPreferences.Where(s => s.Status == 1).ToList(); objUser.RestaurantListAll = objContext.ContextRestaurant.Where(s => s.Status == 1).ToList(); if (objUser.SelectedPreferences == null) objUser.SelectedPreferences = new int[] { }; if (objUser.RestaurantSelected.Id > 0) { objMenuPrefList = objContext.ContextMenuPreferences.Include("Preferences").Include("Menu.Restaurant") .Where(s => s.Menu.Restaurant.Id == objUser.RestaurantSelected.Id && s.Menu.Status==1).ToList().GroupBy(s => s.Menu.Id).Select(k => k.FirstOrDefault()).ToList(); } else { objMenuPrefList = objContext.ContextMenuPreferences.Include("Preferences").Include("Menu.Restaurant").Where(s=>s.Menu.Status==1).ToList().GroupBy(p => p.Menu.Id).Select(k => k.FirstOrDefault()).ToList(); } if(objUser.IsPreSelected==1) { objUser.UserPreferencesList = objContext.ContextUserPreferences.Where(s => s.User.Id == objUser.Id).ToList(); objUser.SelectedPreferences = objUser.UserPreferencesList.Select(s => s.Preferences.Id).ToArray(); } foreach (MenuPreferences objPref in objMenuPrefList) { objResult = new SearchResult(); objResult.exist = 1; for (int i = 0; i < objUser.SelectedPreferences.Length; i++) { id = objUser.SelectedPreferences[i]; if (objContext.ContextMenuPreferences.Count(s => s.Preferences.Id == id && s.Menu.Id == objPref.Menu.Id) == 0) { objResult.exist = 0; break; } } if (objResult.exist == 1) { objResult.Restaurant = objPref.Menu.Restaurant; objResult.Menu = objPref.Menu; objUser.SearchResult.Add(objResult); } } return View(objUser); }
public ActionResult SearchByRestaurant() { User objUser = new User(); if (Session["UserId"] != null) { int id = Convert.ToInt32(Session["UserId"]); objUser = objContext.ContextUser.Find(id); } objUser.SearchResult = new List<SearchResult>(); objUser.PreferencesList = objContext.ContextPreferences.Where(s => s.Status == 1).ToList(); objUser.RestaurantListAll = objContext.ContextRestaurant.Where(s => s.Status == 1).ToList(); if (objUser.SelectedPreferences == null) objUser.SelectedPreferences = new int[] { }; return View(objUser); }