private IEnumerable<ParseObject> UpdateDuplicateRecordsInternal(ref Purchase[] userCoupons) { var duplicateCoupons = userCoupons.Where(x => x.BundleKey != null) .GroupBy(x => x.BundleKey.ObjectId) .Where(x => x.Count() > 1) .Union(userCoupons.Where(x => x.ClipKey != null).GroupBy(x => x.ClipKey.ObjectId).Where(x => x.Count() > 1)); var updateObjects = new List<ParseObject>(); foreach (var duplicateCouponList in duplicateCoupons) { var couponsToUpdate = duplicateCouponList.Except(new[] { duplicateCouponList.Last() }).ToArray(); couponsToUpdate.ForEach(x => x.PurchaseStatusCode = BL.Consts.CouponStatus.WasDuplicate); userCoupons = userCoupons.Except(couponsToUpdate).ToArray(); updateObjects.AddRange(couponsToUpdate); } return updateObjects; }