Example #1
0
        public async Task <ActionResult <Todoitem> > PostTodoitem(Todoitem todoitem)
        {
            _context.TodoItems.Add(todoitem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTodoitem", new { id = todoitem.Id }, todoitem));
        }
Example #2
0
        public IActionResult Create(Todoitem item)
        {
            _context.Todoitems.Add(item);
            _context.SaveChanges();

            return(CreatedAtRoute("GetTodo", new { id = item.id }, item));
        }
Example #3
0
        public async Task <IActionResult> PutTodoitem(int id, Todoitem todoitem)
        {
            if (id != todoitem.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        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 #5
0
        public async Task <Todoitem> CreateAsync(Todoitem item)
        {
            _context.TodoItems.Add(item);
            await _context.SaveChangesAsync();

            return(item);
        }
        public IActionResult Update(string id, [FromBody] Todoitem item)
        {
            if (item == null || item.Key != id)
            {
                return(BadRequest());
            }

            todoItems.Update(item);
            return(new NoContentResult());
        }
        public IActionResult Create([FromBody] Todoitem item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            todoItems.Add(item);
            return(CreatedAtRoute("GetTodo", new { id = item.Key }, item));
        }
        public async Task <ActionResult <Todoitem> > PutTodoItem(long id, Todoitem item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

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

            return(NoContent());
        }
Example #9
0
        public async Task <ActionResult <Todoitem> > PostTodoitem([FromBody] Todoitem todoitem)
        {
            if (_env.EnvironmentName == "Development")
            {
                _logger.LogWarning(2001, "Post方法被呼叫,傳入資料為:" + JsonConvert.SerializeObject(todoitem));
            }

            _context.todoitems.Add(todoitem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTodoitem", new { id = todoitem.Id }, todoitem));
        }
Example #10
0
        public async Task <Todoitem> DeleteAsync(Todoitem item)
        {
            var todo = await _context.TodoItems.FindAsync(item.Id);

            if (todo == null)
            {
                NotFound();
            }

            _context.TodoItems.Remove(todo);
            _context.SaveChanges();

            return(todo);
        }
        public Task <Todoitem[]> GetIncompleteItemAsync()
        {
            var item1 = new Todoitem
            {
                Title = "Learn ASP .NET Core",
                DueAt = DateTimeOffset.Now.AddDays(1)
            };

            var item2 = new Todoitem
            {
                Title = "Build awesome apps",
                DueAt = DateTimeOffset.Now.AddDays(2)
            };

            return(Task.FromResult(new[] { item1, item2 }));
        }
Example #12
0
        public IActionResult Update(long id, Todoitem item)
        {
            var todo = _context.Todoitems.Find(id);

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

            todo.IsComplete = item.IsComplete;
            todo.Name       = item.Name;

            _context.Todoitems.Update(todo);
            _context.SaveChanges();
            return(NoContent());
        }
Example #13
0
        public async Task <Todoitem> UpdateAsync(Todoitem item)
        {
            var todo = await _context.TodoItems.FindAsync(item.Id);

            if (todo == null)
            {
                NotFound();
            }

            todo.IsComplete = item.IsComplete;
            todo.Name       = item.Name;

            _context.TodoItems.Update(todo);
            _context.SaveChanges();
            return(todo);
        }
Example #14
0
        public IActionResult Update([FromBody] Todoitem item, string id)
        {
            if (item == null || item.Key != id)
            {
                return(BadRequest());
            }

            var item1 = todoItems.Find(id);

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

            item.Key = item1.Key;
            todoItems.Update(item);
            return(new NoContentResult());
        }
Example #15
0
        public async Task <IActionResult> Delete(TodoItemDto itemdto)
        {
            Todoitem item = _mapper.Map <Todoitem>(itemdto);

            return(Ok(await _service.DeleteAsync(item)));
        }
Example #16
0
 public async Task <TodoItemDto> UpdateAsync(Todoitem toDoItem)
 {
     return(Mapper.Map <TodoItemDto>(await _dorepo.UpdateAsync(toDoItem)));
 }