コード例 #1
0
        public async Task<bool> Register(ArgJobSeekerTemp arg)
        {
            Utils.CheckNullOrEmpty(new List<string> { "Email", "FullName", "PhoneNumber" }, arg.Email, arg.FullName, arg.PhoneNumber);

            using (AppDbContext context = new AppDbContext())
            {
                if (arg.Industry==null)
                {
                    arg.Industry = await context.Industries.FirstOrDefaultAsync(x => x.Name == null);
                }
                context.JobSeekerTempProfiles.Add(new JobSeekerTempProfile
                {
                    FullName = arg.FullName,
                    Email = arg.Email,
                    PhoneNumber = arg.PhoneNumber,
                    ExperienceLevel = arg.ExperienceLevel,
                    IndustryId = arg.Industry.Id,
                    DayOfBirthUtc = arg.DayOfBirthUtc,
                    RegisteredDateUtc = DateTime.UtcNow
                });
                await EmailDelivery.SendJobSeekerRegisterCompleted(arg.Email);
                await context.SaveChangesAsync();
                return true;
            }
        }
コード例 #2
0
 public async Task<User> GetEmployerById(Guid id)
 {
     using (AppDbContext context = new AppDbContext())
     {
         User user = await context.Users.Include(x => x.Employer).Where(x => x.Id == id).FirstOrDefaultAsync();
         return user;
     }
 }
コード例 #3
0
 public async Task<List<CompanyHisotry>> GetCompanyHistoryForJobSeeker(Guid id)
 {
     using (AppDbContext context = new AppDbContext())
     {
         List<CompanyHisotry> companyHisotries = await context.CompanyHisotries.Where(x => x.JobSeekerId == id).OrderBy(x=>x.CreatedDateUtc).ToListAsync();
         return companyHisotries;
     }
 }
コード例 #4
0
 public async Task<List<User>> GetTopEmployer()
 {
     using (AppDbContext context = new AppDbContext())
     {
         List<User> users = await context.Users.Include(x => x.Employer).Where(x => x.UserType == UserType.Employer).OrderByDescending(x => x.Employer.CreatedDateUtc).Take(5).ToListAsync();
         return users;
     }
 }
コード例 #5
0
ファイル: JobManager.cs プロジェクト: Soucre/Working_git_vfs
        public async Task CreateNewJob(CreateEditJobParams createEditJobParams)
        {
            Utils.CheckNullOrEmpty(new List<string> { "JobName", "JobType", "JobDescription", "EducationLevel", "FieldOfStudy", "Language", "Certification", "MinimumGrade", "IsStartWorkImmediately", "ExperienceLevel", "StartWorkingAt", "EndWorkingAt", "StartDate", "HoursPerDay", "DayPerWeek", "DayPerMonth", "GenderRequired", "MinSalary", "MaxSalary", "IsSalaryIncludeMealAndBreakTime" }, createEditJobParams.JobName, createEditJobParams.JobType, createEditJobParams.JobDescription, createEditJobParams.Location, createEditJobParams.EducationLevel, createEditJobParams.FieldOfStudy, createEditJobParams.Language, createEditJobParams.Certification, createEditJobParams.MinimumGrade, createEditJobParams.IsStartWorkImmediately, createEditJobParams.ExperienceLevel, createEditJobParams.StartWorkingAt, createEditJobParams.EndWorkingAt, createEditJobParams.StartDate, createEditJobParams.HoursPerDay, createEditJobParams.DayPerWeek, createEditJobParams.DayPerMonth, createEditJobParams.GenderRequired, createEditJobParams.MinSalary, createEditJobParams.MaxSalary, createEditJobParams.IsSalaryIncludeMealAndBreakTime);
            using (AppDbContext context = new AppDbContext())
            {
                User user = await GetCurrentUser(context);

                if (user.UserType == UserType.Employer)
                {
                    Job job = new Job
                    {
                        Id = Guid.NewGuid(),
                        EmployerId = _userId,
                        LanguageId = createEditJobParams.Language.Id,
                        JobName = createEditJobParams.JobName,
                        JobType = createEditJobParams.JobType,
                        MinSalary = createEditJobParams.MinSalary,
                        MaxSalary = createEditJobParams.MaxSalary,
                        ExtraSalary = createEditJobParams.ExtraSalary,
                        StartDate = createEditJobParams.StartDate,
                        EndDate = createEditJobParams.EndDate,
                        JobStartDate = createEditJobParams.JobStartDate,
                        JobDescription = createEditJobParams.JobDescription,
                        IsStartWorkImmediately = createEditJobParams.IsStartWorkImmediately,
                        StartWorkingAt = createEditJobParams.StartWorkingAt,
                        EndWorkingAt = createEditJobParams.EndWorkingAt,
                        AvailableDate = DateTime.UtcNow,
                        HoursPerDay = createEditJobParams.HoursPerDay,
                        DayPerWeek = createEditJobParams.DayPerWeek,
                        DayPerMonth = createEditJobParams.DayPerMonth,
                        GenderRequired = createEditJobParams.GenderRequired,
                        IsSalaryIncludeMealAndBreakTime = createEditJobParams.IsSalaryIncludeMealAndBreakTime,
                        CreatedDateUtc = DateTime.UtcNow,
                        UpdatedDateUtc = DateTime.UtcNow,
                        LocationId = createEditJobParams.Location.Id
                    };
                    context.Jobs.Add(job);

                    Education education = new Education
                    {
                        Id = Guid.NewGuid(),
                        EducationLevel = createEditJobParams.EducationLevel,
                        FieldOfStudyId = createEditJobParams.FieldOfStudy.Id,
                        Certification = createEditJobParams.Certification,
                        MinimumGrade = createEditJobParams.MinimumGrade,
                        ExperienceLevel = createEditJobParams.ExperienceLevel,
                        JobId = job.Id
                    };
                    context.Educations.Add(education);

                    await context.SaveChangesAsync();
                }
                else
                {
                    throw new UserException(ErrorCode.NO_PERMISSION.ToString());
                }
            }
        }
