public ActionResult Preference(employeePreference u) { if (ModelState.IsValid) { using (IOTEmployeeEntities dc = new IOTEmployeeEntities()) { string userName = Session["UserName"].ToString(); var prefTemp = (from c in dc.employeePreferences where c.userName == userName select c.preferredTemperature); var check = (from c in dc.employeePreferences where c.userName == userName select c).SingleOrDefault(); if (check != null) { int prefTempe = prefTemp.FirstOrDefault().Value; Session["PreferredTemperature"] = prefTempe; dc.employeePreferences.Remove(dc.employeePreferences.SingleOrDefault(model => model.userName == userName)); dc.employeePreferences.Remove(dc.employeePreferences.SingleOrDefault(model => model.preferredTemperature == prefTempe)); } dc.employeePreferences.Add(new employeePreference { userName = Session["UserName"].ToString(), preferredTemperature = u.preferredTemperature }); dc.SaveChanges(); TempData["throwMessage"] = "Successfully Updated"; return RedirectToAction("Preference"); } } return View(); }
public ActionResult Preference() { if (Session["UserName"] != null) { if (ModelState.IsValid) { using (IOTEmployeeEntities dc = new IOTEmployeeEntities()) { string userName = Session["UserName"].ToString(); var check = (from c in dc.employeePreferences where c.userName == userName select c).SingleOrDefault(); if (check != null) { var prefTemp = (from c in dc.employeePreferences where c.userName == userName select c.preferredTemperature); int prefTempe = prefTemp.FirstOrDefault().Value; Session["PreferredTemperature"] = prefTempe; } } } return View(); } else { return RedirectToAction("LogIn"); } }
public ActionResult LogIn(empDetail u) { if(ModelState.IsValid) //Check This Out - Jenurius Mark { using (IOTEmployeeEntities dc = new IOTEmployeeEntities()) { var v = dc.empDetails.Where(m => m.userName.Equals(u.userName) && m.password.Equals(u.password)).FirstOrDefault(); if (v != null) { Session["UserName"] = v.userName.ToString(); return RedirectToAction("AfterLogin", new RouteValueDictionary( new {controller = "Temperature", action = "AfterLogin"})); } else { ModelState.AddModelError("", "Invalid Username or Password."); } } } return View(u); }
public ActionResult Registration(empDetail u) { try { if (ModelState.IsValid) { using (IOTEmployeeEntities dc = new IOTEmployeeEntities()) { dc.empDetails.Add(u); dc.SaveChanges(); ModelState.Clear(); u = null; } TempData["throwMessage_Register"] = "Registration Successfull"; } return View("Registration"); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { Exception raise = e; foreach (var validationErrors in e.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } return View("LogIn"); }