public ActionResult AllCustomer(int?pageIndex)
        {
            CustomerRepositery costRep = new CustomerRepositery();

            var countElementPage = 10;
            var costumers        = costRep.allCustomers();

            if (costumers.Count() == 0)
            {
                ViewData["erreurMessage"] = "aucun customer !";
                ViewData["element"]       = "Customer";
                ViewData["create"]        = "true";
                return(View("ErrorEmptyList"));
            }
            List <CustomersModel> customersModel = new List <CustomersModel>();

            foreach (var cust in costumers)
            {
                CustomersModel custModel = new CustomersModel();
                custModel.Customer_ID = cust.Customer_ID;
                custModel.Code        = cust.Code;
                custModel.Name        = cust.Name;
                customersModel.Add(custModel);
            }
            IQueryable <CustomersModel>    listCust = customersModel.AsQueryable();
            PaginatedList <CustomersModel> lst      = new PaginatedList <CustomersModel>(listCust, pageIndex, countElementPage);

            return(View("AllCustomers", lst));
        }
        public ActionResult Edit(Guid id)
        {
            CustomerRepositery custRep   = new CustomerRepositery();
            CustomersModel     custModel = new CustomersModel();
            Customers          customer  = custRep.GetById(id);

            custModel.Code        = customer.Code;
            custModel.Customer_ID = customer.Customer_ID;
            custModel.Name        = customer.Name;
            return(View("EditCustomer", custModel));
        }
        public ActionResult createCustomer(CustomersModel customerModel)
        {
            if (!ModelState.IsValidField("Name") || !ModelState.IsValidField("Code"))
            {
                return(View("CostumerFormulaire", customerModel));
            }
            Customers          customer = new Customers();
            CustomerRepositery costRep  = new CustomerRepositery();

            customer.Customer_ID = Guid.NewGuid();
            customer.Name        = Convert.ToString(Request.Form["Name"]);
            customer.Code        = Convert.ToString(Request.Form["Code"]);
            costRep.AddCostumers(customer);
            return(RedirectToAction("AllCustomer"));
        }
        public ActionResult Delete(Guid id)
        {
            ProjetController   prjtControleur = new ProjetController();
            CustomerRepositery cutoRepo       = new CustomerRepositery();
            Customers          cutomer        = cutoRepo.GetById(id);
            ProjetRepositery   prjtRepo       = new ProjetRepositery();
            List <Projects>    projets        = prjtRepo.GetByCustomerId(id).ToList();

            foreach (var pro in projets)
            {
                prjtControleur.Delete(pro.Project_ID);
            }
            prjtRepo.Save();
            cutoRepo.Delete(cutomer);
            cutoRepo.Save();
            return(RedirectToAction("AllCustomer"));
        }
        public ActionResult updateCustomers(Guid id)
        {
            CustomerRepositery custRep  = new CustomerRepositery();
            Customers          customer = custRep.GetById(id);

            if (!ModelState.IsValidField("Name") || !ModelState.IsValidField("Code"))
            {
                CustomersModel custModel = new CustomersModel();
                custModel.Code        = customer.Code;
                custModel.Customer_ID = customer.Customer_ID;
                custModel.Name        = customer.Name;
                return(View("EditCustomer", custModel));
            }
            String name = Convert.ToString(Request.Form["Name"]);
            String code = Convert.ToString(Request.Form["Code"]);

            custRep.updateCustomers(customer, name, code);
            return(RedirectToAction("AllCustomer"));
        }
        public ActionResult Searche(String query, int?pageIndex)
        {
            var countElementPage       = 10;
            CustomerRepositery costRep = new CustomerRepositery();
            var customers = costRep.getSerachingCustomers(query);
            List <CustomersModel> customersModel = new List <CustomersModel>();

            foreach (var cust in customers)
            {
                CustomersModel custModel = new CustomersModel();
                custModel.Customer_ID = cust.Customer_ID;
                custModel.Code        = cust.Code;
                custModel.Name        = cust.Name;
                customersModel.Add(custModel);
            }
            IQueryable <CustomersModel>    listCust = customersModel.AsQueryable();
            PaginatedList <CustomersModel> lst      = new PaginatedList <CustomersModel>(listCust, pageIndex, countElementPage);

            return(View("AllCustomers", lst));
        }
        public ActionResult Popup(Guid idExpanseReport)
        {
            CustomerRepositery       cstRepo               = new CustomerRepositery();
            ProjetRepositery         prjtRepo              = new ProjetRepositery();
            ExpanseTypesRepositery   expTypRepo            = new ExpanseTypesRepositery();
            List <CustomersModel>    customersModel        = new List <CustomersModel>();
            List <ProjectsModel>     projectsListModel     = new List <ProjectsModel>();
            List <ExpanseTypesModel> expansesTypeListModel = new List <ExpanseTypesModel>();

            ViewData["empty"] = "false";

            IQueryable <Customers> costumers = cstRepo.getlistCustomersHasProject();

            foreach (var cust in costumers)
            {
                CustomersModel custModel = new CustomersModel();
                custModel.Customer_ID = cust.Customer_ID;
                custModel.Code        = cust.Code;
                custModel.Name        = cust.Name;
                customersModel.Add(custModel);
            }

            IQueryable <Projects> projectsList = prjtRepo.allProjects();

            foreach (var prjt in projectsList)
            {
                ProjectsModel  prjtModel = new ProjectsModel();
                CustomersModel Customer  = new CustomersModel();
                prjtModel.Project_ID  = prjt.Project_ID;
                prjtModel.Pole_ID     = prjt.Pole_ID;
                prjtModel.Description = prjt.Description;
                prjtModel.Budget      = prjt.Budget;
                prjtModel.Name        = prjt.Name;
                Customer.Name         = prjtRepo.GetByIdCutomer(prjt.Customer_ID).Name;
                prjtModel.Customers   = Customer;
                projectsListModel.Add(prjtModel);
            }

            IQueryable <ExpanseTypes> expanseTypes = expTypRepo.allExpanseTypes();

            if (User.IsInRole("manager"))
            {
                expanseTypes = expTypRepo.allExpanseTypesManager();
            }

            foreach (var expTpe in expanseTypes)
            {
                ExpanseTypesModel expenseTypeModel = new ExpanseTypesModel();
                expenseTypeModel.ExpenseType_ID = expTpe.ExpenseType_ID;
                expenseTypeModel.Name           = expTpe.Name;
                expenseTypeModel.Ceiling        = expTpe.Ceiling;
                expenseTypeModel.Fixed          = expTpe.Fixed;
                expenseTypeModel.OnlyManagers   = expTpe.OnlyManagers;
                expenseTypeModel.Tva_ID         = expTpe.Tva_ID;
                expansesTypeListModel.Add(expenseTypeModel);
            }

            if (customersModel.Count() == 0 || projectsListModel.Count() == 0 || expansesTypeListModel.Count() == 0)
            {
                ViewData["erreur"] = "Customers , Projets et des ExpanseType";
                ViewData["empty"]  = "true";
            }
            var expanseViewModel = new ExpansesModel
            {
                CustomersList    = customersModel,
                ProjectsList     = projectsListModel,
                ExpanseTypesList = expansesTypeListModel
            };

            expanseViewModel.ExpanseReport_ID = idExpanseReport;

            return(PartialView("_AddType", expanseViewModel));
        }