コード例 #6
0
 public async Task<User> GetUser(Guid id)
 {
     using (AppDbContext context = new AppDbContext())
     {
         await GetCurrentUser(context);
         User user = await context.Users.Include(x => x.JobSeeker).Include(x => x.Employer).Include(x => x.JobSeeker.Language).FirstOrDefaultAsync(p => p.Id == id);
         return user;
     }
 }
コード例 #7
0
 public async Task<List<CompanyHisotry>> GetCompanytHistory(Guid id)
 {
     using (AppDbContext context = new AppDbContext())
     {
         await GetCurrentUser(context);
         List<CompanyHisotry> companyHisotries = await context.CompanyHisotries.Where(x => x.JobSeekerId == id).ToListAsync();
         return companyHisotries;
     }
 }
コード例 #8
0
        public async Task<User> Login(LoginParams loginParams)
        {
            Utils.CheckNullOrEmpty(new List<string> { "Email", "Token" }, loginParams.Email, loginParams.Token);

            using (AppDbContext context = new AppDbContext())
            {
                User user = await context.Users.FirstOrDefaultAsync(p => p.Email == loginParams.Email &&
                                                                         p.AccountType == loginParams.AccountType &&
                                                                         p.UserType == loginParams.UserType);

                if (user == null)
                {
                    throw new UserException(ErrorCode.INVALID.ToString());
                }

                if (!user.IsActivated)
                {
                    throw new UserException(ErrorCode.USER_NOT_VERIFIED_YET.ToString());
                }

                if (loginParams.AccountType == AccountType.Email)
                {
                    if (!UtilsCryptography.VerifyBCryptPassword(loginParams.Token, user.Password))
                    {
                        throw new UserException(ErrorCode.INVALID.ToString());
                    }
                }
                else if (loginParams.AccountType == AccountType.Facebook)
                {
                    try
                    {
                        FacebookClient facebookClient = new FacebookClient(loginParams.Token);
                        await facebookClient.GetTaskAsync("me?fields=id");
                    }
                    catch (Exception)
                    {
                        throw new UserException(ErrorCode.FACEBOOK_INVALID.ToString());
                    }
                }
                else
                {
                    try
                    {
                        string query = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + loginParams.Token;
                        HttpClient client = new HttpClient();
                        await client.GetStringAsync(query);
                    }
                    catch (Exception)
                    {
                        throw new UserException(ErrorCode.GOOGLE_INVALID.ToString());
                    }
                }

                return user;
            }
        }
