Beispiel #1
0
        public async Task <IHttpActionResult> PutTask(int id, Task task)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            try
            {
                _repo.Upadte(task);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
 public async Task <IHttpActionResult> PostTask(Task task)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         _repo.Create(task);
         return(CreatedAtRoute("DefaultApi", new { id = task.Id }, task));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }