예제 #1
0
    protected void AddRow_Click(object sender, EventArgs e)
    {
        /*DataTable table = (DataTable)ViewState["table"];
         * DataRow newRow = table.NewRow();
         * newRow["ID"] = TextBoxID.Text.ToString();
         * newRow["DriverType"] = TextBoxDType.Text.ToString();
         * newRow["Speed"] = TextBoxSpeed.Text.ToString();
         * table.Rows.Add(newRow);
         * BindingGridView();*/
        NewVehicle[] newVehs = new NewVehicle[1];

        //newVehs[0].time = proxy.getServerTimestep() + 1;
        String inode     = TextBoxNID.Text.ToString();
        String pathid    = TextBoxPID.Text.ToString();
        String driver    = TextBoxDType.Text.ToString();
        String fleet     = TextBoxFleet.Text.ToString();
        String vtype     = TextBoxVType.Text.ToString();
        String overspeed = TextBoxOspeed.Text.ToString();
        String range     = TextBoxRange.Text.ToString();

        newVehs[0].inode     = Convert.ToInt32(inode);
        newVehs[0].pathid    = Convert.ToInt32(pathid);
        newVehs[0].driver    = Convert.ToInt32(driver);
        newVehs[0].fleet     = Convert.ToInt32(fleet);
        newVehs[0].vtype     = Convert.ToInt32(vtype);
        newVehs[0].overspeed = Convert.ToInt32(overspeed);
        newVehs[0].range     = Convert.ToInt32(range);

        //proxy.setServerNewVehicleData(newVehs);
        //proxy.setClientState(6);
    }
        public void CreateVehicle(string i_LicenseNumber)
        {
            Console.WriteLine("Enter your vehicle model name");
            string modelName            = Console.ReadLine();
            int    numberOfInputOptions = Enum.GetNames(typeof(eVehicleType)).Length;
            bool   validInput           = false;
            int    opthionNumber        = 0;

            while (!validInput)
            {
                foreach (eVehicleType typeOfVehicle in Enum.GetValues(typeof(eVehicleType)))
                {
                    Console.WriteLine(string.Format("For {0} enter {1}", typeOfVehicle.ToString(), opthionNumber));
                    opthionNumber++;
                }

                int vehicleType = InputValidation.CorrectUserInput(Console.ReadLine(), numberOfInputOptions);
                if (vehicleType != Constants.k_InValid)
                {
                    validInput   = true;
                    m_NewVehicle = NewVehicle.VehicleInstance(modelName, i_LicenseNumber, (eVehicleType)vehicleType);
                }
                else
                {
                    Console.WriteLine("This vehicle type isn't valid!");
                }
            }
        }
예제 #3
0
        public IHttpActionResult PutNewVehicle(int id, NewVehicle newVehicle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != newVehicle.Id)
            {
                return(BadRequest());
            }

            db.Entry(newVehicle).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NewVehicleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #4
