コード例 #1
0
        public async Task <IActionResult> UpdateProfile(UpdateEmployerProfileViewModel input)
        {
            var employerId = this.employersService.GetEmployerIdByUsername(this.User.Identity.Name);

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

            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 updateResult = await this.employersService.UpdateProfileAsync(employerId, input);

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

            this.TempData["Success"] = GlobalConstants.ProfileSuccessfullyUpdated;
            return(this.RedirectToAction(nameof(this.Index)));
        }
コード例 #2
0
        public async Task <string> UpdateProfileAsync(string employerId, UpdateEmployerProfileViewModel model)
        {
            var employer = this.employersRepository
                           .All()
                           .FirstOrDefault(e => e.Id == employerId);

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

            employer.Address                  = model.Address;
            employer.ContactPersonEmail       = model.ContactPersonEmail;
            employer.ContactPersonNames       = model.ContactPersonNames;
            employer.ContactPersonPhoneNumber = model.ContactPersonPhoneNumber;
            employer.ContactPersonPosition    = model.ContactPersonPosition;
            employer.IsHiringAgency           = model.IsHiringAgency;
            employer.IsPublicSector           = model.IsPublicSector;
            employer.JobSectorId              = model.JobSectorId;
            employer.PhoneNumber              = model.PhoneNumber;
            employer.Name = model.Name;
            employer.UniqueIdentificationCode = model.UniqueIdentificationCode;
            employer.WebsiteAddress           = model.WebsiteAddress;

            if (model.Logo != null)
            {
                if (employer.LogoUrl != null)
                {
                    CloudinaryService.DeleteFile(this.cloudinary, model.ApplicationUserId + LogoNameAddIn);
                }

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

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

                employer.LogoUrl = logoUrl;
            }

            employer.ModifiedOn = DateTime.UtcNow;
            try
            {
                this.employersRepository.Update(employer);
                await this.employersRepository.SaveChangesAsync();

                return(employer.Id);
            }
            catch (Exception)
            {
                return(null);
            }
        }
コード例 #3
0
        public async Task UpdateProfileShouldUpdateProfileWhenValidIdIsPassed()
        {
            AutoMapperInitializer.InitializeMapper();
            var context = InMemoryDbContextInitializer.InitializeContext();
            await context.Employers.AddRangeAsync(this.SeedTestData());

            await context.SaveChangesAsync();

            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.PrepareImage();

            var model = new UpdateEmployerProfileViewModel
            {
                Name = "New Name",
                ContactPersonNames       = "Georgi Georgiev",
                ContactPersonEmail       = "*****@*****.**",
                UniqueIdentificationCode = "0009039460577",
                JobSectorId = 3,
                Logo        = logo,
            };
            var employerId = await employersService.UpdateProfileAsync("First", model);

            Assert.NotNull(employerId);

            var record = await context.Employers.FirstOrDefaultAsync(c => c.Id == "First");

            Assert.Equal(model.Name, record.Name);
            Assert.Equal(model.ContactPersonNames, record.ContactPersonNames);
            Assert.Equal(model.ContactPersonEmail, record.ContactPersonEmail);
            Assert.NotNull(record.LogoUrl);
            Assert.Equal(3, record.JobSectorId);
            Assert.Equal(model.UniqueIdentificationCode, record.UniqueIdentificationCode);
        }