public int MoveSegment2NextPosition(Segment segment) { var orderId = -1; foreach (var seg in Segments.OrderBy(t => t.OrderId)) { orderId++; seg.OrderId = orderId; } var oldIndex = Segments[Segments.IndexOf(segment)].OrderId; if (oldIndex == Segments.Count - 1) return oldIndex; Segments.First(t => t.OrderId == oldIndex + 1).OrderId = oldIndex; segment.OrderId = oldIndex + 1; return segment.OrderId; }
public Segment AddSegment(Packet currentPacket) { var segment = new Segment { Name = "", Description = "", OrderId = currentPacket.Segments.Count + 1, Type = new DataTypeView { Type = DataType.Byte }, Size = DataTypeView.SizeOfType(DataType.Byte) }; currentPacket.Segments.Add(segment); return segment; }