示例#1
0
 public DSCBD(CompanyObject action) : base(action)
 {
 }
示例#2
0
        private async Task <bool> CreateCompanyDbAsync(string connectionString, CompanyDto companyInputDto, string companyGUID, string objectGUID)
        {
            var options = new DbContextOptionsBuilder <CompanyDbContext>();

            options.UseSqlServer(connectionString);
            var companyContext = new CompanyDbContext(options.Options);

            using (companyContext)
            {
                try
                {
                    await companyContext.Database.MigrateAsync();

                    using var secondTransaction = await companyContext.Database.BeginTransactionAsync();

                    var company = new Company()
                    {
                        Name            = companyInputDto.Name,
                        Address         = companyInputDto.Address,
                        City            = companyInputDto.City,
                        Country         = companyInputDto.Country,
                        EIK             = companyInputDto.EIK,
                        VatId           = companyInputDto.VatId,
                        Email           = companyInputDto.Email,
                        MOL             = companyInputDto.MOL,
                        IsVatRegistered = companyInputDto.IsVatRegistered,
                        LogoPath        = companyInputDto.LogoPath,
                        IsActive        = false,
                        GUID            = companyGUID,
                    };

                    var obj = new CompanyObject()
                    {
                        Name     = "Стандарт",
                        City     = companyInputDto.City,
                        StartNum = 1,
                        EndNum   = 9999999999,
                        IsActive = true,
                        GUID     = objectGUID,
                    };
                    company.CompanyObjects.Add(obj);

                    var employee = new Employee()
                    {
                        FullName = companyInputDto.MOL,
                        IsActive = true,
                    };

                    company.Employees.Add(employee);

                    await companyContext.Companies.AddAsync(company);

                    await companyContext.SaveChangesAsync();

                    var seeder = new SeedData(companyContext);
                    await seeder.SeedAsync(companyInputDto.IsVatRegistered);

                    await secondTransaction.CommitAsync();
                }
                catch (Exception ex)
                {
                    companyContext.Database.EnsureDeleted();
                    return(false);
                }
            }

            return(true);
        }
示例#3
0
        public ActionResult EditCompany(Company company, Person person)
        {
            ModelState.Clear();
            ViewBag.LoadStatus = "0";
            try
            {
                if (Session["_company"] == null)
                {
                    company.Error     = "Session has expired";
                    company.ErrorCode = 0;
                    return(Json(company, JsonRequestBehavior.AllowGet));
                }

                var oldCompany = Session["_company"] as CompanyObject;

                if (oldCompany == null || oldCompany.CompanyId < 1)
                {
                    company.Error     = "Session has expired";
                    company.ErrorCode = 0;
                    return(Json(company, JsonRequestBehavior.AllowGet));
                }

                if (!ModelState.IsValid)
                {
                    company.Error     = "Please supply all required fields and try again";
                    company.ErrorCode = -1;
                    return(Json(company, JsonRequestBehavior.AllowGet));
                }

                var wx = ValidateControl(company);

                if (wx.Code < 1)
                {
                    company.Error     = wx.Error;
                    company.ErrorCode = -1;
                    return(Json(company, JsonRequestBehavior.AllowGet));
                }

                var newPerson = new Person();
                if (oldCompany.PersonObj != null && oldCompany.PersonObj.PersonId > 0)
                {
                    var oldPerson = oldCompany.PersonObj;
                    newPerson.FirstName   = person.FirstName;
                    newPerson.LastName    = person.LastName;
                    newPerson.Email       = person.Email;
                    newPerson.Designation = person.Designation;
                    newPerson.PhoneNumber = person.PhoneNumber;
                    newPerson.PersonId    = oldPerson.PersonId;
                    newPerson.CompanyId   = oldCompany.CompanyId;
                }

                else
                {
                    newPerson = new Person
                    {
                        FirstName   = person.FirstName,
                        LastName    = person.LastName,
                        Email       = person.Email,
                        Designation = person.Designation,
                        PhoneNumber = person.PhoneNumber,
                        CompanyId   = oldCompany.CompanyId,
                    };
                }
                var newCompany = new Company
                {
                    RCNumber  = company.RCNumber,
                    Name      = company.Name,
                    Address   = company.Address,
                    CompanyId = oldCompany.CompanyId,
                    People    = null
                };

                var k = new CompanyServices().UpdateCompanyCheckDuplicate(newCompany, newPerson);
                if (k < 1)
                {
                    if (k == -3)
                    {
                        company.Error     = "Company already exists";
                        company.ErrorCode = 0;
                        return(Json(company, JsonRequestBehavior.AllowGet));
                    }

                    if (k == -4)
                    {
                        company.Error     = "This Contact Person has already be registered for this Company";
                        company.ErrorCode = 0;
                        return(Json(company, JsonRequestBehavior.AllowGet));
                    }

                    company.Error     = "Process Failed! Please contact the Admin or try again later";
                    company.ErrorCode = 0;
                    return(Json(company, JsonRequestBehavior.AllowGet));
                }

                var dct = new CompanyObject
                {
                    RCNumber   = company.RCNumber,
                    Name       = company.Name,
                    Address    = company.Address,
                    CompanyId  = k,
                    PersonName = person.FirstName + " " + person.LastName,
                    ErrorCode  = 1,
                    Error      = "Company Information was successfully updated"
                };

                return(Json(dct, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                company.Error     = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                company.ErrorCode = 0;
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(Json(company, JsonRequestBehavior.AllowGet));
            }
        }
示例#4
0
 public DCBJD(CompanyObject action) : base(action)
 {
 }
示例#5
0
 public DFS(CompanyObject action) : base(action)
 {
 }
示例#6
0
        public ActionResult AddCompany(Company company, Person person)
        {
            ModelState.Clear();
            ViewBag.LoadStatus = "0";
            try
            {
                if (!ModelState.IsValid)
                {
                    company.Error     = "Please supply all required fields and try again";
                    company.ErrorCode = -1;
                    return(Json(company, JsonRequestBehavior.AllowGet));
                }

                var wx = ValidateControl(company);

                if (wx.Code < 1)
                {
                    company.Error     = wx.Error;
                    company.ErrorCode = -1;
                    return(Json(company, JsonRequestBehavior.AllowGet));
                }

                var wx2 = ValidateControl(person);

                if (wx2.Code < 1)
                {
                    company.Error     = wx2.Error;
                    company.ErrorCode = -1;
                    return(Json(company, JsonRequestBehavior.AllowGet));
                }

                company.People = new List <Person> {
                    person
                };
                var k = new CompanyServices().AddCompanyCheckDuplicate(company);
                if (k < 1)
                {
                    if (k == -3)
                    {
                        company.Error     = "Company already exists";
                        company.ErrorCode = 0;
                        return(Json(company, JsonRequestBehavior.AllowGet));
                    }

                    company.Error     = "Process Failed! Please contact the Admin or try again later";
                    company.ErrorCode = 0;
                    return(Json(company, JsonRequestBehavior.AllowGet));
                }

                var dct = new CompanyObject
                {
                    RCNumber   = company.RCNumber,
                    Name       = company.Name,
                    Address    = company.Address,
                    CompanyId  = k,
                    PersonName = person.FirstName + " " + person.LastName,
                    ErrorCode  = 1,
                    Error      = "Company was successfully added"
                };

                return(Json(dct, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                company.Error     = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                company.ErrorCode = 0;
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(Json(company, JsonRequestBehavior.AllowGet));
            }
        }
示例#7
0
        /// <summary>
        /// Creates a new company organizational unit
        /// </summary>
        /// <param name="hostingOrganizationalUnit"></param>
        /// <param name="company"></param>
        /// <returns></returns>
        public string CreateCompany(string parentOrganizationalUnit, CompanyObject company)
        {
            DirectoryEntry de     = null;
            DirectoryEntry newOrg = null;

            try
            {
                this.logger.Debug("Attempting to create new organizational unit for company " + company.CompanyName + " on path " + parentOrganizationalUnit);

                de = new DirectoryEntry("LDAP://" + this.domainController + "/" + parentOrganizationalUnit, this.username, this.password);

                // Add organizational unit
                newOrg = de.Children.Add("OU=" + company.CompanyCode, "OrganizationalUnit");

                // Set additional information
                newOrg.Properties["description"].Add(company.CompanyName);
                newOrg.Properties["displayName"].Add(company.CompanyName);
                newOrg.Properties["uPNSuffixes"].Add(company.Domains[0]);

                // These values may not be set so only set if they are valid
                if (!string.IsNullOrEmpty(company.Street))
                {
                    newOrg.Properties["street"].Add(company.Street);
                }

                if (!string.IsNullOrEmpty(company.City))
                {
                    newOrg.Properties["l"].Add(company.City);
                }

                if (!string.IsNullOrEmpty(company.State))
                {
                    newOrg.Properties["st"].Add(company.State);
                }

                if (!string.IsNullOrEmpty(company.ZipCode))
                {
                    newOrg.Properties["postalCode"].Add(company.ZipCode);
                }

                if (!string.IsNullOrEmpty(company.Telephone))
                {
                    newOrg.Properties["telephoneNumber"].Add(company.Telephone);
                }

                if (!string.IsNullOrEmpty(company.AdminName))
                {
                    newOrg.Properties["adminDisplayName"].Add(company.AdminName);
                }

                if (!string.IsNullOrEmpty(company.AdminEmail))
                {
                    newOrg.Properties["adminDescription"].Add(company.AdminEmail);
                }

                // Commit all the changes to the new OU
                newOrg.CommitChanges();
                this.logger.Debug("Committed changes to new organizational unit for company " + company.CompanyName);

                // Commit the changes to the parent OU
                de.CommitChanges();
                this.logger.Info("Finished creating new organizational unit for company " + company.CompanyName);

                // Return the distinguished name
                return(newOrg.Properties["distinguishedName"][0].ToString());
            }
            catch (Exception ex)
            {
                this.logger.Error("There was an error creating a new organizational unit for company " + company.CompanyName, ex);

                throw;
            }
            finally
            {
                if (newOrg != null)
                {
                    newOrg.Dispose();
                }

                if (de != null)
                {
                    de.Dispose();
                }
            }
        }
        /// <summary>
        /// Run the relevant scraper
        /// </summary>
        /// <param name="company">the company to be scraped</param>
        /// <returns>a list of all found vacancies</returns>
        public async Task <string> Scrape(CompanyObject company)
        {
            var log = new StringBuilder();

            var scrapeResults = new Dictionary <string, object>();

            await Task.Run(() =>
            {
                switch (company.Name)
                {
                case "Novo Nordisk":
                    scrapeResults = new ScrapeNovoNordisk().Run(company);
                    break;

                case "DTU":
                    scrapeResults = new ScrapeDTU().Run(company);
                    break;

                case "Novozymes":
                    scrapeResults = new ScrapeNovozymes().Run(company);
                    break;

                case "Biogen":
                    scrapeResults = new ScrapeBiogen().Run(company);
                    break;

                case "AGC Biologics":
                    scrapeResults = new ScrapeAgcBiologics().Run(company);
                    break;
                }
            });

            var foundVacancies = scrapeResults[KeyCategory.Vacancies.Key] as List <VacancyObject> ?? new List <VacancyObject>();
            var exceptions     = scrapeResults[KeyCategory.Errors.Key] as List <Exception> ?? new List <Exception>();

            // Logging
            log.Append("Company: " + company.Name + Environment.NewLine);
            log.Append(DateTime.Now.ToString(CultureInfo.CurrentCulture) + Environment.NewLine);
            log.Append(Environment.NewLine);

            var totalVacanciesFound = foundVacancies.Count;

            // Check for vacancies that contain the banned keywords
            var bannedKeywords = _settingsManager.Settings.ScraperBannedKeywords.Split(',');

            for (var i = foundVacancies.Count - 1; i >= 0; i--)
            {
                var remove = false;
                foreach (var bannedKeyword in bannedKeywords)
                {
                    if (string.IsNullOrWhiteSpace(bannedKeyword))
                    {
                        continue;
                    }

                    if (foundVacancies[i].Title.IndexOf(bannedKeyword, StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        remove = true;

                        log.Append("Found vacancy, removed by keyword match '" + bannedKeyword + "' : " + foundVacancies[i].Title + Environment.NewLine);
                    }
                }

                if (remove)
                {
                    foundVacancies.RemoveAt(i);
                }
            }

            // Check for duplicates in the already added vacancies
            for (var i = foundVacancies.Count - 1; i >= 0; i--)
            {
                if (_vacancyManager.Resources.Contains(foundVacancies[i]))
                {
                    log.Append("Found vacancy, removed by duplicate in 'vacancies' : " + foundVacancies[i].Title + Environment.NewLine);
                    foundVacancies.RemoveAt(i);
                }
            }

            // Check for items in the blacklist
            for (var i = foundVacancies.Count - 1; i >= 0; i--)
            {
                if (_blacklistManager.Resources.Contains(foundVacancies[i]))
                {
                    log.Append("Found vacancy, removed by duplicate in 'blacklist' : " + foundVacancies[i].Title + Environment.NewLine);
                    foundVacancies.RemoveAt(i);
                }
            }

            // Check for items in the done list
            var ignoreDuplicatesBeforeThisDate = ConstructDateTime.GetDateToIgnoreDuplicatesBefore();

            for (var i = foundVacancies.Count - 1; i >= 0; i--)
            {
                var found = _doneManager.Resources.Find(o => Equals(o, foundVacancies[i]));
                if (found != null)
                {
                    if (found.Added > ignoreDuplicatesBeforeThisDate) // Added recently, mark as duplicate
                    {
                        log.Append("Found vacancy, removed by duplicate in 'done' : " + foundVacancies[i].Title + Environment.NewLine);
                        foundVacancies.RemoveAt(i);
                    }
                }
            }

            // Check jobnet for duplicates
            var jobnetResults = new Dictionary <string, object>();

            if (_settingsManager.Settings.ScraperCheckJobnet)
            {
                await Task.Run(() =>
                {
                    jobnetResults = new ScraperJobnet().Run(company);
                });

                var foundVacanciesJobnet = jobnetResults[KeyCategory.Vacancies.Key] as List <string> ?? new List <string>();
                var exceptionsJobnet     = jobnetResults[KeyCategory.Errors.Key] as List <Exception> ?? new List <Exception>();

                exceptions.AddRange(exceptionsJobnet);

                // Filter out duplicates
                for (var i = foundVacancies.Count - 1; i >= 0; i--)
                {
                    if (foundVacanciesJobnet.Contains(foundVacancies[i].Title))
                    {
                        log.Append("Found vacancy, removed by duplicate on jobnet.dk : " + foundVacancies[i].Title + Environment.NewLine);

                        foundVacancies.RemoveAt(i);
                    }
                }
            }

            // All checks complete, save leftover vacancies
            foreach (var vacancy in foundVacancies)
            {
                _vacancyManager.Resources.Add(vacancy);
                _vacancyManager.SaveChangesToFile();
            }

            // Add all leftover vacancies to the log
            foreach (var vacancy in foundVacancies)
            {
                log.Append("Found and added : " + vacancy.Title + Environment.NewLine);
            }

            // Normal Log ending
            log.Append(Environment.NewLine);
            log.Append("Found: " + totalVacanciesFound + Environment.NewLine);
            log.Append("Added: " + foundVacancies.Count + Environment.NewLine);

            // Log exceptions
            if (exceptions.Count > 0)
            {
                log.Append(Environment.NewLine + "Exceptions:" + Environment.NewLine + Environment.NewLine);
                foreach (var exception in exceptions)
                {
                    log.Append(exception.Message + Environment.NewLine + exception.StackTrace + Environment.NewLine + Environment.NewLine);
                }
            }

            // Write complete log to file
            var path = Path.Combine(_settingsManager.Settings.LogsFolderPath, company.Name);

            Directory.CreateDirectory(path);
            File.WriteAllText(Path.Combine(path, (DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + " " + company.Name + ".txt")), log.ToString());

            if (exceptions.Count > 0)
            {
                return(@"Error (Check logs for more info)");
            }

            return(@"Complete (" + foundVacancies.Count + " of " + totalVacanciesFound + " vacancies added)");
        }
示例#9
0
 public DICG(CompanyObject action) : base(action)
 {
 }
示例#10
0
 public DCSH(CompanyObject action) : base(action)
 {
 }
示例#11
0
        public override Dictionary <string, object> Run(CompanyObject company)
        {
            var dictionary = new Dictionary <string, object>();

            var foundVacancies = new List <VacancyObject>();
            var errors         = new List <Exception>();

            try
            {
                if (IsValidHttpUrl(company.Url))
                {
                    NavigateToUrlAndWaitUntilLoaded(company.Url);
                }
                else
                {
                    throw new WebDriverException("Invalid URL (" + company.Url + ")");
                }

                // Get the language button
                var languageButton = Driver.FindElement(By.XPath("//button[contains(text(),'Languages')]"));

                if (languageButton != null)
                {
                    // Open dropdown menu
                    languageButton.Click();

                    IReadOnlyCollection <IWebElement> languageCheckBoxes = Driver.FindElements(By.ClassName("custom-checked"));
                    IWebElement danishCheckBox = null;

                    if (languageCheckBoxes.Count == 0)
                    {
                        throw new WebDriverException("Couldn't find language checkboxes");
                    }

                    for (var i = 0; i < languageCheckBoxes.Count; i++)
                    {
                        if (languageCheckBoxes.ElementAt(i).Text.Equals("Danish"))
                        {
                            danishCheckBox = languageCheckBoxes.ElementAt(i);
                            break;
                        }
                    }

                    if (danishCheckBox != null)
                    {
                        // Deselect danish
                        danishCheckBox.Click();

                        ScrollToEndOfPage();

                        // Find all vacancies
                        IReadOnlyCollection <IWebElement> vacancies = Driver.FindElements(By.XPath("//tr[@class='row-record']"));
                        for (var i = 0; i < vacancies.Count; i++)
                        {
                            foundVacancies.Add(new VacancyObject(
                                                   company.Name,
                                                   vacancies.ElementAt(i).FindElement(By.ClassName("joblist-row-heading")).Text,
                                                   DateTime.Now,
                                                   vacancies.ElementAt(i).FindElement(By.TagName("a")).GetAttribute("href")));
                        }
                    }
                    else
                    {
                        throw new WebDriverException("Couldn't find checkbox for danish language");
                    }
                }
                else
                {
                    throw new WebDriverException("Couldn't find language button");
                }
            }
            catch (Exception e)
            {
                errors.Add(e);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                Driver.Close();
                Driver.Quit();
            }

            dictionary.Add(KeyCategory.Vacancies.Key, foundVacancies);
            dictionary.Add(KeyCategory.Errors.Key, errors);

            return(dictionary);
        }