public ActionResult ImportClientAgregateur(ImportClientAgregateur model)
        {
            try
            {
                int clientimporte = 0;
                int clientAimporte = 0;
                model.IsEndImport = true;
                Guid idCgpAgreg = SessionManager.GetUserSession().idAgregCGP.Value;
                if (Request.Form["chkClient"] != null)
                {
                    string[] clientIdList = Request.Form["chkClient"].ToString().Split(',');
                    clientAimporte = clientIdList.Count();
                    string ImportMode = Request.Form["ImportMode"].ToString();
                    List<ImportErrorModel> lsterror = new List<ImportErrorModel>();
                    using (UpsilabEntities context = new UpsilabEntities())
                    {
                        //cas d'initialisation
                        if (ImportMode == "0")
                        {
                            List<CustomerProspect> listecustomer = context.CustomerProspect.Where(c => c.User1.idAgregCGP == idCgpAgreg).ToList();
                            if (listecustomer.Count > 0)
                            {
                                foreach (CustomerProspect customer in listecustomer)
                                {
                                    var user = customer.User;
                                    user.IsDeleted = true;
                                    user.IsActive = false;
                                    user.DateDeleted = DateTime.Now;
                                    user.DateExpired = DateTime.Now;
                                    customer.isDeleted = true;
                                }
                            }
                        }
                        //fin

                        foreach (string sId in clientIdList)
                        {
                            Guid clientId = new Guid(sId);
                            //get client agreg
                            ag_upsideo_client currentClientAgreg = context.ag_upsideo_client.Where(c => c.idclient == clientId && c.deleted != "o").FirstOrDefault();
                            //get client recueil/lab si existe
                            if (currentClientAgreg != null)
                            {
                                string nomclient = string.IsNullOrEmpty(currentClientAgreg.nomclient) ? "" : currentClientAgreg.nomclient.ToLower();
                                string prenomclient = string.IsNullOrEmpty(currentClientAgreg.prenomclient) ? "" : currentClientAgreg.prenomclient.ToLower();
                                CustomerProspect currentcustomer = context.CustomerProspect.Where(c => c.User1.idAgregCGP == idCgpAgreg && c.User.UserName.ToLower() == nomclient && c.User.UserFirstName.ToLower() == prenomclient && (!c.isDeleted.HasValue || (c.isDeleted.HasValue && !c.isDeleted.Value))).FirstOrDefault();
                                switch (ImportMode)
                                {
                                    case "0":
                                        try
                                        {
                                            /*if (currentcustomer != null )
                                            {
                                                //supprimer
                                                currentcustomer.isDeleted = true;
                                                currentcustomer.User.IsDeleted = true;                                            
                                            }*/
                                            User usernow = new User()
                                            {
                                                idUser = Guid.NewGuid(),
                                                idUserProfile = 8,
                                                UserPassword = "",
                                                UserName = currentClientAgreg.nomclient,
                                                UserFirstName = currentClientAgreg.prenomclient,
                                                IsActive = true,
                                                DateCreated = DateTime.Now,
                                                IsDeleted = false,
                                                CGVOk = true,
                                                HasReadMessage = false,
                                                ReceiveLicenseRemind = false,
                                            };

                                            context.User.AddObject(usernow);

                                            CustomerProspect customernow = new CustomerProspect()
                                            {
                                                idCustomer = Guid.NewGuid(),
                                                idFirmInstitution = model.idFirmInstitution.Value,
                                                DateCreated = DateTime.Now,
                                                IdUser = usernow.idUser,
                                                IsCustomer = model.IsCustomer,
                                                idUserCreated = SessionManager.GetUserSession().idUser,
                                                IsAlertRecipientClient = false,
                                                Adress = currentClientAgreg.adr,
                                                ZipCode = currentClientAgreg.cp,
                                                City = currentClientAgreg.ville,
                                                DateOfBirth = currentClientAgreg.ddn,
                                                FiscalAddrress = currentClientAgreg.adr2,
                                                Title = currentClientAgreg.titre,
                                                idAgregClient = currentClientAgreg.idclient,
                                                IsCorporation = false,
                                                isDeleted = false,
                                            };

                                            context.CustomerProspect.AddObject(customernow);

                                            clientimporte = clientimporte + 1;
                                        }
                                        catch (Exception ex)
                                        {
                                            ImportErrorModel err = new ImportErrorModel()
                                            {
                                                Name = currentClientAgreg.nomclient,
                                                FirstName = currentClientAgreg.prenomclient,
                                                Error = ex.Message
                                            };
                                            lsterror.Add(err);
                                        }
                                        break;
                                    case "1":
                                        try
                                        {
                                            if (currentcustomer != null)
                                            {
                                                currentcustomer.idAgregClient = currentClientAgreg.idclient;
                                                /*currentcustomer.Adress = currentClientAgreg.adr;
                                                currentcustomer.ZipCode = currentClientAgreg.cp;
                                                currentcustomer.City = currentClientAgreg.ville;                                           
                                                currentcustomer.FiscalAddrress = currentClientAgreg.adr2;*/

                                            }
                                            else
                                            {
                                                User usernow1 = new User()
                                                {
                                                    idUser = Guid.NewGuid(),
                                                    idUserProfile = 8,
                                                    UserPassword = "",
                                                    UserName = currentClientAgreg.nomclient,
                                                    UserFirstName = currentClientAgreg.prenomclient,
                                                    IsActive = true,
                                                    DateCreated = DateTime.Now,
                                                    IsDeleted = false,
                                                    CGVOk = true,
                                                    HasReadMessage = false,
                                                    ReceiveLicenseRemind = false
                                                };

                                                context.User.AddObject(usernow1);

                                                CustomerProspect customernow1 = new CustomerProspect()
                                                {
                                                    idCustomer = Guid.NewGuid(),
                                                    idFirmInstitution = model.idFirmInstitution.Value,
                                                    DateCreated = DateTime.Now,
                                                    IdUser = usernow1.idUser,
                                                    IsCustomer = model.IsCustomer,
                                                    idUserCreated = SessionManager.GetUserSession().idUser,
                                                    IsAlertRecipientClient = false,
                                                    Adress = currentClientAgreg.adr,
                                                    ZipCode = currentClientAgreg.cp,
                                                    City = currentClientAgreg.ville,
                                                    DateOfBirth = currentClientAgreg.ddn,
                                                    FiscalAddrress = currentClientAgreg.adr2,
                                                    Title = currentClientAgreg.titre,
                                                    idAgregClient = currentClientAgreg.idclient,
                                                    isDeleted = false

                                                };
                                                context.CustomerProspect.AddObject(customernow1);
                                            }
                                            clientimporte = clientimporte + 1;
                                        }
                                        catch (Exception ex)
                                        {
                                            ImportErrorModel err = new ImportErrorModel()
                                            {
                                                Name = currentClientAgreg.nomclient,
                                                FirstName = currentClientAgreg.prenomclient,
                                                Error = ex.Message
                                            };
                                            lsterror.Add(err);
                                        }
                                        break;
                                    case "2":
                                        try
                                        {
                                            if (currentcustomer == null)
                                            {
                                                User usernow2 = new User()
                                                {
                                                    idUser = Guid.NewGuid(),
                                                    idUserProfile = 8,
                                                    UserPassword = "",
                                                    UserName = currentClientAgreg.nomclient,
                                                    UserFirstName = currentClientAgreg.prenomclient,
                                                    IsActive = true,
                                                    DateCreated = DateTime.Now,
                                                    IsDeleted = false,
                                                    CGVOk = true,
                                                    HasReadMessage = false,
                                                    ReceiveLicenseRemind = false
                                                };

                                                context.User.AddObject(usernow2);

                                                CustomerProspect customernow2 = new CustomerProspect()
                                                {
                                                    idCustomer = Guid.NewGuid(),
                                                    idFirmInstitution = model.idFirmInstitution.Value,
                                                    DateCreated = DateTime.Now,
                                                    IdUser = usernow2.idUser,
                                                    IsCustomer = model.IsCustomer,
                                                    idUserCreated = SessionManager.GetUserSession().idUser,
                                                    IsAlertRecipientClient = false,
                                                    Adress = currentClientAgreg.adr,
                                                    ZipCode = currentClientAgreg.cp,
                                                    City = currentClientAgreg.ville,
                                                    DateOfBirth = currentClientAgreg.ddn,
                                                    FiscalAddrress = currentClientAgreg.adr2,
                                                    Title = currentClientAgreg.titre,
                                                    idAgregClient = currentClientAgreg.idclient,
                                                    isDeleted = false

                                                };
                                                context.CustomerProspect.AddObject(customernow2);

                                                clientimporte = clientimporte + 1;
                                            }
                                            else
                                            {
                                                ImportErrorModel err = new ImportErrorModel()
                                                {
                                                    Name = currentClientAgreg.nomclient,
                                                    FirstName = currentClientAgreg.prenomclient,
                                                    Error = "Le client existe déjà"
                                                };
                                                lsterror.Add(err);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            ImportErrorModel err = new ImportErrorModel()
                                            {
                                                Name = currentClientAgreg.nomclient,
                                                FirstName = currentClientAgreg.prenomclient,
                                                Error = ex.Message
                                            };
                                            lsterror.Add(err);
                                        }
                                        break;
                                    default:
                                        break;
                                }

                            }
                        }
                        context.SaveChanges();
                        model.Message = string.Format("{0} client(s) importé(s) sur {1}", clientimporte.ToString(), clientAimporte.ToString());
                        model.ListeErreur = lsterror;
                    }

                }
                else
                {
                    model.Message = "Pas de client importé.";
                }

                return View("Agregateur", model);

            }
            catch (Exception ex)
            {
                Log.AppendException(ex);
                model.Message = ex.Message;
            }
            return View("Agregateur", model);
        }
 public ActionResult ClientListeAgregateur(ImportClientAgregateur model)
 {
     try
     {                
         List<ag_upsideo_client> ListeClient = new List<ag_upsideo_client>();
         Guid idCgpAgreg = SessionManager.GetUserSession().idAgregCGP.Value;
         if (Request.Form["idFirmInstitution"] != null)
         {
             Guid idFirmInstitution = new Guid(Request.Form["idFirmInstitution"].ToString());
             model.idFirmInstitution = idFirmInstitution;
             FirmInstitution Firm = FirmInstitutionBL.GetFirmInstitutionByIdFirmInstitution(idFirmInstitution);
             if (Firm != null)
             {
                 model.FirmInstitutionName = Firm.FirmInstitutionName;
                 model.FirmInstitution = Firm;
                 ListeClient = AgUpsideoClientBL.GetListeClient(idCgpAgreg, Firm.idAgregCabinet.Value);
                 model.ListeClient = ListeClient;
             }
             model.IsEndImport = false;
             return View("Agregateur",model);
         }
         
     }
     catch (Exception ex)
     {
         Log.AppendException(ex);
         ViewBag.Error = LanguageData.GetContent("erreur_selection_type_import");
     }
     return View("Agregateur");
 }