0
    protected void AddRow_Click(object sender, EventArgs e)
    {
        /*DataTable table = (DataTable)ViewState["table"];
         * DataRow newRow = table.NewRow();
         * newRow["ID"] = TextBoxID.Text.ToString();
         * newRow["DriverType"] = TextBoxDType.Text.ToString();
         * newRow["Speed"] = TextBoxSpeed.Text.ToString();
         * table.Rows.Add(newRow);
         * BindingGridView();*/
        string strNID = DropDownListNodeID.SelectedItem.Text;

        NewVehicle[] newVehs = new NewVehicle[1];

        String pathid    = TextBoxPID.Text.ToString();
        String driver    = TextBoxDType.Text.ToString();
        String fleet     = TextBoxFleet.Text.ToString();
        String vtype     = TextBoxVType.Text.ToString();
        String overspeed = TextBoxOspeed.Text.ToString();
        String range     = TextBoxRange.Text.ToString();

        newVehs[0].inode     = Convert.ToInt32(strNID);
        newVehs[0].pathid    = Convert.ToInt32(pathid);
        newVehs[0].driver    = Convert.ToInt32(driver);
        newVehs[0].fleet     = Convert.ToInt32(fleet);
        newVehs[0].vtype     = Convert.ToInt32(vtype);
        newVehs[0].overspeed = Convert.ToInt32(overspeed);
        newVehs[0].range     = Convert.ToInt32(range);

        proxy.SetServerNewVehicleData(newVehs);
        proxy.SetClientState((int)ClientState.AddVehicleSubmitted);

        ShowNextTimeStep();
        ShowVehicles();
    }
        public Vehicle Create(NewVehicle vehicleToCreate, int valetId)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand("INSERT INTO vehicles " +
                                                    "(vehicle_make, vehicle_model, vehicle_color, license_plate, patron_id) " +
                                                    "VALUES (@vehicle_make, @vehicle_model, @vehicle_color, @license_plate, " +
                                                    "(SELECT patron_id FROM patrons WHERE email_address like @email_address))"
                                                    , conn);
                    cmd.Parameters.AddWithValue("@vehicle_make", vehicleToCreate.VehicleMake);
                    cmd.Parameters.AddWithValue("@vehicle_model", vehicleToCreate.VehicleModel);
                    cmd.Parameters.AddWithValue("@vehicle_color", vehicleToCreate.VehicleColor);
                    cmd.Parameters.AddWithValue("@license_plate", vehicleToCreate.LicensePlate);
                    cmd.Parameters.AddWithValue("@email_address", vehicleToCreate.PatronEmail);
                    cmd.ExecuteNonQuery();

                    cmd = new SqlCommand("INSERT INTO valet_slips " +
                                         "(valet_id, license_plate, date, time_in, time_out, amount_owed, " +
                                         "parking_spot_id, parking_status_id) " +
                                         "VALUES (@valet_id, @license_plate, GETDATE(), GETDATE(), '1753-1-1', 0, NULL, " +
                                         "(SELECT parking_status_id FROM parking_statuses WHERE parking_status='Spot Requested'))", conn);
                    cmd.Parameters.AddWithValue("@valet_id", valetId);
                    cmd.Parameters.AddWithValue("@license_plate", vehicleToCreate.LicensePlate);
                    cmd.ExecuteNonQuery();

                    return(Get(vehicleToCreate.LicensePlate));
                }
            }
            catch (SqlException e)
            {
                if (e.Number == 2627)    //PK violation - if vehicle exists then create valet slip below
                {
                    using (SqlConnection conn = new SqlConnection(connectionString))
                    {
                        conn.Open();

                        SqlCommand cmd = new SqlCommand("INSERT INTO valet_slips " +
                                                        "(valet_id, license_plate, date, time_in, time_out, amount_owed, " +
                                                        "parking_spot_id, parking_status_id) " +
                                                        "VALUES (@valet_id, @license_plate, GETDATE(), GETDATE(), '1753-1-1', 0, NULL, " +
                                                        "(SELECT parking_status_id FROM parking_statuses WHERE parking_status='Spot Requested'))", conn);
                        cmd.Parameters.AddWithValue("@valet_id", valetId);
                        cmd.Parameters.AddWithValue("@license_plate", vehicleToCreate.LicensePlate);
                        cmd.ExecuteNonQuery();

                        return(Get(vehicleToCreate.LicensePlate));
                    }
                }
                else
                {
                    throw;
                }
            }
        }
예제 #6
0
        public IHttpActionResult GetNewVehicle(int id)
        {
            NewVehicle newVehicle = db.NewVehicles.Find(id);

            if (newVehicle == null)
            {
                return(NotFound());
            }

            return(Ok(newVehicle));
        }
예제 #7
0
        public IHttpActionResult PostNewVehicle(NewVehicle newVehicle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.NewVehicles.Add(newVehicle);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = newVehicle.Id }, newVehicle));
        }
예제 #8
0
        public IHttpActionResult DeleteNewVehicle(int id)
        {
            NewVehicle newVehicle = db.NewVehicles.Find(id);

            if (newVehicle == null)
            {
                return(NotFound());
            }

            db.NewVehicles.Remove(newVehicle);
            db.SaveChanges();

            return(Ok(newVehicle));
        }
        public IActionResult Create(NewVehicle vehicleToCreate)
        {
            Valet   currentValet   = valetDAO.GetByUserId((int)GetCurrentUserId());
            Vehicle createdVehicle = vehicleDAO.Create(vehicleToCreate, currentValet.ValetId);

            if (createdVehicle == null)
            {
                return(BadRequest());
            }
            else
            {
                return(Created("", createdVehicle));
            }
        }
예제 #10
0
 public ActionResult CreatePost([System.Web.Http.FromBody] NewVehicle vehicle)
 {
     return(Redirect(Url.Action(nameof(Index))));
 }