public ActionResult createExpanses(ExpansesModel expModel, Guid expanseReport_ID)
        {
            ExpanseRepositery expRepo = new ExpanseRepositery();
            Expanses          exp     = new Expanses();

            if (!ModelState.IsValid)
            {
                exp.Amount_HT  = Convert.ToInt32(0);
                exp.Amount_TVA = Convert.ToInt32(0);
            }
            else
            {
                exp.Amount_HT  = Convert.ToInt32(Request.Form["Amount_HT"]);
                exp.Amount_TVA = Convert.ToInt32(Request.Form["Amount_TVA"]);
            }
            var idCustomer    = Request.Form["customerSelect"];
            var idexpanseType = Request.Form["typeSelect"];
            var idprojet      = Request.Form["projectSelect"];

            exp.Expanse_ID       = Guid.NewGuid();
            exp.Amount_TTC       = exp.Amount_HT * exp.Amount_TVA / 100 + exp.Amount_HT;
            exp.Day              = Convert.ToInt16(Request.Form["monthSelect"]);
            exp.ExpanseReport_ID = expanseReport_ID;
            exp.Customer_ID      = new Guid(idCustomer);
            exp.ExpanseType_ID   = new Guid(idexpanseType);
            exp.Project_ID       = new Guid(idprojet);
            expRepo.AddExpanses(exp);
            return(RedirectToAction("AllExpanses", new { idExpanseReport = expanseReport_ID }));
        }
        public ActionResult Searche(String query, int?pageIndex, Guid id)
        {
            var countElementPage      = 10;
            ExpanseRepositery expRepo = new ExpanseRepositery();
            var expanses = expRepo.getSerachingExpanses(query, id);
            List <ExpansesModel> expanseModel = new List <ExpansesModel>();

            ViewData["idExpanseReport"] = id;
            foreach (var exp in expanses)
            {
                ExpansesModel       expanse        = new ExpansesModel();
                CustomersModel      customer       = new CustomersModel();
                ExpanseTypesModel   expType        = new ExpanseTypesModel();
                ExpanseReportsModel expanseRapport = new ExpanseReportsModel();
                ProjectsModel       projet         = new ProjectsModel();
                expanse.Expanse_ID     = exp.Expanse_ID;
                expanse.Amount_HT      = exp.Amount_HT;
                expanse.Amount_TTC     = exp.Amount_TTC;
                expanse.Amount_TVA     = exp.Amount_TVA;
                customer.Name          = expRepo.GetByIdCutomer(exp.Customer_ID).Name;
                projet.Name            = expRepo.GetByIdProjects(exp.Project_ID).Name;
                expType.Name           = expRepo.GetByIdExpanseTypes(exp.ExpanseType_ID).Name;
                expanseRapport.Year    = expRepo.GetByIdExpansesRepport(exp.ExpanseReport_ID).Year;
                expanse.Customers      = customer;
                expanse.Projects       = projet;
                expanse.ExpanseReports = expanseRapport;
                expanse.ExpanseTypes   = expType;
                expanseModel.Add(expanse);
            }
            IQueryable <ExpansesModel>    listCust = expanseModel.AsQueryable();
            PaginatedList <ExpansesModel> lst      = new PaginatedList <ExpansesModel>(listCust, pageIndex, countElementPage);

            return(View("AllExpanses", lst));
        }
        public ActionResult updateExpanse(Guid idExpanse)
        {
            ExpanseRepositery expRepo = new ExpanseRepositery();
            Expanses          exp     = expRepo.GetById(idExpanse);
            Guid   expRapId           = exp.ExpanseReport_ID;
            double ht  = Convert.ToInt32(Request.Form["Amount_HT"]);
            double ttc = Convert.ToInt32(Request.Form["Amount_TTC"]);
            double tva = Convert.ToInt32(Request.Form["Amount_TVA"]);

            expRepo.updateExpanses(exp, ttc, ht, tva);
            return(RedirectToAction("AllExpanses", new { idExpanseReport = expRapId }));
        }
        public ActionResult AllExpanses(int?pageIndex, Guid idExpanseReport)
        {
            ExpanseRepositery expRepo = new ExpanseRepositery();
            double            ttc     = 0;
            double            tva     = 0;
            double            ht      = 0;

            var countElementPage = 10;
            var expanses         = expRepo.GetAllByIdExpansesRepport(idExpanseReport);

            ViewData["idExpanseReport"] = idExpanseReport;
            List <ExpansesModel> expanseModel = new List <ExpansesModel>();

            foreach (var exp in expanses)
            {
                tva = tva + exp.Amount_TVA;
                ht  = ht + exp.Amount_HT;
                ttc = ttc + exp.Amount_TTC;
                ExpansesModel       expanse        = new ExpansesModel();
                CustomersModel      customer       = new CustomersModel();
                ExpanseTypesModel   expType        = new ExpanseTypesModel();
                ExpanseReportsModel expanseRapport = new ExpanseReportsModel();
                ProjectsModel       projet         = new ProjectsModel();
                expanseRapport.ExpanseReport_ID = idExpanseReport;
                expanse.ExpanseReport_ID        = exp.Expanse_ID;
                expanse.Expanse_ID     = exp.Expanse_ID;
                expanse.Amount_HT      = exp.Amount_HT;
                expanse.Amount_TTC     = exp.Amount_TTC;
                expanse.Amount_TVA     = exp.Amount_TVA;
                expanse.Day            = exp.Day;
                customer.Name          = expRepo.GetByIdCutomer(exp.Customer_ID).Name;
                projet.Name            = expRepo.GetByIdProjects(exp.Project_ID).Name;
                expType.Name           = expRepo.GetByIdExpanseTypes(exp.ExpanseType_ID).Name;
                expanseRapport.Year    = expRepo.GetByIdExpansesRepport(exp.ExpanseReport_ID).Year;
                expanse.Customers      = customer;
                expanse.Projects       = projet;
                expanse.ExpanseReports = expanseRapport;
                expanse.ExpanseTypes   = expType;
                expanseModel.Add(expanse);
            }
            ExpanseRepportRepositery expRapRep = new ExpanseRepportRepositery();
            ExpanseReports           expRap    = expRapRep.GetById(idExpanseReport);

            expRapRep.updateExpanseReports(expRap, ttc, ht, tva);
            ViewData["idExpanseReport"] = idExpanseReport;
            IQueryable <ExpansesModel>    listExpanse = expanseModel.AsQueryable();
            PaginatedList <ExpansesModel> lst         = new PaginatedList <ExpansesModel>(listExpanse, pageIndex, countElementPage);

            return(View("AllExpanses", lst));
        }
        public ActionResult edit(Guid idExpanse)
        {
            ExpanseRepositery expRep   = new ExpanseRepositery();
            ExpansesModel     expModel = new ExpansesModel();
            Expanses          exp      = expRep.GetById(idExpanse);

            expModel.Expanse_ID       = exp.Expanse_ID;
            expModel.Project_ID       = exp.Project_ID;
            expModel.Customer_ID      = exp.Customer_ID;
            expModel.ExpanseReport_ID = exp.ExpanseReport_ID;
            expModel.Amount_HT        = exp.Amount_HT;
            expModel.Amount_TTC       = exp.Amount_TTC;
            expModel.Amount_TVA       = exp.Amount_TVA;
            expModel.Day = exp.Day;
            return(View("EditExpanses", expModel));
        }
        public ActionResult Delete(Guid id)
        {
            ExpanseRepositery        expRepo   = new ExpanseRepositery();
            ExpanseRepportRepositery expRapRep = new ExpanseRepportRepositery();
            Expanses       exp       = expRepo.GetById(id);
            Guid           idExpRapo = exp.ExpanseReport_ID;
            ExpanseReports expReport = expRapRep.GetById(idExpRapo);
            double         ttc       = expReport.Total_TTC - exp.Amount_TTC;
            double         ht        = expReport.Total_HT - exp.Amount_HT;
            double         tva       = expReport.Total_TVA - exp.Amount_TVA;

            expRapRep.updateExpanseReports(expReport, ttc, ht, tva);
            expRepo.Delete(exp);
            expRepo.Save();
            return(RedirectToAction("AllExpanses", new { idExpanseReport = idExpRapo }));
        }
        public ActionResult Delete(Guid id)
        {
            ProjetRepositery         prjtRepo  = new ProjetRepositery();
            Projects                 project   = prjtRepo.GetById(id);
            ExpanseRepositery        expRep    = new ExpanseRepositery();
            ExpanseRepportRepositery expRepRep = new ExpanseRepportRepositery();
            List <Expanses>          expList   = expRep.GetByProject(id).ToList();

            foreach (var expanse in expList)
            {
                expRep.Delete(expanse);
            }
            expRep.Save();
            prjtRepo.Delete(project);
            prjtRepo.Save();
            return(RedirectToAction("AllProjets"));
        }
        public ActionResult Delete(Guid id)
        {
            ExpanseTypesRepositery expTypeRepo = new ExpanseTypesRepositery();
            ExpanseRepositery      expRep      = new ExpanseRepositery();
            List <Expanses>        expList     = expRep.GetExpansesByIdExpanseTypes(id).ToList();

            foreach (var expanse in expList)
            {
                expRep.Delete(expanse);
            }
            expRep.Save();
            ExpanseTypes expanseType = expTypeRepo.getById(id);

            expTypeRepo.delete(expanseType);
            expTypeRepo.Save();
            return(RedirectToAction("AllExpanseTypes"));
        }
        public ActionResult Delete(Guid id)
        {
            PolesRepository          poleRep   = new PolesRepository();
            ProjetRepositery         prjtRepo  = new ProjetRepositery();
            ExpanseRepositery        expRep    = new ExpanseRepositery();
            EmployesRepositery       empRepo   = new EmployesRepositery();
            ExpanseRepportRepositery expRepRep = new ExpanseRepportRepositery();
            List <Projects>          projets   = prjtRepo.GetByIdPole(id).ToList();

            foreach (var pro in projets)
            {
                List <Expanses> expList = expRep.GetByProject(pro.Project_ID).ToList();
                foreach (var expanse in expList)
                {
                    expRep.Delete(expanse);
                }
                expRep.Save();
                prjtRepo.Delete(pro);
            }
            prjtRepo.Save();
            foreach (var empl in empRepo.getByIdPole(id))
            {
                List <ExpanseReports> expanseReports = expRepRep.GetByEmployesId(empl.Employee_ID).ToList();
                foreach (var expRepo in expanseReports)
                {
                    expRepRep.Delete(expRepo);
                }
                expRepRep.Save();
                empRepo.Delete(empl);
            }
            empRepo.Save();
            Poles pole = poleRep.GetById(id);

            poleRep.Delete(pole);
            poleRep.Save();
            return(RedirectToAction("AllPoles"));
        }