public IHttpActionResult Put(int idcar, CarPoolModel student)
        {
            CarPool existingStudent = MyService.GetById(idcar);

            if (existingStudent != null)
            {
                existingStudent.Title        = student.Title;
                existingStudent.From         = student.From;
                existingStudent.Time         = student.Time;
                existingStudent.To           = student.To;
                existingStudent.Date         = student.Date;
                existingStudent.NbPlaceDispo = student.NbPlaceDispo;
                existingStudent.Weekly       = student.Weekly;
                existingStudent.Daily        = student.Daily;
                existingStudent.EveryWeekDay = student.EveryWeekDay;
                existingStudent.Message      = student.Message;
                existingStudent.idKid        = 3;
                existingStudent.UntilDate    = student.UntilDate;
                MyService.Update(existingStudent);
                MyService.Commit();
            }
            else
            {
                return(NotFound());
            }


            return(Ok());
        }
        public IHttpActionResult PostNewFeed(CarPoolModel collection)
        {
            using (var ctx = new PidevContext())
            {
                ctx.CarPools.Add(new CarPool()
                {
                    idParent     = collection.idParent,
                    Id           = collection.Id,
                    Title        = collection.Title,
                    From         = collection.From,
                    To           = collection.To,
                    Time         = collection.Time,
                    Date         = collection.Date,
                    Message      = collection.Message,
                    NbPlaceDispo = collection.NbPlaceDispo,
                    idKid        = collection.idKid,
                    Weekly       = collection.Weekly,
                    Daily        = collection.Daily,
                    EveryWeekDay = collection.EveryWeekDay,
                    UntilDate    = collection.UntilDate,
                });;

                ctx.SaveChanges();
            }

            return(Ok());
        }
        public ActionResult Edit(int?id, CarPoolModel collection, bool hidden_field1 = false, bool hidden_field2 = false, bool hidden_field3 = false)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var CarPoolToUpdate = db.CarPools.Find(id);

            if (hidden_field1)
            {
                CarPoolToUpdate.Daily = true;
            }

            else
            {
                CarPoolToUpdate.Daily = false;
            }

            if (hidden_field2)
            {
                CarPoolToUpdate.EveryWeekDay = true;
            }

            else
            {
                CarPoolToUpdate.EveryWeekDay = false;
            }

            if (hidden_field3)
            {
                CarPoolToUpdate.Weekly = true;
            }

            else
            {
                CarPoolToUpdate.Weekly = false;
            }
            if (TryUpdateModel(CarPoolToUpdate, "",
                               new string[] { "ID", "Title", "From", "To", "Time", "Date", "Message", "idKid" }))
            {
                try
                {
                    db.Entry(CarPoolToUpdate).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("MyIndex"));
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            return(View(CarPoolToUpdate));
        }
        // GET: CarPool
        public ActionResult MyIndex(string searchString, string map)
        {
            var    userId = (int)Session["idu"];
            String nom    = ps.GetById(userId).nom;
            String prenom = ps.GetById(userId).prenom;
            String mail   = ps.GetById(userId).email;

            ViewBag.home   = mail;
            ViewBag.nom    = nom;
            ViewBag.prenom = prenom;
            List <Kid> Kids = ServicePar.GetMany().ToList();

            ViewBag.MyKid = new SelectList(Kids, "IdKid", "FirstName");

            List <User> Parents = Service.GetMany().ToList();

            ViewBag.MyParent = new SelectList(Parents, "IdUser", "prenom");

            List <User> Parentn = Service.GetMany().ToList();

            ViewBag.MyParentn = new SelectList(Parentn, "IdUser", "nom");



            var carps = new List <CarPoolModel>();

            foreach (CarPool c in sc.SearchParentByTo(searchString))
            {
                if (c.idParent == userId)
                {
                    ;
                    CarPoolModel cs = new CarPoolModel()
                    {
                        Id           = c.Id,
                        Title        = c.Title,
                        From         = c.From,
                        To           = c.To,
                        Time         = c.Time,
                        Date         = c.Date,
                        Message      = c.Message,
                        idKid        = c.idKid,
                        Daily        = c.Daily,
                        Weekly       = c.Weekly,
                        EveryWeekDay = c.EveryWeekDay,
                        UntilDate    = c.UntilDate,
                        NbPlaceDispo = c.NbPlaceDispo,
                        idParent     = c.idParent,
                    };

                    carps.Add(cs);
                }
            }
            return(View(carps));
        }
        // GET: CarPool
        public ActionResult Index(string searchString, int[] array, int?i)
        {
            des = new List <CarPool>();
            List <Kid> Kids = ServicePar.GetMany().ToList();

            ViewBag.MyKid = new SelectList(Kids, "IdKid", "FirstName");

            List <User> Parents = Service.GetMany().ToList();

            ViewBag.MyParent = new SelectList(Parents, "IdUser", "prenom");

            List <User> Parentn = Service.GetMany().ToList();

            ViewBag.MyParentn = new SelectList(Parentn, "IdUser", "nom");

            List <GeoLocation> geo = db.GeoLocations.ToList <GeoLocation>();

            ViewBag.Geo = geo;

            ViewBag.UserGeo = (from s in db.GeoLocations      // outer sequence
                               join st in db.Users            //inner sequence
                               on s.ParentFK equals st.idUser // key selector

                               select new
            {                    // result selector
                idUser = s.ParentFK,
                NomUser = st.nom,
                PrenomUser = st.prenom,
                AddressUser = s.Address,
                Lat = s.lat,
                Lng = s.lng
            }).ToList();

            var    userId = (int)Session["idu"];
            int    id     = ps.GetById(userId).idUser;
            String nom    = ps.GetById(userId).nom;
            String prenom = ps.GetById(userId).prenom;
            String mail   = ps.GetById(userId).email;

            ViewBag.home   = mail;
            ViewBag.nom    = nom;
            ViewBag.prenom = prenom;
            ViewBag.id     = id;



            //  var Carpool = db.CarPools;
            //  var daily = Carpool.Where(z => z.Daily == true).ToString();
            //  var everyweekday = Carpool.Where(z => z.EveryWeekDay == true).ToString();
            //  var weekly = Carpool.Where(z => z.Weekly == true).ToString();
            //  ViewBag.weekly = new SelectList(weekly);
            //  ViewBag.everyweekday = new SelectList(everyweekday);
            //  ViewBag.weekly = new SelectList(daily);

            var carps = new List <CarPoolModel>();

            foreach (CarPool c in sc.SearchParentByTo(searchString))
            {
                CarPoolModel cs = new CarPoolModel()
                {
                    Id           = c.Id,
                    Title        = c.Title,
                    From         = c.From,
                    To           = c.To,
                    Time         = c.Time,
                    Date         = c.Date,
                    Message      = c.Message,
                    idKid        = c.idKid,
                    Daily        = c.Daily,
                    Weekly       = c.Weekly,
                    EveryWeekDay = c.EveryWeekDay,
                    UntilDate    = c.UntilDate,
                    NbPlaceDispo = c.NbPlaceDispo,
                    idParent     = c.idParent,
                };

                carps.Add(cs);
            }
            if (searchString == null)
            {
                //just load the main index
                return(View(carps.ToPagedList(i ?? 1, 7)));
            }
            else
            {
                return(View(carps.Where(car => car.To == (searchString)).ToPagedList(i ?? 1, 7)));
            }
        }
        // GET: CarPool/Edit/5
        public ActionResult Edit(int?id, bool hidden_field1 = false, bool hidden_field2 = false, bool hidden_field3 = false)
        {
            var    userId = (int)Session["idu"];
            String nom    = ps.GetById(userId).nom;
            String prenom = ps.GetById(userId).prenom;
            String mail   = ps.GetById(userId).email;

            ViewBag.home   = mail;
            ViewBag.nom    = nom;
            ViewBag.prenom = prenom;

            var CarPoolToUpdate = db.CarPools.Find(id);

            if (hidden_field1)
            {
                CarPoolToUpdate.Daily = true;
            }

            else
            {
                CarPoolToUpdate.Daily = false;
            }

            if (hidden_field2)
            {
                CarPoolToUpdate.EveryWeekDay = true;
            }

            else
            {
                CarPoolToUpdate.EveryWeekDay = false;
            }

            if (hidden_field3)
            {
                CarPoolToUpdate.Weekly = true;
            }

            else
            {
                CarPoolToUpdate.Weekly = false;
            }

            CarPool      collection = sc.GetById((long)id);
            CarPoolModel c          = new CarPoolModel();

            c.Id           = collection.Id;
            c.Title        = collection.Title;
            c.From         = collection.From;
            c.To           = collection.To;
            c.Time         = collection.Time;
            c.Date         = collection.Date;
            c.Message      = collection.Message;
            c.NbPlaceDispo = collection.NbPlaceDispo;
            c.idKid        = collection.idKid;

            List <Kid> query = ServicePar.GetMany().ToList();
            //var userId = (int)Session["idu"];
            // var kidss = db.Kids;
            //  var query = kidss.Where(z => z.idParent == userId).Select(z=>z.FirstName).ToList();
            //ViewBag.MyKid = new SelectList(query, "IdKid", "FirstName");

            var kidss = db.Kids;

            ViewBag.Kidsss = kidss.Where(z => z.idParent == userId).Select(m => new SelectListItem {
                Value = m.IdKid.ToString(), Text = m.FirstName
            });
            return(View(c));
        }
        public ActionResult create(CarPoolModel collection, bool hidden_field1 = false, bool hidden_field2 = false, bool hidden_field3 = false)
        {
            ICarPoolService sc   = new CarPoolService();
            CarPool         c    = new CarPool();
            DateTime        date = DateTime.Parse(c.Date.ToString());

            DateTime today = DateTime.Today;

            if (ModelState.IsValid)
            {
                if (hidden_field1)
                {
                    c.Daily = true;
                }

                else
                {
                    c.Daily = false;
                }

                if (hidden_field2)
                {
                    c.EveryWeekDay = true;
                }

                else
                {
                    c.EveryWeekDay = false;
                }

                if (hidden_field3)
                {
                    c.Weekly = true;
                }

                else
                {
                    c.Weekly = false;
                }
                c.UntilDate = collection.UntilDate;

                c.Others = c.Daily || c.EveryWeekDay || c.Weekly ? false : true;

                c.idParent = (int)Session["idu"];
                c.Id       = collection.Id;
                c.Title    = collection.Title;
                c.From     = collection.From;
                c.To       = collection.To;



                c.Time = collection.Time;

                c.Date = collection.Date;


                c.Message      = collection.Message;
                c.NbPlaceDispo = collection.NbPlaceDispo;
                c.idKid        = collection.idKid;


                sc.Add(c);
                sc.Commit();


                return(RedirectToAction("MyIndex"));
            }
            else
            {
                return(View());
            }
        }
        public ActionResult IndexNearme(string searchString, int[] array, int?i)
        {
            var    userId = (int)Session["idu"];
            String nom    = ps.GetById(userId).nom;
            String prenom = ps.GetById(userId).prenom;
            String mail   = ps.GetById(userId).email;

            ViewBag.home   = mail;
            ViewBag.nom    = nom;
            ViewBag.prenom = prenom;

            List <Kid> Kids = ServicePar.GetMany().ToList();

            ViewBag.MyKid = new SelectList(Kids, "IdKid", "FirstName");

            List <User> Parents = Service.GetMany().ToList();

            ViewBag.MyParent = new SelectList(Parents, "IdUser", "prenom");

            List <User> Parentn = Service.GetMany().ToList();

            ViewBag.MyParentn = new SelectList(Parentn, "IdUser", "nom");

            List <GeoLocation> geo = db.GeoLocations.ToList <GeoLocation>();

            ViewBag.Geo = geo;



            //  var Carpool = db.CarPools;
            //  var daily = Carpool.Where(z => z.Daily == true).ToString();
            //  var everyweekday = Carpool.Where(z => z.EveryWeekDay == true).ToString();
            //  var weekly = Carpool.Where(z => z.Weekly == true).ToString();
            //  ViewBag.weekly = new SelectList(weekly);
            //  ViewBag.everyweekday = new SelectList(everyweekday);
            //  ViewBag.weekly = new SelectList(daily);

            List <CarPoolModel> carps = new List <CarPoolModel>();

            foreach (CarPool c in des)
            {
                CarPoolModel cs = new CarPoolModel()
                {
                    Id           = c.Id,
                    Title        = c.Title,
                    From         = c.From,
                    To           = c.To,
                    Time         = c.Time,
                    Date         = c.Date,
                    Message      = c.Message,
                    idKid        = c.idKid,
                    Daily        = c.Daily,
                    Weekly       = c.Weekly,
                    EveryWeekDay = c.EveryWeekDay,
                    UntilDate    = c.UntilDate,
                    NbPlaceDispo = c.NbPlaceDispo,
                    idParent     = c.idParent,
                };

                carps.Add(cs);
            }
            return(View(carps));
        }