예제 #1
0
 public override bool Delete(params object[] keys)
 {
     try
     {
         this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted);
         var obj = new DiscountTypeBO().Get(this.ConnectionHandler, keys);
         var discountTypeSections = new DiscountTypeSectionBO().Any(this.ConnectionHandler, x => x.DiscountTypeId == obj.Id);
         if (discountTypeSections)
         {
             throw new Exception("این نوع تخیف قابل حذف نیست زیرا در قسمت تخفیفات استفاده شده است");
         }
         var sections = new TempDiscountBO().Any(this.ConnectionHandler, x => x.DiscountTypeId == obj.Id);
         if (sections)
         {
             throw new Exception("این نوع تخیف قابل حذف نیست زیرا در قسمت تخفیفات استفاده شده است");
         }
         if (!new DiscountTypeBO().Delete(this.ConnectionHandler, keys))
         {
             throw new Exception("خطایی در حذف نوع تخفیف وجود دارد");
         }
         var discountTypeAutoCodeBo = new DiscountTypeAutoCodeBO();
         var typeAutoCodes          = discountTypeAutoCodeBo.Where(this.ConnectionHandler,
                                                                   x => x.DiscountTypeId == obj.Id);
         foreach (var discountTypeAutoCode in typeAutoCodes)
         {
             if (!discountTypeAutoCodeBo.Delete(this.ConnectionHandler, discountTypeAutoCode.Id))
             {
                 throw new Exception("خطایی در ذخیره کد تخفیف وجود دارد");
             }
         }
         this.ConnectionHandler.CommitTransaction();
         return(true);
     }
     catch (KnownException knownException)
     {
         this.ConnectionHandler.RollBack();
         Log.Save(knownException.Message, LogType.ApplicationError);
         throw new KnownException(knownException.Message, knownException);
     }
     catch (Exception ex)
     {
         this.ConnectionHandler.RollBack();
         Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
         throw new KnownException(ex.Message, ex);
     }
 }
예제 #2
0
        public List <TempDiscount> GetDiscountTypes(string modualName, byte section, Guid?tempId = null)
        {
            try
            {
                var outlist = new List <TempDiscount>();
                if (tempId.HasValue)
                {
                    var tr = new TempBO().Get(this.ConnectionHandler, tempId);
                    if (tr.TransactionId.HasValue)
                    {
                        return(outlist);
                    }
                }
                var list = new DiscountTypeSectionBO().GetDiscountTypes(this.ConnectionHandler, modualName, section);
                var transactionDiscountBo  = new TempDiscountBO();
                var discountTypeAutoCodeBo = new DiscountTypeAutoCodeBO();
                var discountTypeBo         = new DiscountTypeBO();
                if (!list.Any())
                {
                    return(outlist);
                }
                var enumerable            = list.Select(x => x.Id);
                var discountTypes         = discountTypeBo.Where(ConnectionHandler, x => x.Id.In(enumerable));
                var tempDiscounts         = transactionDiscountBo.Where(ConnectionHandler, x => x.DiscountTypeId.In(enumerable));
                var discountTypeAutoCodes = discountTypeAutoCodeBo.Where(ConnectionHandler, x => x.DiscountTypeId.In(enumerable));

                foreach (var discountType in list)
                {
                    var getdiscountType = discountTypes.FirstOrDefault(x => x.Id == discountType.Id);
                    if (getdiscountType == null)
                    {
                        continue;
                    }
                    if (((!string.IsNullOrEmpty(getdiscountType.EndDate.Trim()) && getdiscountType.EndDate.CompareTo(DateTime.Now.ShamsiDate()) < 0)) ||
                        ((!string.IsNullOrEmpty(getdiscountType.StartDate.Trim()) && getdiscountType.StartDate.CompareTo(DateTime.Now.ShamsiDate()) > 0)) ||
                        string.IsNullOrEmpty(getdiscountType.Title) || !getdiscountType.Enabled)
                    {
                        continue;
                    }
                    TempDiscount tempDiscount;
                    if (tempId.HasValue)
                    {
                        var discount = tempDiscounts.FirstOrDefault(x => x.TempId == tempId && x.DiscountTypeId == discountType.Id);
                        if (discount != null)
                        {
                            tempDiscount       = discount;
                            tempDiscount.Added = true;
                        }
                        else
                        {
                            tempDiscount = new TempDiscount()
                            {
                                DiscountTypeId = discountType.Id
                            }
                        };
                    }
                    else
                    {
                        tempDiscount = new TempDiscount()
                        {
                            DiscountTypeId = discountType.Id
                        }
                    };
                    if (getdiscountType.ForceCode)
                    {
                        if (getdiscountType.IsAutoCode)
                        {
                            var byFilter = discountTypeAutoCodes.Any(x =>
                                                                     x.DiscountTypeId == getdiscountType.Id &&
                                                                     x.Used == false);
                            if (!byFilter)
                            {
                                continue;
                            }
                        }
                        else if (getdiscountType.RemainCapacity == 0)
                        {
                            continue;
                        }
                    }
                    if (!getdiscountType.ForceCode && !getdiscountType.ForceAttach)
                    {
                        tempDiscount.Added = true;
                    }
                    tempDiscount.DiscountType = getdiscountType;
                    outlist.Add(tempDiscount);
                }
                return(outlist);
            }
            catch (KnownException ex)
            {
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
            catch (Exception ex)
            {
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
        }