private void AddUpdatedBonus(Data.Bonus updatedBonus) { updatedBonus.Template = _repository.Templates.Single(a => a.Id == updatedBonus.Template.Id && a.Version == updatedBonus.Template.Version); var firstBonusVersion = _repository.Bonuses .Where(bonus => bonus.Id == updatedBonus.Id) .OrderBy(b => b.CreatedOn) .First(); updatedBonus.CreatedOn = firstBonusVersion.CreatedOn; updatedBonus.CreatedBy = firstBonusVersion.CreatedBy; updatedBonus.UpdatedOn = DateTimeOffset.Now.ToBrandOffset(updatedBonus.Template.Info.Brand.TimezoneId); updatedBonus.UpdatedBy = _actorInfoProvider.Actor.UserName; //to persist bonus statistic updatedBonus.Statistic = _repository.GetCurrentVersionBonuses().Single(a => a.Id == updatedBonus.Id).Statistic; updatedBonus.Version++; _repository.Bonuses.Add(updatedBonus); _repository.SaveChanges(); }
internal IQueryable <Data.Bonus> GetCurrentVersionBonuses() { return(_repository.GetCurrentVersionBonuses().AsNoTracking()); }