Ejemplo n.º 1
0
        public ActionResult Ajax_DeleteCoupon([DataSourceRequest] DataSourceRequest request, Coupon coupon)
        {
            ServiceResult result = _service.RemoveCoupon(coupon.DiscountItemId);

            if (!result.Success)
                Utilities.AddModelStateErrors(this.ModelState, result.GetServiceErrors());

            return Json(ModelState.ToDataSourceResult());
        }
Ejemplo n.º 2
0
        public ActionResult Ajax_UpdateCoupon([DataSourceRequest] DataSourceRequest request, Coupon coupon, int? masterEventId)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(coupon.Code))
                    coupon.Code = _service.GenerateDiscountCode();

                coupon.EventId = masterEventId;

                ServiceResult result = _service.UpdateCoupon(coupon);

                if (!result.Success)
                    Utilities.AddModelStateErrors(this.ModelState, result.GetServiceErrors());
            }

            return Json(ModelState.ToDataSourceResult());
        }
Ejemplo n.º 3
0
        public ServiceResult CreateCoupon(Coupon coupon)
        {
            var result = new ServiceResult();
            try
            {

                if (ValidateCoupon(coupon, result))
                {
                    _repository.Coupons.Create(coupon);

                    if (!_sharedRepository)
                        _repository.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                result.AddServiceError(Utilities.GetInnerMostException(ex));
            }
            return result;
        }
Ejemplo n.º 4
0
        private bool NeedToRemoveProcessingFee(SessionCart currentCart, Coupon coupon)
        {
            if (!NeedToRemoveProcessingFee(currentCart))            // check base method
                return false;

            if (coupon.CouponType != CouponType.Registration)       // only if a registration coupon
                return false;

            if (coupon.DiscountType == DiscountType.Dollars)        //  remove for all dollar amounts
                return true;

            if (coupon.DiscountType == DiscountType.Percentage && coupon.Value >= 75) // only 75% disocunt or greater
                return true;

            return false;
        }
Ejemplo n.º 5
0
        protected bool ValidateCoupon(Coupon couponToValidate, ServiceResult serviceResult)
        {
            if (couponToValidate.EndDateTime < couponToValidate.StartDateTime)
                serviceResult.AddServiceError("EndDateTime", "The effective end date must be after the effective start date.");

            if (couponToValidate.Value <= 0)
                serviceResult.AddServiceError("Value", "Value must be positive.");

            if (couponToValidate.MaxRegistrantCount <= 0)
                serviceResult.AddServiceError("MaxRegistrantCount", "Max registrant count must be positive or empty");

            if (_repository.DiscountItems.Filter(x => x.DiscountItemId != couponToValidate.DiscountItemId && x.Code.ToUpper() == couponToValidate.Code.ToUpper()).Any())
                serviceResult.AddServiceError("Code", "The code you entered is already in use by another discount.");

            // does not need to be associated with an event null == all events
            //if (couponToValidate.CouponType == CouponType.Registration && !couponToValidate.EventId.HasValue)
            //    serviceResult.AddServiceError("EventId", "Registration coupons must be associated to an event.");

            return serviceResult.Success;
        }
Ejemplo n.º 6
0
 protected bool CanRemoveCoupon(Coupon couponToRemove, ServiceResult serviceResult)
 {
     return serviceResult.Success;
 }
Ejemplo n.º 7
0
        public ServiceResult UpdateCoupon(Coupon coupon)
        {
            ServiceResult result = new ServiceResult();

            try
            {
                if (ValidateCoupon(coupon, result))
                {
                    Coupon updateCoupon = _repository.Coupons.Find(x => x.DiscountItemId == coupon.DiscountItemId);

                    updateCoupon.Code = coupon.Code;
                    updateCoupon.CouponType = coupon.CouponType;
                    updateCoupon.DiscountType = coupon.DiscountType;
                    updateCoupon.Description = coupon.Description;
                    updateCoupon.EndDateTime = coupon.EndDateTime;
                    updateCoupon.IsActive = coupon.IsActive;
                    updateCoupon.IsReusable = coupon.IsReusable;
                    updateCoupon.MaxRegistrantCount = coupon.MaxRegistrantCount;
                    updateCoupon.StartDateTime = coupon.StartDateTime;
                    updateCoupon.EventId = coupon.EventId;
                    updateCoupon.Value = coupon.Value;

                    if (!_sharedRepository)
                        _repository.SaveChanges();

                }
            }
            catch (Exception ex)
            {
                result.AddServiceError(Utilities.GetInnerMostException(ex));
            }

            return result;
        }