Beispiel #1
0
        public async Task <IActionResult> PutItem(int id, Item item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> PutComment(long id, Comment comment)
        {
            if (id != comment.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #3
0
        public async Task <ActionResult <TodoItem> > Create([FromBody] TodoItem item)
        {
            item.CreatedOn = DateTime.UtcNow;
            item.Id        = default(int);
            await _context.TodoItems.AddAsync(item);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetById), new { item.Id }, item));
        }
        public async Task <IActionResult> PutTodoItem(long id, TodoItem todoItem)
        {
            if (id != todoItem.Id)
            {
                return(BadRequest());
            }

            //Lab 2
            if (todoItem.State.Equals(State.Closed))
            {
                todoItem.DateClosed = DateTime.Now;
            }
            else
            {
                todoItem.DateClosed = default;
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoItemExists(id))
                {
                    return(NotFound("This item does not exist!"));
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }