public bool MergePageResponseDetail(PageResponseDetail pageResponseDetail) { // Assume that the page has been updated var hasBeenUpdated = true; if (PageResponseDetailList.Count > 0) { // Check if the page already exists in the PageResponseDetail. // Either the index to the existing page response detail will be returned // or a negative number which is the one's complement of the insertion point will be returned. int index = GetPageResponseDetailIndexByPageNumber(pageResponseDetail.PageNumber); if (index >= 0) { // Check to see if the page has been updated hasBeenUpdated = !(PageResponseDetailList[index].Equals(pageResponseDetail)); if (hasBeenUpdated) { pageResponseDetail.HasBeenUpdated = hasBeenUpdated; PageResponseDetailList[index] = pageResponseDetail; } } else { hasBeenUpdated = true; pageResponseDetail.HasBeenUpdated = hasBeenUpdated; // The one's complement is the insertion index index = ~index; if (index >= PageResponseDetailList.Count) { PageResponseDetailList.Add(pageResponseDetail); } else { PageResponseDetailList.Insert(index, pageResponseDetail); } } } else { hasBeenUpdated = true; pageResponseDetail.HasBeenUpdated = hasBeenUpdated; PageResponseDetailList.Add(pageResponseDetail); } if (!PageIds.Contains(pageResponseDetail.PageId)) { PageIds.Add(pageResponseDetail.PageId); PageIds.Sort(); } return(hasBeenUpdated); }
public void AddPageResponseDetail(PageResponseDetail pageResponseDetail) { var existingItem = PageResponseDetailList.SingleOrDefault(p => p.PageId == pageResponseDetail.PageId); if (existingItem != null) { PageResponseDetailList.Remove(existingItem); } FormId = FormId ?? pageResponseDetail.FormId; FormName = FormName ?? pageResponseDetail.FormName; pageResponseDetail.FormId = FormId; pageResponseDetail.FormName = FormName; pageResponseDetail.ResponseId = ResponseId; PageResponseDetailList.Add(pageResponseDetail); PageIds = PageResponseDetailList.Select(p => p.PageId).OrderBy(pid => pid).ToList(); }