Exemple #1
0
        public IMessageProvider Save()
        {
            TransactionHelper.BeginTransaction();
            var serialNo    = SerialNoHelper.Create();
            var pointRebate = PointRebateService.GetById(this.PointRebate);

            if (pointRebate == null)
            {
                AddError(LogTypes.AccountRebate, "NoPointRebate");
                return(this);
            }
            var account = AccountService.GetById(AccountId);

            if (account == null || account.Point < pointRebate.Point)
            {
                AddError(LogTypes.AccountRebate, "NoPointRebate");
                return(this);
            }

            var accountLevel =
                AccountLevelPolicyService.Query().FirstOrDefault(
                    x => x.State == AccountLevelPolicyStates.Normal && x.Level == account.AccountLevel && x.AccountTypeId == account.AccountTypeId);

            var owner        = (AccountUser)(_innerObject.OwnerId.HasValue ? this.MembershipService.GetUserById(_innerObject.OwnerId.Value) : null);
            var pointRebates = PointRebateService.Query().Where(x => x.IsFor(account, owner, accountLevel, DateTime.Now) && x.Point < account.Point).ToList();

            if (pointRebates.Count == 0)
            {
                AddError(LogTypes.AccountRebate, "NoPointRebate");
                return(this);
            }

            if (!pointRebates.Any(x => x.PointRebateId == pointRebate.PointRebateId))
            {
                AddError(LogTypes.AccountRebate, "NoPointRebate");
                return(this);
            }

            account.Amount += pointRebate.Amount;
            account.Point  -= pointRebate.Point;

            AccountService.Update(account);
            var dealLog = new DealLog(serialNo, DealTypes.Rebate, -pointRebate.Amount, -pointRebate.Point, null, null, account, null, pointRebate.PointRebateId);

            DealLogService.Create(dealLog);
            SystemDealLogService.Create(new SystemDealLog(serialNo, SecurityHelper.GetCurrentUser())
            {
                Amount = pointRebate.Amount, DealType = SystemDealLogTypes.Rebate, Addin = dealLog.DealLogId.ToString()
            });
            Logger.LogWithSerialNo(LogTypes.AccountRebate, serialNo, account.AccountId, account.Name, pointRebate.DisplayName);
            PointRebateLogService.Create(new PointRebateLog(serialNo, account, SecurityHelper.GetCurrentUser().CurrentUser, pointRebate));
            AddMessage("success", pointRebate.Amount, pointRebate.Point);
            return(TransactionHelper.CommitAndReturn(this));
        }
Exemple #2
0
        public void Query()
        {
            var query = PointRebateService.Query();

            if (State != States.All)
            {
                query = query.Where(x => x.State == State);
            }
            if (AccountLevel != Globals.All)
            {
                query = query.Where(x => x.IncludeLevel(AccountLevel));
            }
            this.List = query.ToList(this, x => new ListPointRebate(x));
        }
Exemple #3
0
        public void Ready()
        {
            var accountLevel =
                AccountLevelPolicyService.Query().FirstOrDefault(
                    x => x.State == AccountLevelPolicyStates.Normal && x.Level == _innerObject.AccountLevel && x.AccountTypeId == _innerObject.AccountTypeId);

            var owner  = (AccountUser)(_innerObject.OwnerId.HasValue ? this.MembershipService.GetUserById(_innerObject.OwnerId.Value) : null);
            var levels = PointRebateService.Query().Where(x => x.IsFor(_innerObject, owner, accountLevel, DateTime.Now) && x.Point < _innerObject.Point)
                         .Select(x => new IdNamePair()
            {
                Key = x.PointRebateId, Name = x.DisplayName
            });

            PointRebate.Bind(levels);
        }