Ejemplo n.º 1
0
 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");
 }
 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();
 }