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);
        }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
 public void Delete(Discount discount)
 {
     _session.Transact(session => session.Delete(discount));
 }
Exemplo n.º 6
0
 public void Update(Discount discount)
 {
     _session.Transact(session => session.Update(discount));
 }
Exemplo n.º 7
0
 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();
 }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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);}
                });
        }
Exemplo n.º 12
0
 public DiscountInfo(Discount discount, CheckLimitationsResult checkLimitationsResult)
 {
     _discount = discount;
     _checkLimitationsResult = checkLimitationsResult;
 }