Esempio n. 1
0
        private void TestUpdateJobAd(bool allocate, int?jobAdCredits, int?applicantCredits)
        {
            var employer = CreateEmployer(allocate, jobAdCredits, applicantCredits);
            var jobAd    = CreateJobAd(employer.Id, 0);

            // Create and open the job ad.

            _employerJobAdsCommand.CreateJobAd(employer, jobAd);
            _employerJobAdsCommand.OpenJobAd(employer, jobAd, false);

            // Check.

            AssertJobAd(jobAd, _employerJobAdsQuery.GetJobAd <JobAd>(employer, jobAd.Id));
            AssertAllocation(jobAdCredits);

            // Update.

            jobAd.Title = string.Format(TitleFormat, 1);
            _employerJobAdsCommand.UpdateJobAd(employer, jobAd);

            // Make sure it is open.

            _employerJobAdsCommand.OpenJobAd(employer, jobAd, false);

            // Check - no extra credit should have been used for the same job ad.

            AssertJobAd(jobAd, _employerJobAdsQuery.GetJobAd <JobAd>(employer, jobAd.Id));
            AssertAllocation(jobAdCredits);
        }
Esempio n. 2
0
        private void UpdateJobAd(IEmployer jobPoster, JobAd jobAd, JobAd existingJobAd, PostReport report)
        {
            try
            {
                report.ProcessedJobAdIds.Add(existingJobAd.Id);

                if (CleanJobAd(jobAd, report))
                {
                    CopyTo(jobAd, existingJobAd);
                    _employerJobAdsCommand.UpdateJobAd(jobPoster, existingJobAd);

                    // Make sure the job is open if needed.

                    if (jobAd.Status == JobAdStatus.Open)
                    {
                        _employerJobAdsCommand.OpenJobAd(jobPoster, existingJobAd, false);
                    }

                    report.Updated++;
                }
            }
            catch (UserException ex)
            {
                AddErrors(ex, report);
                report.Failed++;
            }
        }
Esempio n. 3
0
        public ActionResult PaymentPurchase(Guid jobAdId, JobAdFeaturePack featurePack, Guid?couponId, CreditCard creditCard, CheckBoxValue authoriseCreditCard)
        {
            var employer = CurrentEmployer;

            var jobAd = GetJobAd(employer.Id, jobAdId);

            if (jobAd == null)
            {
                return(NotFound("job ad", "id", jobAdId));
            }

            var product = _employerOrdersQuery.GetJobAdFeaturePackProduct(featurePack);

            if (product == null)
            {
                return(NotFound("feature pack", "featurePack", featurePack));
            }

            var coupon = GetCoupon(couponId);
            var order  = _employerOrdersCommand.PrepareOrder(new[] { product.Id }, coupon, null, GetCreditCardType(creditCard));

            try
            {
                // Validate the coupon first.

                ValidateCoupon(product.Id, couponId, coupon);

                // Check that the terms have been accepted but process the other fields as well.

                if (!authoriseCreditCard.IsChecked)
                {
                    ModelState.AddModelError(new[] { new CreditCardAuthorisationValidationError("authoriseCreditCard") }, new NewOrderErrorHandler());
                }

                // Validate the coupon.

                if (couponId != null && coupon == null)
                {
                    ModelState.AddModelError(new[] { new NotFoundValidationError("coupon", couponId) }, new NewOrderErrorHandler());
                }

                // Validate the credit card.

                creditCard.Validate();

                if (authoriseCreditCard.IsChecked && (couponId == null || coupon != null))
                {
                    // Purchase the order.

                    _employerOrdersCommand.PurchaseOrder(employer.Id, order, CreatePurchaser(employer), creditCard);

                    // Publish the job ad with the appropriate features.

                    jobAd.Features     = _employerOrdersQuery.GetJobAdFeatures(featurePack);
                    jobAd.FeatureBoost = _employerOrdersQuery.GetJobAdFeatureBoost(featurePack);
                    _employerJobAdsCommand.UpdateJobAd(employer, jobAd);

                    return(Publish(employer, jobAd, order.Id));
                }
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new NewOrderErrorHandler());
            }

            // Show the user the errors.

            return(View(new PaymentJobAdModel
            {
                AuthoriseCreditCard = authoriseCreditCard != null && authoriseCreditCard.IsChecked,
                CouponCode = coupon == null ? null : coupon.Code,
                CreditCard = creditCard,
                OrderDetails = _employerOrdersQuery.GetOrderDetails(_creditsQuery, order, _productsQuery.GetProducts()),
                Product = product,
            }));
        }