コード例 #1
0
        public async Task <IHttpActionResult> PutAssistiveDevice(int id, AssistiveDevice assistiveDevice)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != assistiveDevice.ID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public async Task <IHttpActionResult> PostAssistiveDevice(AssistiveDevice assistiveDevice)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AssistiveDevices.Add(assistiveDevice);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (AssistiveDeviceExists(assistiveDevice.ID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = assistiveDevice.ID }, assistiveDevice));
        }
コード例 #3
0
        public async Task <IHttpActionResult> GetAssistiveDevice(int id)
        {
            AssistiveDevice assistiveDevice = await db.AssistiveDevices.FindAsync(id);

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

            return(Ok(assistiveDevice));
        }
コード例 #4
0
        public async Task <IHttpActionResult> DeleteAssistiveDevice(int id)
        {
            AssistiveDevice assistiveDevice = await db.AssistiveDevices.FindAsync(id);

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

            db.AssistiveDevices.Remove(assistiveDevice);
            await db.SaveChangesAsync();

            return(Ok(assistiveDevice));
        }