Beispiel #1
0
        // PUT api/Task/5
        public IHttpActionResult PutTask(int id, Task task)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Beispiel #2
0
 public IHttpActionResult PostTask(Task task)
 {
     if (!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     task.CreatedOn = DateTime.Now;
     db.Tasks.Add(task);
     db.SaveChanges();
     // System.Diagnostics.Trace.TraceInformation("Another post with id : " + task.Id.ToString());
     return Ok(task); //  CreatedAtRoute("DefaultApi", new { id = task.Id }, task);
 }