public async Task <bool> UpdateAsync(JobSeekerServiceModel model)
        {
            if (!this.IsEntityStateValid(model))
            {
                return(false);
            }

            var jobSeeker = await this.jobSeekersRepository.All().SingleOrDefaultAsync(c => c.Id == model.Id);

            if (jobSeeker == null)
            {
                return(false);
            }

            jobSeeker.FirstName         = model.FirstName;
            jobSeeker.LastName          = model.LastName;
            jobSeeker.DateOfBirth       = model.DateOfBirth;
            jobSeeker.Qualification     = model.Qualification;
            jobSeeker.Gender            = model.Gender;
            jobSeeker.IndustryExpertise = model.IndustryExpertise;

            this.jobSeekersRepository.Update(jobSeeker);
            await this.jobSeekersRepository.SaveChangesAsync();

            return(true);
        }
        public async Task <bool> CreateAsync(JobSeekerServiceModel model)
        {
            if (!IsEntityStateValid(model))
            {
                return(false);
            }

            if (model.User == null)
            {
                return(false);
            }

            var user = usersRepository.All().FirstOrDefault(u => u.UserName == model.User.UserName);

            if (user == null)
            {
                return(false);
            }

            var jobSeeker = Mapper.Map <JobSeeker>(model);

            jobSeeker.User = user;

            await this.jobSeekersRepository.AddAsync(jobSeeker);

            await this.jobSeekersRepository.SaveChangesAsync();

            return(true);
        }
Beispiel #3
0
        public async Task CreateAsync_WithInvalidModel_ReturnsFalse()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var user = new User
            {
                UserName = "******"
            };

            await context.Users.AddAsync(user);

            context.SaveChanges();

            var serviceModel = new JobSeekerServiceModel
            {
                User = new UserServiceModel
                {
                    UserName = user.UserName
                }
            };

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var result = await jobSeekerService.CreateAsync(serviceModel);

            Assert.False(result);

            var dbModel = await context.JobSeekers.AnyAsync();

            Assert.False(dbModel);
        }
Beispiel #4
0
        public async Task UpdateAsync_WithNonExistentJobSeeker_ReturnsFalse()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new JobSeeker
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName",
                User      = new User
                {
                    UserName = "******"
                }
            };

            var serviceModel = new JobSeekerServiceModel
            {
                Id = model.Id
            };

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var result = await jobSeekerService.UpdateAsync(serviceModel);

            Assert.False(result);
        }
        public async Task <IActionResult> RegisterJobSeeker(RegisterJobSeeker model)
        {
            if (ModelState.IsValid)
            {
                var user = new User {
                    UserName = model.Username, Email = model.Email, PictureUrl = GlobalConstants.JobSeekerDefaulthAvatarUri
                };
                var result = await userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var newJobSeeker = new JobSeekerServiceModel()
                    {
                        FirstName = model.FirstName, LastName = model.LastName
                    };
                    newJobSeeker.User = new UserServiceModel()
                    {
                        UserName = user.UserName
                    };

                    var addedResult = await jobSeekerService.CreateAsync(newJobSeeker);

                    if (!addedResult)
                    {
                        return(NotFound());
                    }

                    var role = await userManager.AddToRoleAsync(user, GlobalConstants.JobSeeker);

                    var code = await userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);

                    var viewResult = await GetConfirmationTemplate(user, callbackUrl, "ConfirmEmailTemplate");

                    await emailSender.SendEmailAsync(model.Email, "Please verify your email", viewResult);

                    await signInManager.SignInAsync(user, isPersistent : false);

                    this.Success(NotificationMessages.VerificationEmailSent);

                    return(LocalRedirect("/"));
                }

                AddErrors(result);
            }

            return(View(model));
        }
Beispiel #6
0
        public async Task UpdateAsync_WithValidModel_WorksCorrectly()
        {
            const string expectedResult = "TestName12345";

            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var model = new JobSeeker
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName",
                User      = new User
                {
                    UserName = "******"
                }
            };

            await context.JobSeekers.AddAsync(model);

            context.SaveChanges();

            var companyService = new CompanyService(new EfRepository <User>(context),
                                                    new EfRepository <Company>(context));

            var serviceModel = new JobSeekerServiceModel
            {
                Id        = model.Id,
                FirstName = expectedResult,
                LastName  = expectedResult
            };

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var result = await jobSeekerService.UpdateAsync(serviceModel);

            Assert.True(result);

            var actualResultFirstName = (await context.JobSeekers.SingleAsync(j => j.Id == model.Id)).FirstName;
            var actualResultLastName  = (await context.JobSeekers.SingleAsync(j => j.Id == model.Id)).LastName;

            Assert.Equal(expectedResult, actualResultFirstName);
            Assert.Equal(expectedResult, actualResultLastName);
        }
Beispiel #7
0
        public async Task CreateAsync_WithValidModel_WorksCorrectly()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var user = new User
            {
                UserName = "******"
            };

            await context.Users.AddAsync(user);

            context.SaveChanges();

            var serviceModel = new JobSeekerServiceModel
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName",
                User      = new UserServiceModel
                {
                    UserName = user.UserName
                }
            };

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var result = await jobSeekerService.CreateAsync(serviceModel);

            Assert.True(result);

            var dbModel = context.JobSeekers.SingleOrDefault();

            Assert.NotNull(dbModel);

            Assert.Equal(user.Id, dbModel.UserId);
        }
Beispiel #8
0
        public async Task CreateAsync_WithNonExistentUser_ReturnsFalse()
        {
            var context = new JobFinderDbContext(new DbContextOptionsBuilder <JobFinderDbContext>()
                                                 .UseInMemoryDatabase(Guid.NewGuid().ToString())
                                                 .Options);

            var serviceModel = new JobSeekerServiceModel
            {
                FirstName = "TestFirstName",
                LastName  = "TestLastName"
            };

            var jobSeekerService = new JobSeekerService(new EfRepository <User>(context),
                                                        new EfRepository <JobSeeker>(context));

            var result = await jobSeekerService.CreateAsync(serviceModel);

            Assert.False(result);

            var dbModel = await context.JobSeekers.AnyAsync();

            Assert.False(dbModel);
        }