コード例 #9
0
        public async Task<bool> CheckEmail(ArgJobSeekerTemp arg)
        {
            Utils.CheckNullOrEmpty(new List<string> { "Email" }, arg.Email);

            using (AppDbContext context = new AppDbContext())
            {
                JobSeekerTempProfile jobSeekerTempProfile = await context.JobSeekerTempProfiles.FirstOrDefaultAsync(x => x.Email == arg.Email);
                return jobSeekerTempProfile == null;
            }
        }
コード例 #10
0
ファイル: BaseManager.cs プロジェクト: Soucre/Working_git_vfs
        protected async Task<User> GetCurrentUser(AppDbContext context)
        {
            User user = await context.Users.FirstOrDefaultAsync(p => p.Id == _userId);
            if (user == null)
            {
                throw new UserException(ErrorCode.INVALID_SESSION.ToString());
            }

            return user;
        }
コード例 #11
0
 public async Task<JobSeeker> CreateTempFile(Guid id)
 {
     using (AppDbContext context = new AppDbContext())
     {
         JobSeeker jobSeeker = await context.JobSeekers.FirstOrDefaultAsync(x => x.UserId == id);
         if (jobSeeker == null)
         {
             throw new UserException(ErrorCode.FILE_NOT_FOUND.ToString());
         }
         return jobSeeker;
     }
 }
コード例 #12
0
 public async Task DeleteCompanyHistory(CompanyHisotry deleteCompanyHisotry)
 {
     using (AppDbContext context = new AppDbContext())
     {
         CompanyHisotry companyHisotry =await context.CompanyHisotries.Where(x => x.Id == deleteCompanyHisotry.Id).FirstOrDefaultAsync();
         if (companyHisotry == null)
         {
             throw new UserException(ErrorCode.INVALID.ToString());
         }
         context.CompanyHisotries.Remove(companyHisotry);
         await context.SaveChangesAsync();
     }
 }
コード例 #13
0
 public async Task UpdateEmployerLogoPhoto(byte[] imageBytes)
 {
     using (AppDbContext context = new AppDbContext())
     {
         User user = await GetCurrentUser(context);
         if (user.UserType == UserType.Employer)
         {
             Employer employer = await context.Employers.FirstOrDefaultAsync(x => x.UserId == user.Id);
             employer.Logo = imageBytes;
             await context.SaveChangesAsync();
         }
     }
 }
コード例 #14
0
 public async Task UpdateJobSeekerProfilePhoto(byte[] imageBytes)
 {
     using (AppDbContext context = new AppDbContext())
     {
         User user = await GetCurrentUser(context);
         if (user.UserType == UserType.JobSeeker)
         {
             JobSeeker jobSeeker = await context.JobSeekers.FirstOrDefaultAsync(x => x.UserId == user.Id);
             jobSeeker.Avartar = imageBytes;
             await context.SaveChangesAsync();
         }
     }
 }
コード例 #15
0
 public async Task UpdateJobSeekerMoreDoc(byte[] imageBytes,string extension)
 {
     using (AppDbContext context = new AppDbContext())
     {
         User user = await GetCurrentUser(context);
         if (user.UserType == UserType.JobSeeker)
         {
             JobSeeker jobSeeker = await context.JobSeekers.FirstOrDefaultAsync(x => x.UserId == user.Id);
             jobSeeker.MoreDocument = imageBytes;
             jobSeeker.Extension = extension;
             await context.SaveChangesAsync();
         }
     }
 }
