Example #1
0
        private JobAd CreateJobAd(IEmployer employer, AnonymousUser anonymousUser, JobAdModel jobAdModel, HttpPostedFileBase logo, Guid?logoId)
        {
            CreateLogo(jobAdModel, logo, logoId);

            // Prepare it first.

            jobAdModel.Prepare();

            // Update a new instance.

            var jobAd = new JobAd();

            UpdateJobAd(jobAd, jobAdModel);

            // Create the job ad.

            if (employer != null)
            {
                _employerJobAdsCommand.CreateJobAd(employer, jobAd);
            }
            else
            {
                _anonymousJobAdsCommand.CreateJobAd(anonymousUser, jobAd);
            }

            return(jobAd);
        }
Example #2
0
 private EditJobAdModel GetEditJobAdModel(bool isNew, JobAdModel jobAdModel)
 {
     return(new EditJobAdModel
     {
         IsNew = isNew,
         JobAd = jobAdModel,
         Reference = new JobAdReferenceModel
         {
             DefaultCountry = ActivityContext.Location.Country,
             Countries = _locationQuery.GetCountries(),
             Industries = _industriesQuery.GetIndustries(),
         }
     });
 }
Example #3
0
        public ActionResult SaveJobAd(Guid?jobAdId, JobAdModel jobAdModel, HttpPostedFileBase logo, Guid?logoId)
        {
            var isNew = jobAdId == null;

            try
            {
                var employer      = CurrentEmployer;
                var anonymousUser = CurrentAnonymousUser;

                string message;

                if (jobAdId == null)
                {
                    // Creating a new job ad.

                    jobAdId = CreateJobAd(employer, anonymousUser, jobAdModel, logo, logoId).Id;
                    message = "The job ad has been saved as a draft.";
                }
                else
                {
                    // Saving an existing job ad.

                    var jobAd = GetJobAd(employer.Id, jobAdId.Value);
                    if (jobAd == null)
                    {
                        return(NotFound("job ad", "id", jobAdId.Value));
                    }

                    // Update the the job ad.

                    UpdateJobAd(employer, anonymousUser, jobAd, jobAdModel, logo, logoId);
                    message = "The job ad has been saved.";
                }

                // Then go back to the job ad.

                return(RedirectToRouteWithConfirmation(JobAdsRoutes.JobAd, new { jobAdId }, message));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(View(GetEditJobAdModel(isNew, jobAdModel)));
        }
Example #4
0
        public ActionResult PreviewJobAd(Guid?jobAdId, JobAdModel jobAdModel, HttpPostedFileBase logo, Guid?logoId)
        {
            var isNew = jobAdId == null;

            try
            {
                var employer      = CurrentEmployer;
                var anonymousUser = CurrentAnonymousUser;

                if (jobAdId == null)
                {
                    // Creating a new job ad.

                    jobAdId = CreateJobAd(employer, anonymousUser, jobAdModel, logo, logoId).Id;
                }
                else
                {
                    // Editing an existing job ad.

                    var jobAd = GetJobAd(employer != null ? employer.Id : anonymousUser.Id, jobAdId.Value);
                    if (jobAd == null)
                    {
                        return(NotFound("job ad", "id", jobAdId.Value));
                    }

                    // Update the the job ad.

                    UpdateJobAd(employer, anonymousUser, jobAd, jobAdModel, logo, logoId);
                }

                // Preview it.

                return(RedirectToRoute(JobAdsRoutes.Preview, new { jobAdId }));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(View(GetEditJobAdModel(isNew, jobAdModel)));
        }
Example #5
0
        private void CreateLogo(JobAdModel jobAdModel, HttpPostedFileBase logo, Guid?logoId)
        {
            jobAdModel.Logo = new LogoModel();
            if (logo == null && logoId == null)
            {
                return;
            }

            if (logo == null)
            {
                // File already uploaded.

                jobAdModel.Logo.FileReferenceId = logoId;
                return;
            }

            // Uploading a new file.

            var fileName      = Path.GetFileName(logo.FileName);
            var fileReference = _employerLogosCommand.SaveLogo(new HttpPostedFileContents(logo), fileName);

            jobAdModel.Logo.FileReferenceId = fileReference.Id;
        }
Example #6
0
        private void UpdateJobAd(JobAd jobAd, JobAdModel jobAdModel)
        {
            // Validate it first after updating the content.

            jobAdModel.Summary = HtmlUtil.TextToHtml(jobAdModel.Summary);
            jobAdModel.Content = HtmlUtil.TextToHtml(jobAdModel.Content);

            IList <ValidationError> errors = new List <ValidationError>();

            try
            {
                jobAdModel.Validate();
            }
            catch (ValidationErrorsException ex)
            {
                // If there are errors then need to put things back the way they were.

                jobAdModel.Summary = HtmlUtil.HtmlToText(jobAdModel.Summary);
                jobAdModel.Content = HtmlUtil.HtmlToText(jobAdModel.Content);

                errors = ex.Errors.ToList();
            }

            // Need to explicitly check these.

            if (jobAdModel.ContactDetails == null || string.IsNullOrEmpty(jobAdModel.ContactDetails.EmailAddress))
            {
                errors.Add(new RequiredValidationError("email address"));
            }

            if (jobAdModel.ContactDetails != null && !string.IsNullOrEmpty(jobAdModel.ContactDetails.PhoneNumber))
            {
                IValidator validator = new PhoneNumberValidator();
                if (!validator.IsValid(jobAdModel.ContactDetails.PhoneNumber))
                {
                    errors = errors.Concat(validator.GetValidationErrors("PhoneNumber")).ToList();
                }
            }

            if (jobAdModel.ContactDetails != null && !string.IsNullOrEmpty(jobAdModel.ContactDetails.FaxNumber))
            {
                IValidator validator = new PhoneNumberValidator();
                if (!validator.IsValid(jobAdModel.ContactDetails.FaxNumber))
                {
                    errors = errors.Concat(validator.GetValidationErrors("FaxNumber")).ToList();
                }
            }

            if (jobAdModel.IndustryIds.IsNullOrEmpty())
            {
                errors.Add(new RequiredValidationError("industry"));
            }

            if (jobAdModel.JobTypes == JobTypes.None)
            {
                errors.Add(new RequiredValidationError("job type"));
            }

            if (jobAdModel.Location == null || string.IsNullOrEmpty(jobAdModel.Location.ToString()))
            {
                errors.Add(new RequiredValidationError("location"));
            }

            const JobAdFeaturePack featurePack = JobAdFeaturePack.BaseFeaturePack;
            var features          = _employerOrdersQuery.GetJobAdFeatures(featurePack);
            var defaultExpiryTime = _jobAdsCommand.GetDefaultExpiryTime(features);

            if (jobAdModel.ExpiryTime != null)
            {
                if (jobAdModel.ExpiryTime.Value > defaultExpiryTime)
                {
                    errors.Add(new JobAdExpiryValidationError("ExpiryTime", (defaultExpiryTime - DateTime.Now).Days + 1));
                }
            }

            if (errors.Count > 0)
            {
                throw new ValidationErrorsException(errors);
            }

            // Assign.

            jobAd.Title          = jobAdModel.Title;
            jobAd.ContactDetails = jobAdModel.ContactDetails;
            jobAd.Features       = features;
            jobAd.FeatureBoost   = _employerOrdersQuery.GetJobAdFeatureBoost(featurePack);

            // If the date has not been changed from the default then let it remain the default.

            jobAd.ExpiryTime = jobAd.ExpiryTime == null && jobAdModel.ExpiryTime != null && jobAdModel.ExpiryTime.Value.Date == defaultExpiryTime.Date
                ? null
                : jobAdModel.ExpiryTime;

            jobAd.Visibility.HideCompany        = jobAdModel.HideCompany;
            jobAd.Visibility.HideContactDetails = jobAdModel.HideContactDetails;

            jobAd.Integration.ExternalReferenceId = jobAdModel.ExternalReferenceId;

            jobAd.LogoId = jobAdModel.Logo == null ? null : jobAdModel.Logo.FileReferenceId;

            jobAd.Description.Content           = jobAdModel.Content;
            jobAd.Description.CompanyName       = jobAdModel.CompanyName;
            jobAd.Description.PositionTitle     = jobAdModel.PositionTitle;
            jobAd.Description.ResidencyRequired = jobAdModel.ResidencyRequired;
            jobAd.Description.JobTypes          = jobAdModel.JobTypes;
            jobAd.Description.Industries        = jobAdModel.IndustryIds == null
                ? new List <Industry>()
                : (from i in jobAdModel.IndustryIds select _industriesQuery.GetIndustry(i)).ToList();
            jobAd.Description.Summary      = jobAdModel.Summary;
            jobAd.Description.Salary       = jobAdModel.Salary;
            jobAd.Description.Package      = jobAdModel.Package;
            jobAd.Description.BulletPoints = jobAdModel.BulletPoints;
            jobAd.Description.Location     = jobAdModel.Location;
        }
Example #7
0
        private void UpdateJobAd(IEmployer employer, AnonymousUser anonymousUser, JobAd jobAd, JobAdModel jobAdModel, HttpPostedFileBase logo, Guid?logoId)
        {
            // Update the job ad.

            CreateLogo(jobAdModel, logo, logoId);
            UpdateJobAd(jobAd, jobAdModel);

            // Save it.

            if (employer != null)
            {
                _employerJobAdsCommand.UpdateJobAd(employer, jobAd);
            }
            else
            {
                _anonymousJobAdsCommand.UpdateJobAd(anonymousUser, jobAd);
            }
        }