123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.Entity;
- using System.Data.Entity.Infrastructure;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Web.Http;
- using System.Web.Http.Description;
- using esoft_API.Models.Entities;
- namespace esoft_API.Controllers
- {
- public class ExecutorsController : ApiController
- {
- private esoftEntities db = new esoftEntities();
- // GET: api/Executors
- public IQueryable<Executor> GetExecutor()
- {
- return db.Executor;
- }
- // GET: api/Executors/5
- [ResponseType(typeof(Executor))]
- public IHttpActionResult GetExecutor(int id)
- {
- Executor executor = db.Executor.Find(id);
- if (executor == null)
- {
- return NotFound();
- }
- return Ok(executor);
- }
- // PUT: api/Executors/5
- [ResponseType(typeof(void))]
- public IHttpActionResult PutExecutor(int id, Executor executor)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- if (id != executor.ID)
- {
- return BadRequest();
- }
- db.Entry(executor).State = EntityState.Modified;
- try
- {
- db.SaveChanges();
- }
- catch (DbUpdateConcurrencyException)
- {
- if (!ExecutorExists(id))
- {
- return NotFound();
- }
- else
- {
- throw;
- }
- }
- return StatusCode(HttpStatusCode.NoContent);
- }
- // POST: api/Executors
- [ResponseType(typeof(Executor))]
- public IHttpActionResult PostExecutor(Executor executor)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- db.Executor.Add(executor);
- try
- {
- db.SaveChanges();
- }
- catch (DbUpdateException)
- {
- if (ExecutorExists(executor.ID))
- {
- return Conflict();
- }
- else
- {
- throw;
- }
- }
- return CreatedAtRoute("DefaultApi", new { id = executor.ID }, executor);
- }
- // DELETE: api/Executors/5
- [ResponseType(typeof(Executor))]
- public IHttpActionResult DeleteExecutor(int id)
- {
- Executor executor = db.Executor.Find(id);
- if (executor == null)
- {
- return NotFound();
- }
- db.Executor.Remove(executor);
- db.SaveChanges();
- return Ok(executor);
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- db.Dispose();
- }
- base.Dispose(disposing);
- }
- private bool ExecutorExists(int id)
- {
- return db.Executor.Count(e => e.ID == id) > 0;
- }
- }
- }
|