Exemplo n.º 1
0
        // *********************************************************************************************************************************************w
        // GET: api/orders/returncar/{carLicenseNumber}
        // function that returns the latests order that active of the car with the carLicenseNumber
        // by merging 3 tables OrdersTable, CarsTable And CarModelTable
        // when customer makes an order, the order is adding to the table and the end date is null if the order is value is null it means that the order is
        // still active
        // this function helped me to show the employee the amount of money the customer needs to pay by merging carmodeltable
        // and get the car image and license number to help the employee to see if the car matches the order by merging carstable
        public IHttpActionResult GetCarOrder(int carLicenseNumber)
        {
            using (CarsDBEntities db = new CarsDBEntities())
            {
                var innerJoinQuery =
                    from order in db.OrdersTables
                    join cars in db.CarsTables on order.CarLicenseNumber equals cars.CarLicenseNumber
                    join model in db.CarModelTables on cars.carmodelID equals model.carmodelID
                    where order.CarLicenseNumber == carLicenseNumber && order.ReturnDate == null
                    select new
                {
                    order.OrderID,
                    order.EstimatedReturnDate,
                    order.ReturnDate,
                    order.StartDate,
                    order.UserID,
                    cars.Image,
                    cars.CarLicenseNumber,
                    model.dailyPrice,
                    model.dailyLateFee
                };

                return(Ok(innerJoinQuery.FirstOrDefault()));
            }
        }
 public IHttpActionResult GetAllCarModels()
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         return(Ok(db.CarModelTables.ToList()));
     }
 }
Exemplo n.º 3
0
        // ***************************************************************************************************************************************
        // GET : api/cars/cardetails/{carid}
        // function that get 1 parameter car id and returns the first car with this carid including information from carmodeltable and branchtable
        // i used this function for rent calculation to bring all the information the employee/customer is needed,
        // i used it twice, at the employee rent calculate before return the car, and in the customer rent calculation
        // it includes Information about the model from CarModelTable, carlicense number, carid and car image from cars table and branch name
        public IHttpActionResult GetAvaliableCar(int carid)
        {
            using (CarsDBEntities db = new CarsDBEntities())
            {
                var innerJoinQuery =
                    (from carmodel in db.CarModelTables
                     join cars in db.CarsTables on carmodel.carmodelID equals cars.carmodelID
                     where cars.CarID == carid
                     join branchs in db.BranchTables on cars.BranchId equals branchs.BranchId

                     select new
                {
                    carmodel.carmodelID,
                    carmodel.dailyLateFee,
                    carmodel.dailyPrice,
                    carmodel.gearbox,
                    carmodel.manufacturer,
                    carmodel.model,
                    carmodel.year,
                    cars.Image,
                    cars.CarLicenseNumber,
                    cars.CarID,
                    branchs.BranchName,
                })
                ;

                //produces flat sequence
                return(Ok(innerJoinQuery.FirstOrDefault()));
            }
        }
 public IHttpActionResult GetAllUsers()
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         return(Ok(db.UsersTables.ToList()));
     }
 }
Exemplo n.º 5
0
 public IHttpActionResult GetAllAvaliableCars()
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var innerJoinQuery =
             from carmodel in db.CarModelTables
             join cars in db.CarsTables on carmodel.carmodelID equals cars.carmodelID
             where cars.isRentable == true && cars.isDamaged == false
             join branch in db.BranchTables on cars.BranchId equals branch.BranchId
             orderby carmodel.manufacturer
             select new
         {
             carmodel.carmodelID,
             carmodel.dailyLateFee,
             carmodel.dailyPrice,
             carmodel.gearbox,
             carmodel.manufacturer,
             carmodel.model,
             carmodel.year,
             cars.Image,
             cars.CarLicenseNumber,
             cars.CarID,
             branch.BranchName
         };
         return(Ok(innerJoinQuery.ToList()));
     }
 }
 public IHttpActionResult GetCarModel(int carmodelID)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var CarModel = db.CarModelTables.FirstOrDefault(car => carmodelID == car.carmodelID);
         return(Ok(CarModel));
     }
 }
Exemplo n.º 7
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"));
     }
 }
