public async Task <IActionResult> PutTodoItem(long id, TodoItem todoItem)
        {
            if (id != todoItem.todoId)
            {
                return(BadRequest());
            }

            _context.Entry(todoItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
        public async Task <ActionResult <TodoItem> > PostTodoItem(TodoItem item)
        {
            _context.TodoItems.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item));
        }
Example #3
0
        public async Task <IActionResult> PutUser(long id, User user)
        {
            if (id != user.userId)
            {
                return(BadRequest());
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        private async Task Delete(TodoItem data)
        {
            var todo = _db.TodoItems.Find(data.Id);

            if (todo == null)
            {
                return;
            }

            //if you prefer soft delete then set the property is delete to true

            if (_isSoftDelete) //This might be in your applications config
            {
                todo.IsDeleted = true;
                _db.TodoItems.Update(todo);
            }
            else
            {
                _db.TodoItems.Remove(todo);
            }

            await _db.SaveChangesAsync();
        }
 public async Task AddTask(TodoItem entity)
 {
     _context.TodoItems.Add(entity);
     await _context.SaveChangesAsync();
 }
        private async Task SaveAndPublish(TodoItem todoItem, CancellationToken cancellationToken)
        {
            await todoItemContext.SaveChangesAsync(cancellationToken);

            await eventBus.Publish(todoItem.PendingEvents.ToArray());
        }