コード例 #16
0
ファイル: JobManager.cs プロジェクト: Soucre/Working_git_vfs
        public async Task UpdateJob(CreateEditJobParams createEditJobParams)
        {
            Utils.CheckNullOrEmpty(new List<string> { "JobId", "JobName", "JobType", "JobDescription", "EducationLevel", "FieldOfStudy", "Language", "Certification", "MinimumGrade", "IsStartWorkImmediately", "ExperienceLevel", "StartWorkingAt", "EndWorkingAt", "StartDate", "HoursPerDay", "DayPerWeek", "DayPerMonth", "GenderRequired", "MinSalary", "MaxSalary", "IsSalaryIncludeMealAndBreakTime" }, createEditJobParams.JobID, createEditJobParams.JobName, createEditJobParams.JobType, createEditJobParams.JobDescription, createEditJobParams.Location, createEditJobParams.EducationLevel, createEditJobParams.FieldOfStudy, createEditJobParams.Language, createEditJobParams.Certification, createEditJobParams.MinimumGrade, createEditJobParams.IsStartWorkImmediately, createEditJobParams.ExperienceLevel, createEditJobParams.StartWorkingAt, createEditJobParams.EndWorkingAt, createEditJobParams.StartDate, createEditJobParams.HoursPerDay, createEditJobParams.DayPerWeek, createEditJobParams.DayPerMonth, createEditJobParams.GenderRequired, createEditJobParams.MinSalary, createEditJobParams.MaxSalary, createEditJobParams.IsSalaryIncludeMealAndBreakTime);

            using (AppDbContext context = new AppDbContext())
            {
                Job job = await context.Jobs.FirstOrDefaultAsync(p => p.Id == createEditJobParams.JobID);
                Education education = await context.Educations.FirstOrDefaultAsync(p => p.JobId == createEditJobParams.JobID);

                if (job == null || education == null)
                {
                    throw new UserException(ErrorCode.INVALID_SESSION.ToString());
                }

                job.LanguageId = createEditJobParams.Language.Id;
                job.JobName = createEditJobParams.JobName;
                job.JobType = createEditJobParams.JobType;
                job.MinSalary = createEditJobParams.MinSalary;
                job.MaxSalary = createEditJobParams.MaxSalary;
                job.ExtraSalary = createEditJobParams.ExtraSalary;
                job.StartDate = createEditJobParams.StartDate;
                job.EndDate = createEditJobParams.EndDate;
                job.JobStartDate = createEditJobParams.JobStartDate;
                job.JobDescription = createEditJobParams.JobDescription;
                job.IsStartWorkImmediately = createEditJobParams.IsStartWorkImmediately;
                job.StartWorkingAt = createEditJobParams.StartWorkingAt;
                job.EndWorkingAt = createEditJobParams.EndWorkingAt;
                job.HoursPerDay = createEditJobParams.HoursPerDay;
                job.DayPerWeek = createEditJobParams.DayPerWeek;
                job.DayPerMonth = createEditJobParams.DayPerMonth;
                job.GenderRequired = createEditJobParams.GenderRequired;
                job.IsSalaryIncludeMealAndBreakTime = createEditJobParams.IsSalaryIncludeMealAndBreakTime;
                job.UpdatedDateUtc = DateTime.UtcNow;
                job.LocationId = createEditJobParams.Location.Id;

                education.EducationLevel = createEditJobParams.EducationLevel;
                education.FieldOfStudyId = createEditJobParams.FieldOfStudy.Id;
                education.Certification = createEditJobParams.Certification;
                education.MinimumGrade = createEditJobParams.MinimumGrade;
                education.ExperienceLevel = createEditJobParams.ExperienceLevel;

                await context.SaveChangesAsync();
            }

        }
コード例 #17
0
ファイル: HomeManager.cs プロジェクト: Soucre/Working_git_vfs
        public async Task Feedback (FeedbackParams feedbackParams)
        {
            Utils.CheckNullOrEmpty(new List<string> { "FullName", "Address", "Email", "PhoneNumber", "Message" }, feedbackParams.FullName, feedbackParams.Address, feedbackParams.Email, feedbackParams.PhoneNumber, feedbackParams.Message);

            using (AppDbContext context = new AppDbContext())
            {
                Feedback feedback = new Feedback
                {
                    Id = Guid.NewGuid(),
                    FullName = feedbackParams.FullName,
                    Address = feedbackParams.Address,
                    Email = feedbackParams.Email,
                    PhoneNumber = feedbackParams.PhoneNumber,
                    Message = feedbackParams.Message,
                    CreatedDateUtc = DateTime.UtcNow
                };

                context.Feedbacks.Add(feedback);
                await context.SaveChangesAsync();
            }
        }
コード例 #18
0
        public async Task<Tuple<List<User>, int, int>> Search(SearchEmployerParams employerParams)
        {
            using (AppDbContext context = new AppDbContext())
            {
                var query = context.Users.Include(x => x.Employer).Where(x => x.UserType == UserType.Employer).AsQueryable();

                if (!string.IsNullOrWhiteSpace(employerParams.CompanyName))
                {
                    query = query.Where(x => x.Employer.CompanyName == employerParams.CompanyName);
                }

                int totalItems = await query.CountAsync();
                int totalPages = totalItems / employerParams.PageSize;
                if (totalItems % employerParams.PageSize > 0)
                {
                    totalPages++;
                }

                List<User> users = await query.OrderByDescending(p => p.Employer.CompanyName).Skip(employerParams.PageIndex * employerParams.PageSize).Take(employerParams.PageSize).ToListAsync();
                return new Tuple<List<User>, int, int>(users, totalPages, totalItems);
            }
        }
