Ejemplo n.º 1
0
        public async Task <IHttpActionResult> PostAction(CHM.Services.Models.Action action)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Actions.Add(action);

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

            return(CreatedAtRoute("DefaultApi", new { id = action.ID }, action));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PutAction(Guid id, CHM.Services.Models.Action action)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> GetAction(Guid id)
        {
            CHM.Services.Models.Action action = await db.Actions.FindAsync(id);

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

            return(Ok(action));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> DeleteAction(Guid id)
        {
            CHM.Services.Models.Action action = await db.Actions.FindAsync(id);

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

            db.Actions.Remove(action);
            await db.SaveChangesAsync();

            return(Ok(action));
        }