예제 #1
0
        public async Task <IHttpActionResult> PutAdministrativeBody(int id, AdministrativeBody administrativeBody)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public async Task <IHttpActionResult> GetAdministrativeBody(int id)
        {
            AdministrativeBody administrativeBody = await db.AdministrativeBodies.FindAsync(id);

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

            return(Ok(administrativeBody));
        }
예제 #3
0
        public async Task <IHttpActionResult> PostAdministrativeBody(AdministrativeBody administrativeBody)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.AdministrativeBodies.Add(administrativeBody);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = administrativeBody.Id }, administrativeBody));
        }
예제 #4
0
        public async Task <IHttpActionResult> DeleteAdministrativeBody(int id)
        {
            AdministrativeBody administrativeBody = await db.AdministrativeBodies.FindAsync(id);

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

            db.AdministrativeBodies.Remove(administrativeBody);
            await db.SaveChangesAsync();

            return(Ok(administrativeBody));
        }