コード例 #19
0
 public async Task<List<Location>> GetAllLocation()
 {
     using (AppDbContext context = new AppDbContext())
     {
         List<Location> locations = await context.Locations.OrderBy(x => x.Name).ToListAsync();
         return locations;
     }
 }
コード例 #20
0
        public async Task UpdateEmployerProfile(EmployerProfileUpdatedCompanyInfoParams employerProfileUpdatedCompanyInfoParams)
        {
            Utils.CheckNullOrEmpty(new List<string> { "UserId", "CompanyName", "CompanyRegistrationNumber", "Address", "WebLink", "ContactName", "PhoneNumber", "NatureOfBusiness" }, employerProfileUpdatedCompanyInfoParams.UserId, employerProfileUpdatedCompanyInfoParams.CompanyName, employerProfileUpdatedCompanyInfoParams.CompanyRegistrationNumber, employerProfileUpdatedCompanyInfoParams.Address, employerProfileUpdatedCompanyInfoParams.WebLink, employerProfileUpdatedCompanyInfoParams.ContactName, employerProfileUpdatedCompanyInfoParams.PhoneNumber, employerProfileUpdatedCompanyInfoParams.NatureOfBusiness);

            using (AppDbContext context = new AppDbContext())
            {
                User user = await context.Users.FirstOrDefaultAsync(p => p.Id == employerProfileUpdatedCompanyInfoParams.UserId);
                Employer employer = await context.Employers.FirstOrDefaultAsync(p => p.UserId == employerProfileUpdatedCompanyInfoParams.UserId);

                if (employer == null || user == null)
                {
                    throw new UserException(ErrorCode.INVALID_SESSION.ToString());
                }

                employer.CompanyName = employerProfileUpdatedCompanyInfoParams.CompanyName;
                employer.CompanyRegistrationNumber = employerProfileUpdatedCompanyInfoParams.CompanyRegistrationNumber;
                employer.Address = employerProfileUpdatedCompanyInfoParams.Address;
                employer.WebLink = employerProfileUpdatedCompanyInfoParams.WebLink;
                employer.ContactName = employerProfileUpdatedCompanyInfoParams.ContactName;
                employer.PhoneNumber = employerProfileUpdatedCompanyInfoParams.PhoneNumber;
                employer.NatureOfBusiness = employerProfileUpdatedCompanyInfoParams.NatureOfBusiness;

                await context.SaveChangesAsync();
            }
        }
コード例 #21
0
        public async Task UpdateEmployerProfile(EmployerProfileUpdatedOverviewParams employerProfileUpdatedOverviewParams)
        {
            using (AppDbContext context = new AppDbContext())
            {
                Employer employer = await context.Employers.FirstOrDefaultAsync(p => p.UserId == employerProfileUpdatedOverviewParams.UserId);
                if (employer == null)
                {
                    throw new UserException(ErrorCode.INVALID_SESSION.ToString());
                }

                employer.OverView = employerProfileUpdatedOverviewParams.OverView;
                await context.SaveChangesAsync();
            }
        }
