Example #1
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);
            }
        }
Example #2
0
        public bool GroupPayTemp(IConnectionHandler connectionHandler, Temp temp, List <Guid> model)
        {
            temp.Description = Resources.Payment.GroupPayment + " ";
            var index = 1;

            foreach (var guid in model)
            {
                if (temp.Description.Length > 80)
                {
                    temp.Description += "\r\n" + " ";
                }
                var temp1 = this.Get(connectionHandler, guid);
                if (temp1 == null)
                {
                    continue;
                }
                temp.Amount      += temp1.Amount;
                temp.Description += ((index > 1 && index <= model.Count) ? " " + Resources.Payment.And + " " : " ") +
                                    temp1.Description + " " + Resources.Payment.WithAmount + ":" + temp1.Amount + " " +
                                    ((Common.Definition.Enums.CurrencyType)temp1.CurrencyType)
                                    .GetDescriptionInLocalization();
                index++;
            }

            if (!this.Insert(connectionHandler, temp))
            {
                return(false);
            }
            if (!model.Any())
            {
                return(true);
            }
            var list           = this.Where(connectionHandler, x => x.Id.In(model));
            var tempDiscountBo = new TempDiscountBO();
            var discounts      = tempDiscountBo.Where(connectionHandler, x => x.TempId.In(model));

            foreach (var temp1 in list)
            {
                if (model.Count > 1)
                {
                    System.Threading.Thread.Sleep(1000);
                }
                temp1.ParentId = temp.Id;
                if (!this.Update(connectionHandler, temp1))
                {
                    return(false);
                }
                var discountAttaches = discounts.Where(discount => discount.TempId == temp1.Id).ToList();
                foreach (var discountAttach in discountAttaches)
                {
                    if (discountAttaches.Count > 1)
                    {
                        System.Threading.Thread.Sleep(1000);
                    }
                    var tempDiscount = new TempDiscount()
                    {
                        TempId         = temp.Id,
                        DiscountTypeId = discountAttach.DiscountTypeId,
                        AttachId       = discountAttach.AttachId
                    };
                    if (!tempDiscountBo.Insert(connectionHandler, tempDiscount))
                    {
                        throw new Exception(Resources.Payment.ErrorInSaveTransactionDiscount);
                    }
                }
            }

            return(true);
        }