예제 #1
0
 public static MetroLocation GetMetroLocationByMetroLocationID(int MetroLocationID)
 {
     MetroLocation metroLocation = new MetroLocation();
     SqlMetroLocationProvider sqlMetroLocationProvider = new SqlMetroLocationProvider();
     metroLocation = sqlMetroLocationProvider.GetMetroLocationByMetroLocationID(MetroLocationID);
     return metroLocation;
 }
예제 #2
0
        public ActionResult AddMetro(int _Busnumber, string busLines, string CityName, string zone, string Name)
        {
            City city = new City()
            {
                CityName = CityName
            };
            int      cityID   = CheckPostCity(city);
            Stations stations = new Stations()
            {
                Type = "Metro", Name = Name, zone = zone, cityID = cityID
            };
            int stationId = CheckPostStation(stations);

            string[] _Lines = busLines.Split(',');
            for (int i = 0; i < _Lines.Length - 1; i++)
            {
                MetroLocation metro = new MetroLocation();
                metro.MetroNumber = _Busnumber;
                metro.Source      = _Lines[i];
                metro.Destination = _Lines[i + 1];
                metro.stationId   = stationId;

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("http://localhost:65046/");
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                var respond = client.PostAsJsonAsync <MetroLocation>($"Moslah/Metro/CreateMetro", metro).Result;
            }
            return(View("Index"));
        }
예제 #3
0
    public static MetroLocation GetMetroLocationByMetroLocationID(int MetroLocationID)
    {
        MetroLocation            metroLocation            = new MetroLocation();
        SqlMetroLocationProvider sqlMetroLocationProvider = new SqlMetroLocationProvider();

        metroLocation = sqlMetroLocationProvider.GetMetroLocationByMetroLocationID(MetroLocationID);
        return(metroLocation);
    }
예제 #4
0
 public IHttpActionResult Post(MetroLocation metro)//Add new bus
 {
     if (ListOfMetro.FirstOrDefault(m => m.MetroNumber == metro.MetroNumber) == null)
     {
         DB.metroLocations.Add(metro);
         DB.SaveChanges();
         return(Ok());
     }
     return(NotFound());
 }
예제 #5
0
        public IHttpActionResult DeleteMetro(int metroNo)// deleteByBusNo.
        {
            MetroLocation MetroLocation = ListOfMetro.FirstOrDefault(s => s.MetroNumber == metroNo);

            if (MetroLocation == null)
            {
                return(NotFound());
            }
            DB.metroLocations.Remove(MetroLocation);
            DB.SaveChanges();
            return(Ok());
        }
