Esempio n. 1
0
        public async Task IfLogoIsInvalidCreateProfileReturnsNull()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();

            var repository       = new EfDeletableEntityRepository <Employer>(context);
            var cloudinary       = new Cloudinary(new Account(CloudinaryConfig.CloudName, CloudinaryConfig.ApiKey, CloudinaryConfig.ApiSecret));
            var employersService = this.GetMockedService(repository, cloudinary);

            var logo  = this.PrepareInvalidImage();
            var model = new CreateEmployerProfileInputModel
            {
                ApplicationUserId = "1",
                Name = "Recruit Me",
                ContactPersonNames       = "Ivan Ivanov",
                ContactPersonEmail       = "*****@*****.**",
                JobSectorId              = 4,
                UniqueIdentificationCode = "204558718",
                Logo = logo,
            };

            var employerId = await employersService.CreateProfileAsync(model);

            Assert.Null(employerId);
        }
        public async Task <string> CreateProfileAsync(CreateEmployerProfileInputModel model)
        {
            var employer = AutoMapperConfig.MapperInstance.Map <Employer>(model);

            if (model.Logo != null)
            {
                var logoUrl = await CloudinaryService.UploadImageAsync(this.cloudinary, model.Logo, model.ApplicationUserId + LogoNameAddIn);

                if (logoUrl == null)
                {
                    return(null);
                }

                employer.LogoUrl = logoUrl;
            }

            employer.CreatedOn = DateTime.UtcNow;
            try
            {
                await this.employersRepository.AddAsync(employer);

                await this.employersRepository.SaveChangesAsync();

                return(employer.Id);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 3
0
        public IActionResult CreateProfile()
        {
            var employerId = this.employersService.GetEmployerIdByUsername(this.User.Identity.Name);

            if (employerId != null)
            {
                return(this.RedirectToAction(nameof(this.UpdateProfile)));
            }

            var model = new CreateEmployerProfileInputModel
            {
                ImageExtensions = this.fileExtensionsService.GetImageExtensions(),
                JobSectors      = this.jobSectors,
            };

            return(this.View(model));
        }
Esempio n. 4
0
        public async Task <IActionResult> CreateProfile(CreateEmployerProfileInputModel input)
        {
            if (this.employersService.GetEmployerIdByUsername(this.User.Identity.Name) != null)
            {
                return(this.RedirectToAction(nameof(this.UpdateProfile)));
            }

            if (!this.ModelState.IsValid)
            {
                input.ImageExtensions = this.fileExtensionsService.GetImageExtensions();
                input.JobSectors      = this.jobSectors;
                return(this.View(input));
            }

            if (input.Logo != null && !this.allowedExtensions.Any(ae => input.Logo.FileName.EndsWith(ae)))
            {
                this.ModelState.AddModelError(string.Empty, GlobalConstants.FileExtensionNotSupported);
                input.ImageExtensions = this.allowedExtensions;
                input.JobSectors      = this.jobSectors;
                return(this.View(input));
            }

            var user = await this.userManager.GetUserAsync(this.User);

            input.ApplicationUserId = user.Id;

            var employerId = await this.employersService.CreateProfileAsync(input);

            if (employerId == null)
            {
                return(this.RedirectToAction("Error", "Home"));
            }

            user.EmployerId = employerId;
            await this.userManager.UpdateAsync(user);

            this.TempData["Success"] = GlobalConstants.ProfileSuccessfullyCreated;
            return(this.RedirectToAction(nameof(this.Index)));
        }
Esempio n. 5
0
        public async Task CreateProfileAsyncSavesInfoCorrectly()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();

            var repository = new EfDeletableEntityRepository <Employer>(context);

            var employersService = this.GetMockedService(repository, null);

            var model = new CreateEmployerProfileInputModel
            {
                ApplicationUserId = "11",
                Address           = "address",
                Name = "Recruit Me",
                ContactPersonNames       = "Ivan Ivanov",
                ContactPersonEmail       = "*****@*****.**",
                JobSectorId              = 4,
                UniqueIdentificationCode = "204558718",
            };

            var employerId = await employersService.CreateProfileAsync(model);

            Assert.NotNull(employerId);

            var record = await context.Employers.Where(c => c.Id == employerId).FirstOrDefaultAsync();

            Assert.Equal(model.Name, record.Name);
            Assert.Equal(model.ApplicationUserId, record.ApplicationUserId);
            Assert.Equal(model.Address, record.Address);
            Assert.Null(record.WebsiteAddress);
            Assert.Null(record.PhoneNumber);
            Assert.Null(record.LogoUrl);
            Assert.Equal(4, record.JobSectorId);
            Assert.NotNull(record.ContactPersonNames);
            Assert.NotNull(record.ContactPersonEmail);
            Assert.NotNull(record.UniqueIdentificationCode);
        }