Exemplo n.º 1
0
        public ActionResult Create([Bind(Exclude = "Id")] Car carToCreate)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            _db.Cars.Add(carToCreate);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 // ********************************************************************************************************************************************
 // POST: api/orders/admin/add/
 // function that get 1 parameter from OrdersTable type and adds it to the table
 public IHttpActionResult Post([FromBody] OrdersTable order)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         db.OrdersTables.Add(order);
         db.SaveChanges();
         return(Ok("the order has been added"));
     }
 }
        public void addCarToDb(string carName, string carModel, string carTransmission, string carGazType, double carEngLitres, string carType, int carDiscount, string carPhoto1, double carPrice, string carPhoto2, string carPhoto3)
        {
            #region getCarManufacturerId
            string carManufName = carName;

            var checkId = context.CarManufacturer
                          .Where(x => x.Name == carManufName)
                          .Select(x => new { Id = x.Id });

            int[] CarManufacturerId = new int[1];
            foreach (var item in checkId)
            {
                CarManufacturerId[0] = item.Id;
            }

            #endregion
            if (checkId != null)
            {
                Cars CarToAdd = new Cars();

                CarToAdd.Name              = carManufName;
                CarToAdd.Model             = carModel;
                CarToAdd.Transmission      = carTransmission;
                CarToAdd.GazType           = carGazType;
                CarToAdd.EngineLitres      = carEngLitres;
                CarToAdd.TypeOfCar         = carType;
                CarToAdd.CarManufacturerId = CarManufacturerId[0];
                CarToAdd.Discount          = carDiscount;
                CarToAdd.Photo1            = carPhoto1;
                CarToAdd.Price             = carPrice;
                CarToAdd.Photo2            = carPhoto2;
                CarToAdd.Photo3            = carPhoto3;

                context.Cars.Add(CarToAdd);
                context.SaveChanges();
                MessageBox.Show($"{CarToAdd.Name} \n {CarToAdd.Model} \n {CarToAdd.Transmission} \n {CarToAdd.GazType} \n{CarToAdd.EngineLitres} \n {CarToAdd.TypeOfCar} \n {CarToAdd.CarManufacturerId} \n {CarToAdd.Discount} \n {CarToAdd.Photo1} \n {CarToAdd.Price} \n {CarToAdd.Photo2} \n {CarToAdd.Photo3}");
            }
            else
            {
                MessageBox.Show("No such Car manufacturer!");
            }
        }
Exemplo n.º 4
0
 // ********************************************************************************************************************************************
 // DELETE: api/orders/admin/delete/{orderid}
 // function that get one parameter - orderid searching if there is object with the same orderid
 // if true it deletes this object from the table and return success
 // else return bad request
 public IHttpActionResult Delete(int orderid)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentOrder = db.OrdersTables.FirstOrDefault(o => o.OrderID == orderid);
         if (currentOrder != null)
         {
             db.OrdersTables.Remove(currentOrder);
             db.SaveChanges();
             return(Ok("the order #" + orderid + " has been removed"));
         }
         return(BadRequest("couldnt find the order #" + orderid));
     }
 }
Exemplo n.º 5
0
        // *******************************************************************************************************************************************
        // POST: api/cars/admin/add/ -- admin using
        // function that get 1 parameter from CarsTable type
        // looking if this carLicenseNumber is already exists
        // if null and carlicense number != from 0 it adds it to the table and return success
        // else returns badrequest

        public IHttpActionResult Post([FromBody] CarsTable car)
        {
            using (CarsDBEntities db = new CarsDBEntities())
            {
                var currentCar = db.CarsTables.FirstOrDefault(c => c.CarLicenseNumber == car.CarLicenseNumber);
                if (currentCar == null && car.CarLicenseNumber != 0)
                {
                    db.CarsTables.Add(car);
                    db.SaveChanges();
                    return(Ok("The Car Number " + car.CarLicenseNumber + " added to the table"));
                }
                return(BadRequest("Cannot Add This Car The Car Id Number" + car.CarLicenseNumber + "is already exists"));
            }
        }
 public IHttpActionResult Delete(int carmodelID)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentCarModel = db.CarModelTables.FirstOrDefault(carmodelVal => carmodelID == carmodelVal.carmodelID);
         if (currentCarModel != null)
         {
             db.CarModelTables.Remove(currentCarModel);
             db.SaveChanges();
             return(Ok("Deleted"));
         }
         else
         {
             return(BadRequest());
         }
     }
 }
 public IHttpActionResult Post([FromBody] CarModelTable carmodel)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentCarModel = db.CarModelTables.FirstOrDefault(carmodelVal =>
                                                                (carmodel.manufacturer == carmodelVal.manufacturer) && (carmodel.model == carmodelVal.model) && (carmodel.year == carmodelVal.year) && (carmodel.gearbox == carmodelVal.gearbox));
         if (currentCarModel == null)
         {
             db.CarModelTables.Add(carmodel);
             db.SaveChanges();
             return(Ok("The Car Model " + carmodel.manufacturer + " " + carmodel.model + " added to the table"));
         }
         else
         {
             return(BadRequest("The Car Model " + carmodel.manufacturer + " " + carmodel.model + " cannot added to the table"));
         }
     }
 }
