public CheckLimitationsResult CheckLimitations(Discount discount, CartModel cart)
        {
            var limitations = _session.QueryOver<DiscountLimitation>()
                .Where(limitation => limitation.Discount.Id == discount.Id)
                .Cacheable()
                .List();

            var results = new CheckLimitationsResult[limitations.Count];
            for (var i = 0; i < limitations.Count; i++)
            {
                var limitation = limitations[i];
                var fullName = limitation.GetType().FullName;
                if (LimitationCheckerTypes.ContainsKey(fullName))
                {
                    var checker = _kernel.Get(LimitationCheckerTypes[fullName]) as DiscountLimitationChecker;
                    if (checker != null)
                    {
                        results[i] = checker.CheckLimitations(limitation, cart);
                        continue;
                    }
                }
                results[i] = CheckLimitationsResult.CurrentlyInvalid("Limitation cannot be checked");
            }
            return CheckLimitationsResult.Combine(results);
        }
 public IList<DiscountUsage> GetUsages(Discount discount)
 {
     return _session.QueryOver<DiscountUsage>()
         .Where(usage => usage.Discount.Id == discount.Id)
         .Fetch(usage => usage.Order).Eager
         .OrderBy(x => x.CreatedOn).Desc
         .Cacheable().List();
 }
 public IList<DiscountLimitation> GetLimitations(Discount discount)
 {
     return
         _session.QueryOver<DiscountLimitation>()
             .Where(limitation => limitation.Discount.Id == discount.Id)
             .Cacheable()
             .List();
 }
Beispiel #4
0
        public void Save(Discount discount)
        {
            //Discount oldDiscount = Get(discount.Id);
            //DiscountLimitation oldDiscountLimitation = oldDiscount.Limitation;
            //if (discountLimitation != null && oldDiscountLimitation != null)
            //{
            //    if (oldDiscount.Limitation.GetType() != discountLimitation.GetType())
            //    {
            //        DeleteOldLimitationOrApplication(oldDiscount, oldDiscountLimitation);
            //        oldDiscount.Limitation = discountLimitation;
            //    }
            //    else
            //    {
            //        oldDiscount.Limitation.CopyValues(discountLimitation);
            //    };
            //}
            //else if (discountLimitation == null && oldDiscountLimitation != null)
            //{
            //    DeleteOldLimitationOrApplication(oldDiscount, oldDiscountLimitation);
            //    oldDiscount.Limitation = discountLimitation;
            //}
            //else
            //{
            //    oldDiscount.Limitation = discountLimitation;
            //}

            //DiscountApplication oldDiscountApplication = oldDiscount.Application;
            //if (discountApplication != null && oldDiscountApplication != null)
            //{
            //    if (oldDiscount.Application.GetType() != discountApplication.GetType())
            //    {
            //        DeleteOldLimitationOrApplication(oldDiscount, oldDiscountApplication);
            //        oldDiscount.Application = discountApplication;
            //    }
            //    else
            //    {
            //        oldDiscount.Application.CopyValues(discountApplication);
            //    };
            //}
            //else if (discountApplication == null && oldDiscountApplication != null)
            //{
            //    DeleteOldLimitationOrApplication(oldDiscount, oldDiscountApplication);
            //    oldDiscount.Application = discountApplication;
            //}
            //else
            //{
            //    oldDiscount.Application = discountApplication;
            //}

            _session.Transact(session => session.SaveOrUpdate(discount));
        }
 public void Delete(Discount discount)
 {
     _session.Transact(session => session.Delete(discount));
 }
 public void Update(Discount discount)
 {
     _session.Transact(session => session.Update(discount));
 }
 public void Add(Discount discount)
 {
     _session.Transact(session => session.Save(discount));
 }
 public IList<DiscountApplication> GetApplications(Discount discount)
 {
     return
         _session.QueryOver<DiscountApplication>().Where(application => application.Discount.Id == discount.Id)
             .Cacheable().List();
 }
Beispiel #9
0
        public DiscountLimitation GetLimitation(Discount discount, string limitationType)
        {
            if (string.IsNullOrWhiteSpace(limitationType))
                return null;

            var limitation =
                TypeHelper.GetAllConcreteMappedClassesAssignableFrom<DiscountLimitation>()
                          .FirstOrDefault(type => type.FullName == limitationType);

            return null;
            //discount.Limitation != null && discount.Limitation.GetType() == limitation
            //       ? discount.Limitation
            //       : Activator.CreateInstance(limitation) as DiscountLimitation;
        }
Beispiel #10
0
        public DiscountApplication GetApplication(Discount discount, string applicationType)
        {
            var application =
                TypeHelper.GetAllConcreteMappedClassesAssignableFrom<DiscountApplication>()
                          .FirstOrDefault(type => type.FullName == applicationType);

            return null;
            //return discount.Application != null && discount.Application.GetType() == application
            //           ? discount.Application
            //           : Activator.CreateInstance(application) as DiscountApplication;
        }
Beispiel #11
0
        //private void DeleteOldLimitationOrApplication(Discount oldDiscount, object oldLimitationOrApplication)
        //{
        //    oldDiscount.Limitation = null;
        //    _session.Transact(session => session.SaveOrUpdate(oldDiscount));
        //    _session.Transact(session => session.Delete(oldLimitationOrApplication));
        //}

        public void Delete(Discount discount)
        {
            _session.Transact(session =>
                {
                    session.Delete(discount);
                    foreach (var limitation in discount.Limitations)
                    {
                        session.Delete(limitation);
                    }
                    foreach (var application in discount.Applications)
                    {session.Delete(application);}
                });
        }
Beispiel #12
0
 public DiscountInfo(Discount discount, CheckLimitationsResult checkLimitationsResult)
 {
     _discount = discount;
     _checkLimitationsResult = checkLimitationsResult;
 }