예제 #1
0
        public EntrepriseModel Add(EntrepriseModel entreprise)
        {
            Entreprise entity = Entreprise.formModel(entreprise);

            _ctx.Entreprise.Add(entity);
            _ctx.SaveChanges();
            return(Entreprise.toModel(entity));
        }
예제 #2
0
 public static Entreprise formModel(EntrepriseModel address)
 {
     return(new Entreprise
     {
         EntrepriseId = address.EntrepriseId,
         Name = address.Name,
         Tva = address.Tva,
         Contracts = address.Contracts.Select(c => Contract.formModel(c)).ToList(),
         Entities = address.Entities.Select(e => Entity.formModel(e)).ToList(),
         UpdatedDate = address.UpdatedDate,
         CreatedDate = address.CreatedDate,
         DeletedDate = address.DeletedDate,
     });
 }
예제 #3
0
        public void Remove(EntrepriseModel entreprise)
        {
            Entreprise entity = Entreprise.formModel(entreprise);

            entreprise.DeletedDate = DateTime.UtcNow;
            foreach (var child in entity.Entities)
            {
                child.DeletedDate = DateTime.UtcNow;
            }
            foreach (var child in entity.Contracts)
            {
                child.DeletedDate = DateTime.UtcNow;
            }
            _ctx.SaveChanges();
        }
예제 #4
0
        public void Delete(EntrepriseModel entreprise)
        {
            Entreprise entity = Entreprise.formModel(entreprise);

            foreach (var child in entity.Entities)
            {
                _ctx.Entity.Remove(child);
            }
            foreach (var child in entity.Contracts)
            {
                _ctx.Contract.Remove(child);
            }
            _ctx.Entreprise.Remove(entity);
            _ctx.SaveChanges();
        }
예제 #5
0
        private static void RecupererSociete(string annee)
        {
            List <EntrepriseModel> entrepriseModels = new List <EntrepriseModel>();
            string rootUrlRNE       = "https://www.registre-entreprises.tn/search/";
            string urlRNE           = $"{rootUrlRNE}RCCSearch.do?action=getPage&rg_type=PM&search_mode=NORMAL";
            string urlRNENext       = $"{rootUrlRNE}RCCSearch.do?action=search&id=n";
            string urlRNEPrevious   = $"{rootUrlRNE}RCCSearch.do?action=search&id=p";
            string urlDetailsResult = $"{rootUrlRNE}RCCSearch.do?action=chooseDocuments&numRegistreIndex=";
            string urlBackToList    = $"{rootUrlRNE}RCCSearch.do?action=backToList";

            using (var webDriver = WebDriverHelper.CreateSession())
            {
                webDriver.ResizeWindow(SeleniumConfig.BrowserSize);
                webDriver.Navigate().GoToUrl(urlRNE);
                Thread.Sleep(500);
                var selectAnneeInsertion = webDriver.FindElement(By.Name("searchRegistrePmRcc.registrePm.demande.anneeInsertion"));
                selectAnneeInsertion.Click();
                var option2020 = selectAnneeInsertion.FindElement(By.XPath($"option[@value='{annee}']"));
                option2020.Click();
                var searchButton = webDriver.FindElement(By.XPath("//div[text() = 'Rechercher']"));
                searchButton.Click();

                bool isElementDisplayed = webDriver.FindElement(By.ClassName("search-result-jort")).Displayed;

                int indexFile = 0;

                while (webDriver.FindElement(By.ClassName("search-result-jort")).Displayed)
                {
                    var lignes = webDriver.FindElements(By.XPath("//table[@class='search-result-jort']/tbody/tr"));

                    for (int i = 0; i < lignes.Count(); i++)
                    {
                        webDriver.Navigate().GoToUrl(urlDetailsResult + $"{i}");

                        try
                        {
                            var entreprise = new EntrepriseModel();

                            if (webDriver.FindElement(By.ClassName("search-result-jort")).Displayed)
                            {
                                entreprise.IdentifiantUnique        = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[1]/td[2]")).Text;
                                entreprise.FormeJuridique           = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[2]/td[2]")).Text;
                                entreprise.FormeJuridiqueArabe      = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[2]/td[3]")).Text;
                                entreprise.EtatRegistre             = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[3]/td[2]")).Text;
                                entreprise.EtatRegistreArabe        = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[3]/td[3]")).Text;
                                entreprise.SituationFiscale         = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[4]/td[2]")).Text;
                                entreprise.SituationFiscaleArabe    = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[4]/td[3]")).Text;
                                entreprise.DenominationSociale      = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[5]/td[2]")).Text;
                                entreprise.DenominationSocialeArabe = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[5]/td[3]")).Text;
                                entreprise.NomCommercial            = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[6]/td[2]")).Text;
                                entreprise.NomCommercialArabe       = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[6]/td[3]")).Text;;
                                entreprise.AdresseSiege             = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[7]/td[2]")).Text;
                                entreprise.AdresseSiegeArabe        = webDriver.FindElement(By.XPath("//table[contains(@class,'search-result-jort')]/tbody/tr[7]/td[3]")).Text;
                            }

                            entrepriseModels.Add(entreprise);
                        }
                        catch (Exception ex)
                        {
                        }

                        webDriver.Navigate().GoToUrl(urlBackToList);
                    }

                    if (entrepriseModels.Count() >= 1000)
                    {
                        var json = JsonConvert.SerializeObject(entrepriseModels);
                        File.WriteAllText($"export_{annee}_{indexFile}.json", json, Encoding.UTF8);
                        entrepriseModels.Clear();
                        indexFile++;
                    }

                    webDriver.Navigate().GoToUrl(urlRNENext);
                }
            }
        }
