Exemple #1
0
        public static ApiCar GetCar(int id)
        {
            var car = db.Cars.Find(id);

            var carApi = new ApiCar();

            PropertyCopier <Car, ApiCar> .Copy(car, carApi, true);

            return(carApi);
        }
Exemple #2
0
 public ActionResult Edit(ApiCar car)
 {
     if (client.UpdateCar(car))
     {
         ViewBag.message = "Car Updated";
     }
     else
     {
         ViewBag.message = "Car not Changed, error";
     }
     return(RedirectToAction("Details", new { id = car.CarId }));
 }
Exemple #3
0
        public static void PutCar(int id, ApiCar ac)
        {
            // Create a new car
            Car c = db.Cars.Find(id);

            // Copy car
            if (ac.CarId == id)
            {
                PropertyCopier <ApiCar, Car> .Copy(ac, c, true);

                db.Entry(c).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
Exemple #4
0
        public static void PostCar(ApiCar ac)
        {
            // Create a new EF Customer.
            Car c = new Car();

            // Copy the Simplified customer to the EF customer using the tool I provided.
            PropertyCopier <ApiCar, Car> .Copy(ac, c, true);

            // Tell EF we want to add the customer.
            db.Cars.Add(c);

            //Save changes
            db.SaveChanges();
        }
        public HttpResponseMessage PostCar([FromBody] ApiCar ac)
        {
            try
            {
                DBAccess.PostCar(ac);
            }
            catch (Exception e)
            {
                // ERROR
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot create record." + e.StackTrace));
            }

            // All OK
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public HttpResponseMessage PutCar(int id, [FromBody] ApiCar ac)
        {
            try
            {
                // Persist our change.
                DBAccess.PutCar(id, ac);
            }
            catch (Exception e)
            {
                // ERROR
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Cannot update record: " + e));
            }

            // All OK
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public bool UpdateCar(ApiCar car)
        {
            client.BaseAddress = new Uri("http://localhost:81/");

            var putTask = client.PutAsJsonAsync <ApiCar>("api/Car/" + car.CarId, car);

            putTask.Wait();
            var result = putTask.Result;

            if (result.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool CreateCar(ApiCar car)
        {
            client.BaseAddress = new Uri("http://localhost:81/");

            var postTask = client.PostAsJsonAsync("api/Car", car);

            postTask.Wait();
            var result = postTask.Result;

            if (result.IsSuccessStatusCode)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #9
0
        public ActionResult Create(FormCollection form)
        {
            ApiCar car = new ApiCar();

            car.CarColor      = form["CarColor"];
            car.CarType       = form["CarType"];
            car.CarModel      = form["CarModel"];
            car.CarPrice      = Decimal.Parse(form["CarPrice"]);
            car.CarCommission = Decimal.Parse(form["CarCommission"]);
            if (!client.CreateCar(car))
            {
                return(View(car));
            }
            else
            {
                return(RedirectToAction("Inventory"));
            }
        }
Exemple #10
0
        public ActionResult Create(FormCollection form)
        {
            ApiCar car = new ApiCar()
            {
                CarColor      = form["CarColor"].ToString(),
                CarType       = form["CarType"].ToString(),
                CarModel      = form["CarModel"].ToString(),
                CarPrice      = Decimal.Parse(form["CarPrice"]),
                CarCommission = Decimal.Parse(form["CarCommission"]),
            };

            if (client.CreateCar(car))
            {
                return(RedirectToAction("Cars"));
            }
            else
            {
                return(View(car));
            }
        }
Exemple #11
0
        public ActionResult Delete(int id)
        {
            ApiCar car = client.GetCar(id);

            return(View(car));
        }