public void ResolveLabels(TodoItem todoItem) { if (todoItem.Labels != null) { List <TodoLabel> tempList = new List <TodoLabel>(todoItem.Labels); foreach (TodoLabel label in todoItem.Labels) { string labelText = label.Value; TodoLabel found = _context.TodoItemLabels.FirstOrDefault(t => t.Value.Equals(labelText)); if (found != null) { tempList.Remove(label); tempList.Add(found); found.LabelTodoItems.Add(todoItem); } else { label.LabelTodoItems.Add(todoItem); _context.TodoItemLabels.Add(label); } } todoItem.Labels = tempList; } }
public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return(false); } TodoLabel other = (TodoLabel)obj; return(other.Value.Equals(this.Value)); }