Exemplo n.º 8
0
        private void BtnRemUserAccount_Click(object sender, RoutedEventArgs e)
        {
            CarsDBEntities context = new CarsDBEntities();



            //Accounts acc = Accountsdtgr.SelectedItem as Accounts;

            //var test = context.Accounts.Where()
        }
 public IHttpActionResult GetUserLogin(string username, string password)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentUser = db.UsersTables.FirstOrDefault(user => (user.UserName == username) && (user.Password == password));
         if (currentUser != null)
         {
             return(Ok(currentUser));
         }
         return(BadRequest());
     }
 }
Exemplo n.º 10
0
 // ********************************************************************************************************************************************
 // GET: api/orders/user/{userid} -- user using
 // function that get one parameter - user id and returns all the orders in OrderTable with this user id
 public IHttpActionResult GetAllUserOrders(int userid)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var innerJoinQuery =
             from order in db.OrdersTables
             join cars in db.CarsTables on order.CarLicenseNumber equals cars.CarLicenseNumber
             where order.UserID == userid
             select order;
         return(Ok(innerJoinQuery.ToList()));
     }
 }
Exemplo n.º 11
0
        // GET
        //Car for Details get the first car from the model who is avaliable: api/Cars/5
        //public IHttpActionResult GetCarFromModel(int carmodelID)
        //{
        //    using (CarsDBEntities db = new CarsDBEntities())
        //    {
        //        var car = db.CarsTables.FirstOrDefault(u => carmodelID == u.carmodelID && u.isDamaged == false && u.isRentable == true);
        //        if (car != null)
        //        {
        //            return Ok(car);
        //        }
        //        return BadRequest("Couldnt find the current car");
        //    }
        //}

        // *******************************************************************************************************************************************
        // GET: api/cars/admin/get/{carlicenseid} -- admin using
        // function that gets one parameter carlicenseid and searching for the object in the CarsTable
        // if true it returns ok and the car object
        // else return badrequest
        public IHttpActionResult GetCar(int carlicenseid)
        {
            using (CarsDBEntities db = new CarsDBEntities())
            {
                var car = db.CarsTables.FirstOrDefault(u => carlicenseid == u.CarLicenseNumber);
                if (car != null)
                {
                    return(Ok(car));
                }
                return(BadRequest("Couldnt find the current car"));
            }
        }
Exemplo n.º 12
0
        private void AddTreeNode()
        {
            CarsDBEntities context = new CarsDBEntities();

            var test = context.CarManufacturer
                       .Where(a => a.Id != 0)
                       .Select(a => a.Id)
                       .ToList();
            var test1 = context.Cars
                        .Where(a => a.CarManufacturerId != 0)
                        .Select(a => a.CarManufacturerId)
                        .ToList();
        }
Exemplo n.º 13
0
        private void fill_combobox()
        {
            CarsDBEntities context = new CarsDBEntities();
            var            test    = context.CarManufacturer
                                     .Where(a => a.Id != 0)
                                     .Select(a => a.Name)
                                     .ToList();

            foreach (var item in test)
            {
                this.CarNameComboBox.Items.Add(item);
            }
        }
        public IHttpActionResult GetUser(int UserID)
        {
            using (CarsDBEntities db = new CarsDBEntities())
            {
                var currentUser = db.UsersTables.FirstOrDefault(u => UserID == u.UserID);

                if (currentUser != null)
                {
                    return(Ok(currentUser));
                }
                return(BadRequest("Couldnt find the current user"));
            }
        }
Exemplo n.º 15
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.º 16
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"));
            }
        }
Exemplo n.º 17
0
 // **********************************************************************************************************************************************
 // GET: api/orders/admin/get/{orderid} -- admin using
 // function that get one parameter (orderid), and search for the first object in OrderTable with this primary key
 // if it founds it returns ok and the objects that found
 // else return bad request
 public IHttpActionResult Get(int orderid)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentOrder = db.OrdersTables.Find(orderid);
         if (currentOrder != null)
         {
             return(Ok(currentOrder));
         }
         else
         {
             return(BadRequest("cannot find the order with the order id #" + orderid));
         }
     }
 }
