Example #1
0
        public async Task <IActionResult> Create([FromBody] CreateOrUpdateTodoItemDto item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            var todoItem = _mapper.Map <CreateOrUpdateTodoItemDto, TodoItem>(item);

            await _context.TodoItems.AddAsync(todoItem);

            await _context.SaveChangesAsync();

            return(CreatedAtRoute(nameof(GetActionResultById), new { id = todoItem.Id }, todoItem));
        }
Example #2
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> Update(long id, [FromBody] CreateOrUpdateTodoItemDto item)
        {
            if (item == null || id == 0)
            {
                return(BadRequest());
            }

            var todoItem = await _context.TodoItems.FirstOrDefaultAsync(s => s.Id == id);

            if (todoItem == null)
            {
                return(NotFound());
            }

            _mapper.Map(item, todoItem);

            _context.TodoItems.Update(todoItem);
            await _context.SaveChangesAsync();

            return(new NoContentResult());
        }