Beispiel #1
0
        public IHttpActionResult PostCyberEmployee(CyberEmployee cyberEmployee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CyberEmployees.Add(cyberEmployee);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (CyberEmployeeExists(cyberEmployee.ID))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = cyberEmployee.ID }, cyberEmployee));
        }
Beispiel #2
0
        public IHttpActionResult PutCyberEmployee(int id, CyberEmployee cyberEmployee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #3
0
        public IHttpActionResult GetCyberEmployee(int id)
        {
            CyberEmployee cyberEmployee = db.CyberEmployees.Find(id);

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

            return(Ok(cyberEmployee));
        }
Beispiel #4
0
        public IHttpActionResult DeleteCyberEmployee(int id)
        {
            CyberEmployee cyberEmployee = db.CyberEmployees.Find(id);

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

            db.CyberEmployees.Remove(cyberEmployee);
            db.SaveChanges();

            return(Ok(cyberEmployee));
        }