public void DeleteTimelineScreenContentXref(TimelineScreenContentXref xref) { var query = from timelinescreencontentxref in db.TimelineScreenContentXrefs select timelinescreencontentxref; query = query.Where(tscxs => tscxs.TimelineID.Equals(xref.TimelineID)); query = query.OrderBy("DisplayOrder", false); List <TimelineScreenContentXref> timelinescreencontentxrefs = query.ToList(); bool found = false; foreach (TimelineScreenContentXref timelinescreencontentxref in timelinescreencontentxrefs) { if (found) { timelinescreencontentxref.DisplayOrder -= 1; db.Entry(timelinescreencontentxref).State = EntityState.Modified; } if (timelinescreencontentxref.TimelineScreenContentXrefID == xref.TimelineScreenContentXrefID) { found = true; db.TimelineScreenContentXrefs.Remove(timelinescreencontentxref); } } db.SaveChanges(); }
public void CreateTimelineScreenContentXref(TimelineScreenContentXref xref) { // Get the maximum display order var query = from timelinescreencontentxref in db.TimelineScreenContentXrefs select timelinescreencontentxref; query = query.Where(tscxs => tscxs.TimelineID.Equals(xref.TimelineID)); query = query.OrderBy("DisplayOrder", true); List <TimelineScreenContentXref> timelinescreencontentxrefs = query.ToList(); int maxdisplayorder = 0; if (timelinescreencontentxrefs.Count > 0) { maxdisplayorder = timelinescreencontentxrefs[0].DisplayOrder; } xref.DisplayOrder = maxdisplayorder + 1; db.TimelineScreenContentXrefs.Add(xref); db.SaveChanges(); }
public void UpdateTimelineScreenContentXref(TimelineScreenContentXref xref) { db.Entry(xref).State = EntityState.Modified; db.SaveChanges(); }
public TimelineScreenContentXref GetTimelineScreenContentXref(int id) { TimelineScreenContentXref timelinescreencontentxref = db.TimelineScreenContentXrefs.Find(id); return(timelinescreencontentxref); }
public void MoveTimelineScreenContentXref(TimelineScreenContentXref xref, bool ismoveup) { var query = from timelinescreencontentxref in db.TimelineScreenContentXrefs select timelinescreencontentxref; query = query.Where(tscxs => tscxs.TimelineID.Equals(xref.TimelineID)); query = query.OrderBy("DisplayOrder", false); List <TimelineScreenContentXref> timelinescreencontentxrefs = query.ToList(); // Get the current and max display orders int currentdisplayorder = xref.DisplayOrder; int maxdisplayorder = 1; foreach (TimelineScreenContentXref timelinescreencontentxref in timelinescreencontentxrefs) { if (timelinescreencontentxref.DisplayOrder > maxdisplayorder) { maxdisplayorder = timelinescreencontentxref.DisplayOrder; } } // Adjust the appropriate display orders foreach (TimelineScreenContentXref timelinescreencontentxref in timelinescreencontentxrefs) { if (ismoveup) { if (timelinescreencontentxref.TimelineScreenContentXrefID == xref.TimelineScreenContentXrefID) // move current question up { if (currentdisplayorder > 1) { xref.DisplayOrder -= 1; } } else // find the previous item and increment it { if (timelinescreencontentxref.DisplayOrder == currentdisplayorder - 1) { timelinescreencontentxref.DisplayOrder += 1; db.Entry(timelinescreencontentxref).State = EntityState.Modified; } } } else { if (timelinescreencontentxref.TimelineScreenContentXrefID == xref.TimelineScreenContentXrefID) // move current question down { if (currentdisplayorder < maxdisplayorder) { xref.DisplayOrder += 1; } } else // find the next item and decrement it { if (timelinescreencontentxref.DisplayOrder == currentdisplayorder + 1) { timelinescreencontentxref.DisplayOrder -= 1; db.Entry(timelinescreencontentxref).State = EntityState.Modified; } } } } db.SaveChanges(); }