Пример #1
0
        public IHttpActionResult PutWebApiEmp(int id, WebApiEmp webApiEmp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public IHttpActionResult GetWebApiEmp(int id)
        {
            WebApiEmp webApiEmp = db.WebApiEmps.Find(id);

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

            return(Ok(webApiEmp));
        }
Пример #3
0
        public IHttpActionResult PostWebApiEmp(WebApiEmp webApiEmp)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.WebApiEmps.Add(webApiEmp);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = webApiEmp.Id }, webApiEmp));
        }
Пример #4
0
        public IHttpActionResult DeleteWebApiEmp(int id)
        {
            WebApiEmp webApiEmp = db.WebApiEmps.Find(id);

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

            db.WebApiEmps.Remove(webApiEmp);
            db.SaveChanges();

            return(Ok(webApiEmp));
        }