// GET api/values/5 public IEnumerable <CarsStock> Get(int id) { CarsStock ST = new CarsStock(); CarsStock ST1 = new CarsStock(); List <CarsStock> li = new List <CarsStock>(); if (id == 1) { ST.CarName = "Maruti Waganor"; ST.CarPrice = "4 lakhs"; ST.CarModel = "VXI"; ST.CarColor = "Brown"; li.Add(ST); } else { ST.CarName = "Maruti Swift"; ST.CarPrice = "5 lakhs"; ST.CarModel = "VXI"; ST.CarColor = "Red"; li.Add(ST1); } return(li); }
public HttpResponseMessage Put([FromBody] CarsStock Nvalue, int id) { try { using (EntityDbContext objDB = new EntityDbContext()) { var carData = objDB.Cars.SingleOrDefault(p => p.CarID == id); if (carData == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, string.Format("Car Does not Exists"))); } else { carData.CarName = Nvalue.CarName; carData.CarModel = Nvalue.CarModel; carData.CarPrice = Nvalue.CarPrice; carData.CarColor = Nvalue.CarColor; objDB.SaveChanges(); var msg = Request.CreateResponse(HttpStatusCode.OK, "Record Updated"); msg.Headers.Location = Request.RequestUri; return(msg); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] CarsStock cs) { try { using (EntityDbContext objDB = new EntityDbContext()) { objDB.Cars.Add(cs); objDB.SaveChanges(); } var msg = Request.CreateResponse(HttpStatusCode.OK, "record Created"); msg.Headers.Location = Request.RequestUri; return(msg); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IEnumerable <CarsStock> GetAllCarDetails() { CarsStock ST = new CarsStock(); CarsStock ST1 = new CarsStock(); List <CarsStock> li = new List <CarsStock>(); ST.CarName = "Maruti Waganor"; ST.CarPrice = "4 lakhs"; ST.CarModel = "VXI"; ST.CarColor = "Brown"; ST.CarName = "Maruti Swift"; ST.CarPrice = "5 lakhs"; ST.CarModel = "VXI"; ST.CarColor = "Red"; li.Add(ST); li.Add(ST1); return(li); }
// GET api/<controller>/5 public CarsStock Get(int id) { CarsStock ST = new CarsStock(); if (id == 1) { ST.CarName = "Maruti Waganor"; ST.CarPrice = "4 Lakh"; ST.CarModel = "VXI"; ST.CarColor = "Brown"; } else { ST.CarName = "Maruti Swift"; ST.CarPrice = "5 Lakh"; ST.CarModel = "VXI"; ST.CarColor = "RED"; } return(ST); }
public void Putcar(int id, [FromBody] CarsStock cs) { }
public void PostCar([FromBody] CarsStock cs) { }
// PUT api/<controller>/5 public void PutCar(int id, [FromBody] CarsStock value) { }
// POST api/<controller> public void PostCar([FromBody] CarsStock value) { }