Ejemplo n.º 1
0
 public async Task AddLabelToTodoItem(TodoItemLabel label, TodoItem todoItem)
 {
     if (!todoItem.Labels.Contains(label))
     {
         _context.Entry(todoItem).State = EntityState.Modified;
         todoItem.Labels.Add(label);
         await _context.SaveChangesAsync();
     }
 }
Ejemplo n.º 2
0
        public void AddLabel(TodoItemLabel item)
        {
            // ensuring that the label won't be put to the database if the same label allready exists
            TodoItemLabel todoItemLabel = _context.TodoItemLabel.FirstOrDefault(s => s.Value == item.Value);

            if (todoItemLabel == null)
            {
                _context.TodoItemLabel.Add(item);
            }
            _context.SaveChanges();
        }
Ejemplo n.º 3
0
        public async Task <TodoItemLabel> AddLabelToDb(TodoItemLabel label)
        {
            TodoItemLabel labelinDb = await _context.TodoLabels.FirstOrDefaultAsync(l => l.Value.Equals(label.Value));

            if (labelinDb == null)
            {
                _context.TodoLabels.Add(label);
                await _context.SaveChangesAsync();

                return(label);
            }
            return(labelinDb);
        }