示例#1
0
        public async Task<IHttpActionResult> PutWorkTask(int id, WorkTask workTask)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
示例#2
0
        public async Task<IHttpActionResult> PostWorkTask(WorkTask workTask)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.WorkTasks.Add(workTask);
            await db.SaveChangesAsync();

            return CreatedAtRoute("DefaultApi", new { id = workTask.Id }, workTask);
        }