Example #1
0
        private void SeedRoles(WyfDbContext context)
        {
            var roleStore   = new RoleStore <IdentityRole>(context);
            var roleManager = new RoleManager <IdentityRole>(roleStore);
            var allRoles    = new string[] { "User", "Admin", "Employer", "Employee" };

            foreach (var role in allRoles)
            {
                if (!roleManager.RoleExists(role))
                {
                    roleManager.Create(new IdentityRole(role));
                }
            }

            context.SaveChanges();
        }
Example #2
0
        private void SeedCities(WyfDbContext context)
        {
            string[] citiesToSeed = new[]
            {
                "Blagoevgrad",
                "Burgas",
                "Dobrich",
                "Gabrovo",
                "Haskovo",
                "Kardzhali",
                "Kyustendil",
                "Lovech",
                "Montana",
                "Pazardzhik",
                "Pernik",
                "Pleven",
                "Plovdiv",
                "Razgrad",
                "Ruse",
                "Shumen",
                "Svishtov",
                "Silistra",
                "Sliven",
                "Smolyan",
                "Sofia",
                "Sofia Region",
                "Stara Zagora",
                "Targovishte",
                "Varna",
                "Veliko Tarnovo",
                "Vidin",
                "Vratsa",
                "Yambol",
                "Other Bulgarian",
                "Other Abroad"
            };

            foreach (var cityName in citiesToSeed)
            {
                context.Cities.AddOrUpdate(c => c.Name, new City()
                {
                    Name = cityName
                });
                context.SaveChanges();
            }
        }
Example #3
0
        public async Task <KeyValuePair <string, int> > GetPersonInfo()
        {
            ExternalLoginData externalLogin = ExternalLoginData.FromIdentity(User.Identity as ClaimsIdentity);
            WyfDbContext      dbContext     = new WyfDbContext();

            var roles = IdentityUtils.GetRolesFromIdentity(RequestContext.Principal.Identity);

            var identityUserId = RequestContext.Principal.Identity.GetUserId();
            KeyValuePair <string, int> pair = new KeyValuePair <string, int>();
            var employerRoleName            = "Employer";
            var employeeRoleName            = "Employee";

            if (roles.Contains(employerRoleName) && !roles.Contains(employeeRoleName))
            {
                Employer employer = await this._context.Employers.FirstOrDefaultAsync(e => e.UserId == identityUserId);

                pair = new KeyValuePair <string, int>(employerRoleName, employer.Id);
            }
            else if (roles.Contains(employeeRoleName) && !roles.Contains(employerRoleName))
            {
                try
                {
                    Employee employee =
                        await this._context.Employees.FirstOrDefaultAsync(e => e.UserId == identityUserId);

                    pair = new KeyValuePair <string, int>(employeeRoleName, employee.Id);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            else
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("There are Person with the current user identity found in the database."),
                    ReasonPhrase = "Missing Resource Exception"
                });
            }

            return(pair);
        }
Example #4
0
        private void SeedIndustries(WyfDbContext context)
        {
            string[] industries = new[]
            {
                "Accounting, Auditing",
                "Administrative And Support Services",
                "Advertising, Marketing, Pr",
                "Agriculture, Forestry And Fishing",
                "Architectural Services",
                "Arts, Entertainment",
                "Automobile Industry",
                "Banking, Finance, Investments",
                "Beauty Parlour",
                "Chemistry And Chemical Technologies",
                "Computer Hardware",
                "Computer Software",
                "Construction",
                "Consulting",
                "Courier Services",
                "Design, Computer Design, Creative",
                "Education, Training, Library",
                "Electronics, Electrotechnics",
                "Energetics, Electricity",
                "Engineering",
                "Food Industry",
                "Governmental, Municipal",
                "Healthcare, Medicine",
                "HR, Employment",
                "Insurance",
                "Internet, e-Commerce",
                "IT",
                "Legal, Law Enforcement",
                "Maintenance Support",
                "Management",
                "Manufacturing, Production",
                "Media",
                "Military",
                "Mining",
                "Non-Profit, Social Service",
                "Personal Care",
                "Pharmaceutical, Biotechnology",
                "Policy Making",
                "Real Estate",
                "Restaurant, Food Services",
                "Sales, Customer Support",
                "Security Services",
                "Social Activities",
                "Science",
                "Sports, Recreation, Rehabilitation",
                "Telecommunication",
                "Textile Industry",
                "Tourism, Hospitality",
                "Trade-Retail, Wholesale",
                "Translation Services",
                "Transportation, Logistics",
                "Other"
            };

            foreach (var industryName in industries)
            {
                context.Industries.AddOrUpdate(c => c.Name, new Industry()
                {
                    Name = industryName
                });
                context.SaveChanges();
            }
        }