示例#1
0
        public async Task AddAsync(TodoItem todoItem)
        {
            if (_context.TodoItem.Any(s => s.Id == todoItem.Id))
            {
                throw new DuplicateTodoItemException("Item with the id: " + todoItem.Id + " already exists.");
            }

            _context.TodoItem.Add(todoItem);
            await _context.SaveChangesAsync();
        }
示例#2
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);
        }