예제 #6
0
    public bool UpdateMetroLocation(MetroLocation metroLocation)
    {
        using (SqlConnection connection = new SqlConnection(this.ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("UpdateMetroLocation", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MetroLocationID", SqlDbType.Int).Value        = metroLocation.MetroLocationID;
            cmd.Parameters.Add("@MetroLocationName", SqlDbType.NVarChar).Value = metroLocation.MetroLocationName;
            cmd.Parameters.Add("@State", SqlDbType.NVarChar).Value             = metroLocation.State;
            connection.Open();

            int result = cmd.ExecuteNonQuery();
            return(result == 1);
        }
    }
예제 #7
0
    public int InsertMetroLocation(MetroLocation metroLocation)
    {
        using (SqlConnection connection = new SqlConnection(this.ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("InsertMetroLocation", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MetroLocationID", SqlDbType.Int).Direction    = ParameterDirection.Output;
            cmd.Parameters.Add("@MetroLocationName", SqlDbType.NVarChar).Value = metroLocation.MetroLocationName;
            cmd.Parameters.Add("@State", SqlDbType.NVarChar).Value             = metroLocation.State;
            connection.Open();

            int result = cmd.ExecuteNonQuery();
            return((int)cmd.Parameters["@MetroLocationID"].Value);
        }
    }
예제 #8
0
        public IHttpActionResult PutMetro(int metronum, MetroLocation metro)//Add new bus
        {
            MetroLocation metroedit = DB.metroLocations.FirstOrDefault(m => m.MetroNumber == metronum);

            if (metroedit == null)
            {
                return(NotFound());
            }
            metroedit.MetroNumber = metro.MetroNumber;
            metroedit.Destination = metro.Destination;
            metroedit.Source      = metro.Source;
            metroedit.Stations    = metro.Stations;
            metroedit.PriceMetro  = metro.PriceMetro;
            DB.SaveChanges();
            return(Ok());
        }
예제 #9
0
    public MetroLocation GetMetroLocationFromReader(IDataReader reader)
    {
        try
        {
            MetroLocation metroLocation = new MetroLocation
                                          (

                DataAccessObject.IsNULL <int>(reader["MetroLocationID"]),
                DataAccessObject.IsNULL <string>(reader["MetroLocationName"]),
                DataAccessObject.IsNULL <string>(reader["State"])
                                          );
            return(metroLocation);
        }
        catch (Exception ex)
        {
            return(null);
        }
    }
예제 #10
0
    public static bool UpdateMetroLocation(MetroLocation metroLocation)
    {
        SqlMetroLocationProvider sqlMetroLocationProvider = new SqlMetroLocationProvider();

        return(sqlMetroLocationProvider.UpdateMetroLocation(metroLocation));
    }
예제 #11
0
    public static int InsertMetroLocation(MetroLocation metroLocation)
    {
        SqlMetroLocationProvider sqlMetroLocationProvider = new SqlMetroLocationProvider();

        return(sqlMetroLocationProvider.InsertMetroLocation(metroLocation));
    }
예제 #12
0
    public MetroLocation GetMetroLocationFromReader(IDataReader reader)
    {
        try
        {
            MetroLocation metroLocation = new MetroLocation
                (

                     DataAccessObject.IsNULL<int>(reader["MetroLocationID"]),
                     DataAccessObject.IsNULL<string>(reader["MetroLocationName"]),
                     DataAccessObject.IsNULL<string>(reader["State"])
                );
             return metroLocation;
        }
        catch(Exception ex)
        {
            return null;
        }
    }
예제 #13
0
    public bool UpdateMetroLocation(MetroLocation metroLocation)
    {
        using (SqlConnection connection = new SqlConnection(this.ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("UpdateMetroLocation", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MetroLocationID", SqlDbType.Int).Value = metroLocation.MetroLocationID;
            cmd.Parameters.Add("@MetroLocationName", SqlDbType.NVarChar).Value = metroLocation.MetroLocationName;
            cmd.Parameters.Add("@State", SqlDbType.NVarChar).Value = metroLocation.State;
            connection.Open();

            int result = cmd.ExecuteNonQuery();
            return result == 1;
        }
    }
예제 #14
0
    public int InsertMetroLocation(MetroLocation metroLocation)
    {
        using (SqlConnection connection = new SqlConnection(this.ConnectionString))
        {
            SqlCommand cmd = new SqlCommand("InsertMetroLocation", connection);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MetroLocationID", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.Parameters.Add("@MetroLocationName", SqlDbType.NVarChar).Value = metroLocation.MetroLocationName;
            cmd.Parameters.Add("@State", SqlDbType.NVarChar).Value = metroLocation.State;
            connection.Open();

            int result = cmd.ExecuteNonQuery();
            return (int)cmd.Parameters["@MetroLocationID"].Value;
        }
    }
예제 #15
0
 public static bool UpdateMetroLocation(MetroLocation metroLocation)
 {
     SqlMetroLocationProvider sqlMetroLocationProvider = new SqlMetroLocationProvider();
     return sqlMetroLocationProvider.UpdateMetroLocation(metroLocation);
 }
예제 #16
0
 public static int InsertMetroLocation(MetroLocation metroLocation)
 {
     SqlMetroLocationProvider sqlMetroLocationProvider = new SqlMetroLocationProvider();
     return sqlMetroLocationProvider.InsertMetroLocation(metroLocation);
 }