コード例 #22
0
        public async Task UpdateJobSeekerProfile(JobSeekerProfileUpdatedExperienceLevelParams param)
        {
            Utils.CheckNullOrEmpty(new List<string> { "ExperienceYear", "HighestEducation", "ExpectedPosition", "ExpectedLocation", "ExpectedJobCategory", "ExpectedSalary", "UserId" },
                param.ExperienceYear, param.HighestEducation, param.ExpectedPosition, param.ExpectedLocation, param.ExpectedJobCategory, param.ExpectedSalary, param.UserId);

            using (AppDbContext context = new AppDbContext())
            {
                User user = await context.Users.FirstOrDefaultAsync(p => p.Id == param.UserId);
                JobSeeker jobSeeker = await context.JobSeekers.FirstOrDefaultAsync(p => p.UserId == param.UserId);

                if (jobSeeker == null || user == null)
                {
                    throw new UserException(ErrorCode.INVALID_SESSION.ToString());
                }

                jobSeeker.ExperienceYear = param.ExperienceYear;
                jobSeeker.HighestEducation = param.HighestEducation;
                jobSeeker.ExpectedPosition = param.ExpectedPosition;
                jobSeeker.ExpectedLocation = param.ExpectedLocation;
                jobSeeker.ExpectedJobCategory = param.ExpectedJobCategory;
                jobSeeker.ExpectedSalary = param.ExpectedSalary;
                jobSeeker.CanNegotiation = param.CanNegotiation;
                jobSeeker.LanguageId = param.Language.Id;
                jobSeeker.UpdatedDateUtc = DateTime.UtcNow;

                foreach (CompanyHisotry companyHistory in param.CompanyHistories)
                {
                    var company = await context.CompanyHisotries.FirstOrDefaultAsync(x => x.Id == companyHistory.Id);
                    if (company == null)
                    {
                        var newItem = new CompanyHisotry
                        {
                            JobSeekerId = jobSeeker.UserId,
                            CompanyName = companyHistory.CompanyName,
                            Position = companyHistory.Position,
                            From = companyHistory.From,
                            To = companyHistory.To,
                            CreatedDateUtc = DateTime.UtcNow,
                            UpdatedDateUtc = DateTime.UtcNow
                        };
                        context.CompanyHisotries.Add(newItem);
                    }
                    else
                    {
                        company.CompanyName = companyHistory.CompanyName;
                        company.Position = companyHistory.Position;
                        company.From = companyHistory.From;
                        company.To = companyHistory.To;
                        company.UpdatedDateUtc = DateTime.UtcNow;
                    }
                }
                await context.SaveChangesAsync();
            }
        }
コード例 #23
0
        public async Task UpdateJobSeekerProfile(JobSeekerProfileUpdatedAdditionInfoParam param)
        {
            using (AppDbContext context = new AppDbContext())
            {
                JobSeeker jobSeeker = await context.JobSeekers.FirstOrDefaultAsync(p => p.UserId == param.UserId);
                if (jobSeeker == null)
                {
                    throw new UserException(ErrorCode.INVALID_SESSION.ToString());
                }

                jobSeeker.AdditionalInfo = param.AdditionalInfo;
                jobSeeker.UpdatedDateUtc = DateTime.UtcNow;
                await context.SaveChangesAsync();
            }
        }
コード例 #24
0
        public async Task ChangePassword(ChangePasswordParams changePasswordParams)
        {
            Utils.CheckNullOrEmpty(new List<string> { "CurrentPassword", "NewPassword" }, changePasswordParams.CurrentPassword, changePasswordParams.NewPassword);


            using (AppDbContext context = new AppDbContext())
            {
                User user = await context.Users.FirstOrDefaultAsync(p => p.Id == changePasswordParams.UserId);
                if (user == null)
                {
                    throw new UserException(ErrorCode.INVALID.ToString());
                }

                if (!UtilsCryptography.VerifyBCryptPassword(changePasswordParams.CurrentPassword, user.Password))
                {
                    throw new UserException(ErrorCode.CURRENT_PASSWORD_INCORRECT.ToString());
                }

                user.Password = UtilsCryptography.GenerateBCryptHash(changePasswordParams.NewPassword);
                await context.SaveChangesAsync();
            }
        }
コード例 #25
0
        //job seeker profile
        public async Task UpdateJobSeekerProfile(JobSeekerProfileUpdatedPersonalInfoParams param)
        {
            Utils.CheckNullOrEmpty(new List<string> { "DateOfBirth", "Email", "FullName", "Gender", "NRICNumber", "NRICType", "NationalServiceStatus", "UserId", "PostalCode", "PhoneNumber" }, param.DateOfBirth, param.Email, param.FullName, param.Gender, param.NRICNumber, param.NRICType, param.NationalServiceStatus, param.UserId, param.PostalCode, param.PhoneNumber);

            using (AppDbContext context = new AppDbContext())
            {
                User user = await context.Users.FirstOrDefaultAsync(p => p.Id == param.UserId);
                JobSeeker jobSeeker = await context.JobSeekers.FirstOrDefaultAsync(p => p.UserId == param.UserId);

                if (jobSeeker == null || user == null)
                {
                    throw new UserException(ErrorCode.INVALID_SESSION.ToString());
                }

                user.Email = param.Email;
                jobSeeker.FullName = param.FullName;
                jobSeeker.Gender = param.Gender;
                jobSeeker.NationalServiceStatus = param.NationalServiceStatus;
                jobSeeker.DateOfBirth = param.DateOfBirth;
                jobSeeker.NRICNumber = param.NRICNumber;
                jobSeeker.NRICType = param.NRICType;
                jobSeeker.Race = param.Race;
                jobSeeker.Religions = param.Religions;
                jobSeeker.PhoneNumber = param.PhoneNumber;
                jobSeeker.MobileNumber = param.MobileNumber;
                jobSeeker.PostalCode = param.PostalCode;
                jobSeeker.Address = param.Address;
                jobSeeker.UpdatedDateUtc = DateTime.UtcNow;

                await context.SaveChangesAsync();
            }
        }
