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)); }
public void Save() { var serialNo = SerialNoHelper.Create(); var item = PointRebateService.GetById(PointRebateId); if (item != null) { TransactionHelper.BeginTransaction(); item.DisplayName = DisplayName; item.Point = Point; item.Amount = Amount; item.DisplayName = DisplayName; OnSave(item); PointRebateService.Update(item); AddMessage("success", DisplayName); Logger.LogWithSerialNo(LogTypes.PointRebateEdit, serialNo, item.PointRebateId, DisplayName); TransactionHelper.Commit(); } }
public void Read(int id) { var pointRebate = PointRebateService.GetById(id); this.SetInnerObject(pointRebate); }