Exemplo n.º 8
0
 // ********************************************************************************************************************************************
 // PUT: api/orders/admin/edit/
 // function that get one parameter from orderstable type seach if this id is already exists
 // if true it changes the property value to the ordertable type object
 // and return ok and the current user
 // else return bad request
 public HttpResponseMessage Put([FromBody] OrdersTable value)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentOrder = db.OrdersTables.FirstOrDefault(o => o.OrderID == value.OrderID);
         if (currentOrder != null)
         {
             currentOrder.CarLicenseNumber    = value.CarLicenseNumber;
             currentOrder.EstimatedReturnDate = value.EstimatedReturnDate;
             currentOrder.OrderID             = value.OrderID;
             currentOrder.ReturnDate          = value.ReturnDate;
             currentOrder.StartDate           = value.StartDate;
             currentOrder.UserID = value.UserID;
             db.SaveChanges();
             return(Request.CreateResponse <OrdersTable>(HttpStatusCode.OK, currentOrder));
         }
         else
         {
             return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "Couldnt find the current order"));
         }
     }
 }
Exemplo n.º 9
0
 public HttpResponseMessage OrderFinish(int CarLicenseNumber, int OrderID)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentCar = db.CarsTables.FirstOrDefault(tmpcar => tmpcar.CarLicenseNumber == CarLicenseNumber);
         if (currentCar != null)
         {
             currentCar.isRentable = true;
             var currentOrder = db.OrdersTables.FirstOrDefault(tmporder => tmporder.OrderID == OrderID);
             if (currentOrder != null)
             {
                 currentOrder.ReturnDate = DateTime.Now.ToString("yyyy-MM-dd");
             }
             db.SaveChanges();
             return(Request.CreateResponse <CarsTable>(HttpStatusCode.OK, currentCar));
         }
         else
         {
             return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "Count find that current car"));
         }
     }
 }
Exemplo n.º 10
0
 // *********************************************************************************************************************************************
 // PUT: api/Cars/5
 // Function that edits values in CarsTable by getting 1 parameter from CarsTable type
 // if this car.CarLicenseNumber is found to check the values are true and edits the currentcar values and return success
 // else return bad request
 public HttpResponseMessage Put([FromBody] CarsTable car)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentCar = db.CarsTables.FirstOrDefault(tmpcar => tmpcar.CarLicenseNumber == car.CarLicenseNumber);
         if (currentCar != null)
         {
             currentCar.carmodelID       = car.carmodelID;
             currentCar.CarLicenseNumber = car.CarLicenseNumber;
             currentCar.currentKm        = car.currentKm;
             currentCar.Image            = car.Image;
             currentCar.isDamaged        = car.isDamaged;
             currentCar.isRentable       = car.isRentable;
             db.SaveChanges();
             return(Request.CreateResponse <CarsTable>(HttpStatusCode.OK, currentCar));
         }
         else
         {
             return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "Count find that current car"));
         }
     }
 }
        public IHttpActionResult Put([FromBody] CarModelTable carmodel)
        {
            using (CarsDBEntities db = new CarsDBEntities())
            {
                var currentCarModel = db.CarModelTables.FirstOrDefault(carmodelVal => carmodel.carmodelID == carmodelVal.carmodelID);
                if (currentCarModel != null)
                {
                    currentCarModel.dailyLateFee = carmodel.dailyLateFee;
                    currentCarModel.dailyPrice   = carmodel.dailyPrice;
                    currentCarModel.gearbox      = carmodel.gearbox;
                    currentCarModel.manufacturer = carmodel.manufacturer;
                    currentCarModel.model        = carmodel.model;
                    currentCarModel.year         = carmodel.year;

                    db.SaveChanges();
                    return(Ok("The Car Model " + carmodel.carmodelID + " has been edited"));
                }
                else
                {
                    return(BadRequest("Cannot find the Car Model With the Id" + carmodel.carmodelID));
                }
            }
        }
Exemplo n.º 12
0
 public void Create(T item)
 {
     Context.Set <T>().Add(item);
     Context.SaveChanges();
 }