コード例 #26
0
        public async Task ResetPassword(ResetPasswordParams resetPasswordParams)
        {
            Utils.CheckNullOrEmpty(new List<string> { "ConfirmationCode", "Password" }, resetPasswordParams.ConfirmationCode, resetPasswordParams.Password);
            using (AppDbContext context = new AppDbContext())
            {
                User user = await context.Users.FirstOrDefaultAsync(p => p.ConfirmationCode == resetPasswordParams.ConfirmationCode);
                if (user == null)
                {
                    throw new UserException(ErrorCode.INVALID.ToString());
                }

                user.ConfirmationCode = null;
                user.Password = UtilsCryptography.GenerateBCryptHash(resetPasswordParams.Password);
                await context.SaveChangesAsync();
            }
        }
コード例 #27
0
        public async Task ForgotPassword(string email)
        {
            Utils.CheckNullOrEmpty(new List<string> { "Email" }, email);

            using (AppDbContext context = new AppDbContext())
            {
                User user = await context.Users.FirstOrDefaultAsync(p => p.Email == email);
                if (user == null)
                {
                    throw new UserException(ErrorCode.EMAIL_INVALID.ToString());
                }

                user.ConfirmationCode = Guid.NewGuid().ToString();
                await context.SaveChangesAsync();
                await EmailDelivery.SendForgotPasswordRequest(email, user.ConfirmationCode);
            }
        }
コード例 #28
0
        public async Task<User> RegisterJobseeker(RegisterJobseekerParams registerJobseekerParams)
        {
            Utils.CheckNullOrEmpty(new List<string> { "Email", "Token", "AccountType" }, registerJobseekerParams.Email, registerJobseekerParams.Token, registerJobseekerParams.AccountType);

            if (!Utils.IsEmail(registerJobseekerParams.Email))
            {
                throw new UserException(ErrorCode.EMAIL_INVALID.ToString());
            }

            using (AppDbContext context = new AppDbContext())
            {
                if (await context.Users.AnyAsync(p => p.Email == registerJobseekerParams.Email))
                {
                    throw new UserException(ErrorCode.EMAIL_IN_USED.ToString());
                }

                byte[] imageBytes = null;
                bool activated = true;
                string confirmationCode = string.Empty;
                if (registerJobseekerParams.AccountType == AccountType.Email)
                {
                    activated = false;
                    confirmationCode = Guid.NewGuid().ToString();
                    registerJobseekerParams.Token = UtilsCryptography.GenerateBCryptHash(registerJobseekerParams.Token);

                }
                else if (registerJobseekerParams.AccountType == AccountType.Facebook)
                {
                    try
                    {
                        FacebookClient facebookClient = new FacebookClient(registerJobseekerParams.Token);
                        await facebookClient.GetTaskAsync("me?fields=id");

                        WebClient webClient = new WebClient();
                        imageBytes = webClient.DownloadData(registerJobseekerParams.AvatarPath);
                        registerJobseekerParams.Token = null;
                    }
                    catch (Exception)
                    {
                        throw new UserException(ErrorCode.FACEBOOK_INVALID.ToString());
                    }

                }
                else
                {
                    try
                    {
                        string query = "https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + registerJobseekerParams.Token;
                        HttpClient client = new HttpClient();
                        await client.GetStringAsync(query);

                        WebClient webClient = new WebClient();
                        imageBytes = webClient.DownloadData(registerJobseekerParams.AvatarPath);
                        registerJobseekerParams.Token = null;
                    }
                    catch (Exception)
                    {
                        throw new UserException(ErrorCode.GOOGLE_INVALID.ToString());
                    }
                }

                User user = new User
                {
                    Id = Guid.NewGuid(),
                    Email = registerJobseekerParams.Email,
                    Password = registerJobseekerParams.Token,
                    AccountType = registerJobseekerParams.AccountType,
                    UserType = UserType.JobSeeker,
                    RegisteredDateUtc = DateTime.UtcNow,
                    IsActivated = activated,
                    ConfirmationCode = confirmationCode
                };
                context.Users.Add(user);

                Language defaultLanguage = await context.Languages.FirstOrDefaultAsync(p => p.Name == "English - United States");


                if (registerJobseekerParams.AccountType != AccountType.Email)
                {
                    registerJobseekerParams.DayOfBirthUtc = new DateTime(2000, 1, 1);
                    registerJobseekerParams.NRICType = NRICType.Citizen;
                }

                JobSeeker jobSeeker = new JobSeeker
                {
                    UserId = user.Id,
                    Avartar = imageBytes,
                    FullName = registerJobseekerParams.FullName,
                    Gender = Gender.Male,
                    NRICNumber = registerJobseekerParams.NRICNumber,
                    DateOfBirth = registerJobseekerParams.DayOfBirthUtc,
                    NRICType = registerJobseekerParams.NRICType,
                    ExperienceYear = ExperienceYear.Student,
                    LanguageId = defaultLanguage.Id,
                    CanNegotiation = true,
                    CreatedDateUtc = DateTime.UtcNow,
                    UpdatedDateUtc = DateTime.UtcNow
                };
                context.JobSeekers.Add(jobSeeker);

                await context.SaveChangesAsync();

                if (user.IsActivated)
                {
                    await EmailDelivery.SendJobSeekerRegisterCompleted(registerJobseekerParams.Email);
                }
                else
                {
                    await EmailDelivery.SendJobSeekerRegisterActivation(registerJobseekerParams.Email, confirmationCode);
                    return null;
                }

                return user;
            }
        }
