示例#1
0
 public bool Edit(Vehicle vehicle)
 {
     try
     {
         db.Entry(vehicle).State = EntityState.Modified;
         db.SaveChanges();
         return true;
     }
     catch (System.Data.DataException ex)
     {
         // Shud do some logging
         Console.WriteLine(ex.ToString());
         //throw new System.Data.DataException();
         return false;
     }
 }
示例#2
0
        // insert a vehicle
        public bool AddVehicle(Vehicle vehicle)
        {
            var ctx = HttpContext.Current;
            try
            {
                // add information to the cache
                //var currentData = ((Vehicle)ctx.Cache[CacheKey]);
                //currentData.Add(vehicle);
                //ctx.Cache[CacheKey] = currentData.ToArray();

                // add data to the database
                db.Vehicles.Add(vehicle);
                db.SaveChanges();

                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return false;
            }
        }
示例#3
0
        public HttpResponseMessage Put(Vehicle vehicle_)
        {
            if (!this.ModelState.IsValid)
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest));

            if (vehicle_ == null)
                throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound));

            bool result = this.vehicle.Edit(vehicle_);

            var response = Request.CreateResponse(HttpStatusCode.OK, result);
            response.Headers.Add("Access-Control-Allow-Origin", "*");
            return response;
        }
示例#4
0
        public HttpResponseMessage Post(Vehicle vehicle_)
        {
            // if state is not valid  method aborts the request and returns a Bad Request (400) status code
            if (!this.ModelState.IsValid)
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest));

            this.vehicle.AddVehicle(vehicle_);

            HttpContext context = HttpContext.Current;

            var response = Request.CreateResponse(HttpStatusCode.Created, vehicle_);
            response.Headers.Add("Access-Control-Allow-Origin", "*");

            return response;
        }