public ActionResult Edit(int id, Lookout lookout, int s, List <PreferredCompany> pc, string locids)
        {
            string[] nameslist = locids.Split(',');
            lookout.LastActive      = System.DateTime.Now;
            db.Entry(lookout).State = EntityState.Modified;
            db.SaveChanges();
            WorkShift ws = db.WorkShifts.FirstOrDefault(a => a.Lookout_Id == id);
            Shift     sf = new Shift();

            sf                 = db.Shifts.Find(s);
            ws.Shift_Id        = sf.id;
            db.Entry(ws).State = System.Data.Entity.EntityState.Modified;  //EntityState.Modified;
            db.SaveChanges();
            foreach (var list in pc)
            {
                PreferredCompany pcs = db.PreferredCompanies.FirstOrDefault(a => a.Lookout_id == list.Lookout_id);
                db.Entry(pcs).CurrentValues.SetValues(pc);
                db.SaveChanges();
            }

            PreferredLocation        pr  = new PreferredLocation();
            List <PreferredLocation> prl = db.PreferredLocations.Where(ax => ax.Lookout_id == lookout.Id).ToList();

            foreach (var a in nameslist)
            {
                int      c   = Convert.ToInt16(a);
                Location loc = db.Locations.FirstOrDefault(ax => ax.City_id == c);
                //List<PreferredLocation> prl = db.PreferredLocations.Where(ax => ax.Lookout_id==lookout.Id).ToList();
                foreach (var lis in prl)
                {
                    db.PreferredLocations.Remove(lis);
                    db.SaveChanges();
                }
                var l = Convert.ToInt16(loc.id);
                pr.Location_id = l;
                pr.Lookout_id  = lookout.Id;
                db.PreferredLocations.Add(pr);
                db.SaveChanges();

                //    var l = Convert.ToInt16(loc.id);
                //    if (prl.Lookout_id == lookout.Id)
                //    {
                //        prl.Location_id=l;
                //        db.Entry(prl).CurrentValues.SetValues(nameslist);
                //        db.SaveChanges();
                //    }
            }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
        public ActionResult Create(Lookout lookout, int s, List <PreferredCompany> pc, string lkid)
        {
            string[] nameslist = lkid.Split(',');

            lookout.LastActive = System.DateTime.Now;

            db.Lookouts.Add(lookout);
            db.SaveChanges();
            foreach (var list in pc)
            {
                list.Lookout_id = lookout.Id;
                db.PreferredCompanies.Add(list);
                db.SaveChanges();
            }
            PreferredLocation prl = new PreferredLocation();

            foreach (var a in nameslist)
            {
                int      c   = Convert.ToInt16(a);
                Location loc = db.Locations.FirstOrDefault(ax => ax.City_id == c);
                var      l   = Convert.ToInt16(loc.id);
                prl.Location_id = l;
                prl.Lookout_id  = lookout.Id;
                db.PreferredLocations.Add(prl);
                db.SaveChanges();
            }

            WorkShift ws    = new WorkShift();
            Shift     shift = db.Shifts.Find(s);

            ws.Shift_Id   = shift.id;
            ws.Lookout_Id = lookout.Id;
            db.WorkShifts.Add(ws);
            db.SaveChanges();
            return(Json("", JsonRequestBehavior.AllowGet));
        }