コード例 #29
0
        public async Task<User> ActiveJobSeekerAccount(string code)
        {
            Utils.CheckNullOrEmpty(new List<string> { "Activation Code" }, code);

            using (AppDbContext context = new AppDbContext())
            {
                User user = await context.Users.FirstOrDefaultAsync(p => p.ConfirmationCode == code &&
                                                                         p.IsActivated == false);

                if (user == null)
                {
                    throw new UserException(ErrorCode.INVALID.ToString());
                }

                user.IsActivated = true;
                user.ConfirmationCode = null;
                await context.SaveChangesAsync();

                return user;
            }
        }
コード例 #30
0
        public async Task<bool> RegisterEmployer(RegisterEmployerParam registerEmployerParam)
        {
            if (!Utils.IsEmail(registerEmployerParam.Email))
            {
                throw new UserException(ErrorCode.EMAIL_INVALID.ToString());
            }

            using (AppDbContext context = new AppDbContext())
            {
                if (await context.Users.AnyAsync(p => p.Email == registerEmployerParam.Email))
                {
                    throw new UserException(ErrorCode.EMAIL_IN_USED.ToString());
                }

                Random generator = new Random();
                string password = generator.Next(100000, 999999).ToString();

                User user = new User
                {
                    Id = Guid.NewGuid(),
                    Email = registerEmployerParam.Email,
                    Password = UtilsCryptography.GenerateBCryptHash(password),
                    AccountType = AccountType.Email,
                    UserType = UserType.Employer,
                    RegisteredDateUtc = DateTime.UtcNow,
                    IsActivated = true,
                    ConfirmationCode = ""
                };
                context.Users.Add(user);

                Employer employer = new Employer
                {
                    CompanyName = registerEmployerParam.CompanyName,
                    CompanyRegistrationNumber = registerEmployerParam.CompanyRegistrationNumber,
                    ContactName = registerEmployerParam.ContactName,
                    PhoneNumber = registerEmployerParam.ContactNumber,
                    NatureOfBusiness = registerEmployerParam.NaturalOfBusiness,
                    OverView = registerEmployerParam.Message,
                    CreatedDateUtc = DateTime.UtcNow,
                    UpdatedDateUtc = DateTime.UtcNow,
                    UserId = user.Id,
                };
                context.Employers.Add(employer);

                await context.SaveChangesAsync();
                await EmailDelivery.SendEmployerRegisterCompleted(registerEmployerParam.Email, password);

                return true;
            }
        }