예제 #6
0
        public void Update(EntrepriseModel dBentreprise, EntrepriseModel entreprise)
        {
            Entreprise dBentity = Entreprise.formModel(dBentreprise);
            Entreprise entity   = Entreprise.formModel(entreprise);

            _ctx.Entry(dBentity).CurrentValues.SetValues(entity);

            // Delete Entities
            foreach (var child in dBentity.Entities.ToList())
            {
                if (!entity.Entities.Any(c => c.EntityId == child.EntityId))
                {
                    _ctx.Entity.Remove(child);
                }
            }

            //update or insert
            foreach (var child in entity.Entities)
            {
                if (child == null)
                {
                    continue;
                }

                var existingChild = dBentity.Entities
                                    .Where(c => c.EntityId == child.EntityId)
                                    .SingleOrDefault();

                if (existingChild != null)
                {
                    // Update child
                    _ctx.Entry(existingChild).CurrentValues.SetValues(child);
                    _ctx.Entry(existingChild.Address).CurrentValues.SetValues(child.Address);
                }
                else
                {
                    // Insert child
                    var newChild = new Entity
                    {
                        isSiegeCentral = child.isSiegeCentral,
                        Address        = new Address
                        {
                            City   = child.Address.City,
                            Street = child.Address.Street
                        }
                    };
                    dBentity.Entities.Add(newChild);
                }
            }

            // Delete Contracts
            foreach (var child in dBentity.Contracts.ToList())
            {
                if (!entity.Contracts.Any(c => c.ContactId == child.ContactId && c.EntrepriseId == child.EntrepriseId))
                {
                    _ctx.Contract.Remove(child);
                }
            }

            //update or insert
            foreach (var child in entity.Contracts)
            {
                var existingChild = dBentity.Contracts
                                    .Where(c => c.ContactId == child.ContactId && c.EntrepriseId == child.EntrepriseId)
                                    .SingleOrDefault();

                if (existingChild != null)
                {
                    // Update child
                    _ctx.Entry(existingChild).CurrentValues.SetValues(child);
                }
                else
                {
                    // Insert child
                    var newChild = new Contract
                    {
                        ContractType = child.ContractType,
                        TVA          = child.TVA,
                        ContactId    = child.ContactId
                    };
                    dBentity.Contracts.Add(newChild);
                }
            }

            _ctx.SaveChanges();
        }
        public void Remove(int id)
        {
            EntrepriseModel dBentity = _entrepriseDAL.Get(id);

            _entrepriseDAL.Remove(dBentity);
        }
        public void Delete(int id)
        {
            EntrepriseModel dBentity = _entrepriseDAL.Get(id);

            _entrepriseDAL.Delete(dBentity);
        }
        public void Update(EntrepriseDTO entity)
        {
            EntrepriseModel dBentity = _entrepriseDAL.Get(entity.EntrepriseId);

            _entrepriseDAL.Update(dBentity, EntrepriseModel.formDTO(entity));
        }
        public EntrepriseDTO Add(EntrepriseDTO entity)
        {
            EntrepriseModel entreprise = EntrepriseModel.formDTO(entity);

            return(EntrepriseModel.toDTO(_entrepriseDAL.Add(entreprise)));
        }
 public EntrepriseDTO Get(int id)
 {
     return(EntrepriseModel.toDTO(_entrepriseDAL.Get(id)));
 }
 public IEnumerable <EntrepriseDTO> GetAll()
 {
     return(_entrepriseDAL.GetAll().Select(c => EntrepriseModel.toDTO(c)));
 }