// GET: Conge/Delete/5
        public ActionResult Delete(int id)
        {
            conge cm = new conge();

            cm = cs.Get(t => t.id == id);
            CongeModels c = new CongeModels();

            c.DateFin   = cm.DateFin;
            c.DateDebut = cm.DateDebut;
            return(View(c));
        }
        // GET: Conge/Edit/5
        public ActionResult Edit(int id)
        {
            conge cm = new conge();

            cm = cs.Get(t => t.id == id);
            CongeModels c = new CongeModels();

            c.DateDebut = cm.DateDebut;
            c.DateFin   = cm.DateFin;
            c.certefica = cm.certefica;
            c.typeConge = cm.typeConge;


            return(View(c));
        }
        public ActionResult DetailsAdmin(int id)
        {
            conge       cm = new conge();
            CongeModels c  = new CongeModels();

            cm = cs.Get(t => t.id == id);

            c.DateDebut     = cm.DateDebut;
            c.DateFin       = cm.DateFin;
            c.certefica     = cm.certefica;
            c.typeConge     = cm.typeConge;
            ViewBag.id      = cm.id;
            ViewBag.reponse = cm.reponse;
            ViewBag.nbr_jrs = cm.nbr_jr;
            return(View(c));
        }
        public ActionResult Create(CongeModels cm, HttpPostedFileBase file)
        {
            {
                if (!ModelState.IsValid || file == null || file.ContentLength == 0)
                {
                    RedirectToAction("Create");
                }
            }
            conge c = new conge();

            c.id        = cm.id;
            c.typeConge = cm.typeConge;
            if (c.typeConge == "Maladie")
            {
                c.certefica = file.FileName;
                var fileName = "";
                if (file.ContentLength > 0)
                {
                    fileName = Path.GetFileName(file.FileName);
                    var path = Path.
                               Combine(Server.MapPath("~/Content/Upload/"),
                                       fileName);
                    file.SaveAs(path);
                }
            }
            else if (c.typeConge == "Normale")
            {
                c.certefica = "N'a pas besoin de certificat";
            }
            c.DateDebut    = cm.DateDebut;
            c.DateFin      = cm.DateFin;
            c.reponse      = "false";
            c.typeConge    = cm.typeConge;
            c.demandeConge = "true";
            //c.certefica = cm.certefica;

            //calcule nbr jours conge
            // System.TimeSpan diff1 = c.DateFin.Subtract(DateTime.Now);
            //  int x = (int)diff1.TotalDays;
            //c.nbr_jr = x;

            cs.Add(c);
            cs.Commit();

            return(RedirectToAction("Index"));
        }
        // GET: Conge
        public ActionResult Index()
        {
            List <CongeModels> lc = new List <CongeModels>();

            foreach (var cm in cs.GetMany())
            {
                CongeModels c = new CongeModels();
                c.id        = cm.id;
                c.DateDebut = cm.DateDebut;
                c.DateFin   = cm.DateFin;
                c.typeConge = cm.typeConge;
                c.certefica = cm.certefica;

                lc.Add(c);
            }

            return(View(lc));
        }
        public ActionResult Edit(int id, CongeModels cm, HttpPostedFileBase file)
        {
            {
                if (!ModelState.IsValid || file == null || file.ContentLength == 0)
                {
                    RedirectToAction("Create");
                }
            }
            conge c = new conge();

            c    = cs.Get(t => t.id == id);
            c.id = cm.id;

            c.DateDebut = cm.DateDebut;
            c.DateFin   = cm.DateFin;
            c.typeConge = cm.typeConge;
            if (c.typeConge == "Maladie")
            {
                c.certefica = file.FileName;
                var fileName = "";
                if (file.ContentLength > 0)
                {
                    fileName = Path.GetFileName(file.FileName);
                    var path = Path.
                               Combine(Server.MapPath("~/Content/Upload/"),
                                       fileName);
                    file.SaveAs(path);
                }
            }
            else if (c.typeConge == "Normale")
            {
                c.certefica = "N'a pas besoin de certificat";
            }
            cs.Update(c);
            cs.Commit();

            return(RedirectToAction("Index"));
        }