Esempio n. 1
0
        // 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));
     }
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        // 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);
        }
Esempio n. 6
0
 public void Putcar(int id, [FromBody] CarsStock cs)
 {
 }
Esempio n. 7
0
 public void PostCar([FromBody] CarsStock cs)
 {
 }
Esempio n. 8
0
 // PUT api/<controller>/5
 public void PutCar(int id, [FromBody] CarsStock value)
 {
 }
Esempio n. 9
0
 // POST api/<controller>
 public void PostCar([FromBody] CarsStock value)
 {
 }