Exemplo n.º 18
0
        private void BtnAddCar_Click(object sender, RoutedEventArgs e)
        {
            CarsDBEntities context = new CarsDBEntities();

            if (CarNameComboBox.SelectedItem == null || txtCarsDiscount.Text == " " || txtCarsEngineLitres.Text == " " ||
                txtCarsGazType.Text == "" || txtCarsModel.Text == "" || txtCarsPhoto1.Text == "" || txtCarsTransmission.Text == "" ||
                txtCarsTypeOfCar.Text == "" || txtCarsPhoto2.Text == "" || txtCarsPhoto3.Text == "")
            {
                MessageBox.Show("Input data is empty!");
            }
            else
            {
                SingletonDb sig = SingletonDb.getInstance();
                sig.addCarToDb(CarNameComboBox.SelectedItem.ToString(), txtCarsModel.Text, txtCarsTransmission.Text, txtCarsGazType.Text, double.Parse(txtCarsEngineLitres.Text), txtCarsTypeOfCar.Text, int.Parse(txtCarsDiscount.Text), txtCarsPhoto1.Text, double.Parse(txtCarPrice.Text), txtCarsPhoto2.Text, txtCarsPhoto3.Text);
            }
        }
 public IHttpActionResult Delete(int userid)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var CurrentUser = db.UsersTables.FirstOrDefault(tmpuser => tmpuser.UserID == userid);
         if (CurrentUser != null)
         {
             db.UsersTables.Remove(CurrentUser);
             db.SaveChanges();
             return(Ok("The User Has Been Removed"));
         }
         else
         {
             return(BadRequest("Cannot Find The Current Car"));
         }
     }
 }
 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());
         }
     }
 }
 // **********************************************************************************************************************************************
 // POST: api/cars/admin/add/ -- using for register component and admin adduser component
 // function that get 1 parameter - user from usersTable type checking if there is any user match to his passportid and Username
 // if true return bad request
 // else add the user to the table and return ok
 public IHttpActionResult Post([FromBody] UsersTable user)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentUser = db.UsersTables.FirstOrDefault(userVal => user.PassportID == userVal.PassportID || user.UserName == userVal.UserName);
         if (currentUser == null)
         {
             db.UsersTables.Add(user);
             db.SaveChanges();
             return(Ok("The User With The Passport Number " + user.PassportID + " added to the table"));
         }
         else
         {
             return(BadRequest("The User With The Passport Number " + user.PassportID + " cannot added to the table"));
         }
     }
 }
Exemplo n.º 22
0
 public HttpResponseMessage OrderStart([FromBody] OrdersTable order)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentCar = db.CarsTables.FirstOrDefault(tmpcar => tmpcar.CarLicenseNumber == order.CarLicenseNumber);
         if (currentCar != null)
         {
             currentCar.isRentable = false;
             db.OrdersTables.Add(order);
             db.SaveChanges();
             return(Request.CreateResponse <CarsTable>(HttpStatusCode.OK, currentCar));
         }
         else
         {
             return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "Count find that current car"));
         }
     }
 }
 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.º 24
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"));
         }
     }
 }
Exemplo n.º 25
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.º 26
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"));
         }
     }
 }
        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));
                }
            }
        }
 public HttpResponseMessage EditUser([FromBody] UsersTable user)
 {
     using (CarsDBEntities db = new CarsDBEntities())
     {
         var currentUser = db.UsersTables.Find(user.UserID);
         if (currentUser != null)
         {
             currentUser.FullName    = user.FullName;
             currentUser.PassportID  = user.PassportID;
             currentUser.MemberLevel = user.MemberLevel;
             currentUser.Image       = user.Image;
             currentUser.Gender      = user.Gender;
             currentUser.BirthDate   = user.BirthDate;
             currentUser.Email       = user.Email;
             currentUser.UserName    = user.UserName;
             db.SaveChanges();
             return(Request.CreateResponse <UsersTable>(HttpStatusCode.OK, currentUser));
         }
         else
         {
             return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "Count find that current user"));
         }
     }
 }
Exemplo n.º 29
0
 public BaseRepository(CarsDBEntities context)
 {
     Context = context;
 }