Esempio n. 1
0
        public IHttpActionResult PostDutyPosition(DutyPosition dutyPosition)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.DutyPositions.Add(dutyPosition);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (DutyPositionExists(dutyPosition.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApiPost", new { id = dutyPosition.id }, dutyPosition));
        }
Esempio n. 2
0
        public IHttpActionResult PutDutyPosition(int id, DutyPosition dutyPosition)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DutyPositionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 3
0
        public IHttpActionResult DeleteDutyPosition(int id)
        {
            DutyPosition dutyPosition = db.DutyPositions.Find(id);

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

            db.DutyPositions.Remove(dutyPosition);
            db.SaveChanges();

            return(Ok(dutyPosition));
        }
Esempio n. 4
0
        public IHttpActionResult GetDutyPosition(int id)
        {
            DutyPosition dutyPosition = db.DutyPositions.Find(id);

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

            return(Ok(new DropDownDTO
            {
                id = dutyPosition.id.ToString(),
                description = dutyPosition.description
            }));
        }