public void Query() { if (string.IsNullOrWhiteSpace(this.AccountName)) { var query = PointGiftService.Query().Where(x => x.State == PointGiftStates.Normal); List = BuildQuery(query).ToList(this, x => x); CurrentPoint = 0; } else { var account = AccountService.GetByName(AccountName); if (account != null) { AccountUser owner = null; if (account.OwnerId.HasValue) { owner = (AccountUser)MembershipService.GetUserById(account.OwnerId.Value); } CurrentPoint = account.Point; var accountLevel = AccountLevelPolicyService.Query().FirstOrDefault(x => x.Level == account.AccountLevel && account.AccountTypeId == x.AccountTypeId); var query = PointGiftService.Query().Where(x => x.IsFor(account, owner, accountLevel, DateTime.Now)); List = BuildQuery(query).ToList(this, x => x); } else { ErrorMessage = Localize("nofoundAccount", string.Format("ÕÊ»§ {0} δÕÒµ½", AccountName)); List = new PageOfList <PointGift>(this.OrderBy, this.PageSize); } } }
public void Query() { var query = PointGiftService.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 ListPointGift(x)); }
public object Save() { var serialNo = SerialNoHelper.Create(); try { var account = AccountService.GetByName(AccountName); if (account == null || account.State != AccountStates.Normal) { return(new DataAjaxResult(string.Format(Localize("NoAccount", "会员卡号 {0} 未找到"), AccountName))); } var passwordService = UnityContainer.Resolve <IPasswordService>(HostSite.PasswordType); var password = passwordService.Decrypto(Password); var accountLevel = AccountLevelPolicyService.Query().FirstOrDefault(x => x.Level == account.AccountLevel && account.AccountTypeId == x.AccountTypeId); var owner = (AccountUser)(account.OwnerId.HasValue ? MembershipService.GetUserById(account.OwnerId.Value) : null); var gift = PointGiftService.Query().Where(x => x.IsFor(account, owner, accountLevel, DateTime.Now)).FirstOrDefault(x => x.PointGiftId == GiftId); if (gift == null) { return(new DataAjaxResult(Localize("NoGift", "礼品未找到"))); } if (gift.Point > account.Point) { return(new DataAjaxResult(Localize("NoEnoughPoint", "积分不足"))); } if (User.SaltAndHash(password, account.PasswordSalt) != account.Password) { return(new DataAjaxResult(Localize("error.Password", "密码错误"))); } account.Point -= gift.Point; TransactionHelper.BeginTransaction(); AccountService.Update(account); DealLogService.Create(new DealLog(serialNo, DealTypes.Gift, 0, -gift.Point, null, null, account, null, gift.PointGiftId)); Logger.LogWithSerialNo(LogTypes.AccountDoGift, serialNo, account.AccountId, account.Name, gift.DisplayName); return(TransactionHelper.CommitAndReturn(new DataAjaxResult())); } catch (System.Exception ex) { Logger.Error(LogTypes.AccountDoGift, ex); return(new DataAjaxResult(Localize("Error", "兑换失败"))); } }