예제 #1
0
        public async Task<IHttpActionResult> PutTodo(Todo todo)
        {
            int id = todo.Id;
            todo.Modified = DateTime.Now;

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != todo.Id)
            {
                return BadRequest();
            }

            db.Entry(todo).State = EntityState.Modified;

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

            return Ok(todo);
        }
예제 #2
0
        public async Task<IHttpActionResult> PostTodo(Todo todo)
        {
            todo.Modified = DateTime.Now;
            todo.Created = DateTime.Now;
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            db.Todoes.Add(todo);
            await db.SaveChangesAsync();

            return Ok(todo);
        }