public ActionResult Edit(ShiftPref shiftPref)
        {
            ShiftPref shift = db.ShiftPref.Find(shiftPref.ID);

            shiftPref.EmployID = shift.EmployID;
            shiftPref.Name     = shift.Name;

            var result = db.ShiftPref.SingleOrDefault(b => b.ID == shiftPref.ID);

            if (result != null && ModelState.IsValid)
            {
                db.Entry(result).CurrentValues.SetValues(shiftPref);
                db.SaveChanges();

                if ((bool)System.Web.HttpContext.Current.Session["admin"] == true)
                {
                    return(RedirectToAction("ListOfShifts", "FinalShifts"));
                }
                else
                {
                    return(RedirectToAction("Index", "ShiftPrefs"));
                }
            }
            return(View(shiftPref));
        }
        public ActionResult DeleteConfirmed(long id)
        {
            ShiftPref shiftPref = db.ShiftPref.Find(id);

            db.Preferences.Remove(shiftPref);
            db.SaveChanges();
            return(RedirectToAction("Index", new { ID = shiftPref.EmployID }));
        }
        public ActionResult DeleteConfirmed(long id)
        {
            Employees employees = db.Employees.Find(id);
            ShiftPref shiftPref = db.ShiftPref.Where(x => x.EmployID == id).FirstOrDefault(); //employee(many) -> shiftpref(one) relationship

            db.Preferences.Remove(shiftPref);
            db.SaveChanges();
            db.Employees.Remove(employees);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShiftPref shiftPref = db.ShiftPref.Find(id);

            if (shiftPref == null)
            {
                return(HttpNotFound());
            }
            return(View(shiftPref));
        }
        public ActionResult Create(ShiftPref shiftPref)
        {
            var employ = db.Employees.Find(shiftPref.EmployID);

            shiftPref.Name = employ.FirstName;

            if (ModelState.IsValid)
            {
                db.Preferences.Add(shiftPref);
                db.SaveChanges();
                return(RedirectToAction("Index", new { Id = shiftPref.EmployID }));
            }

            return(View(shiftPref));
        }