コード例 #1
0
ファイル: ErailApi.cs プロジェクト: siddarthkanted/HackTrain
 private void CommonNameValueCollection(NameValueCollection nameValueCollection, Train train)
 {
     nameValueCollection["key"] = "ojxcd2635";
     nameValueCollection["trainno"] = train.TrainRecord.TrainNumber;
     nameValueCollection["stnfrom"] = fromStationCode;
     nameValueCollection["stnto"] = toStationCode;
     nameValueCollection["quota"] = "GN";
     nameValueCollection["date"] = GetNextTrainRunningDate(train);
 }
コード例 #2
0
ファイル: ErailApi.cs プロジェクト: siddarthkanted/HackTrain
 //call http://api.erail.in/seats/?key=API_KEY&trainno=12138&stnfrom=NDLS&stnto=CSTM&quota=GN&class=SL&date=05-SEP-2014
 private void AddSeatAvailability(Train train)
 {
     string url = "http://api.erail.in/seats/";
     var nameValueCollection = new NameValueCollection();
     CommonNameValueCollection(nameValueCollection, train);
     nameValueCollection["class"] = "SL";
     //string response = CallErailApi(url, nameValueCollection);
     string response =
         "{ 'status' : 'OK', 'result' : { 'trainno' : '12138', 'from' : 'NDLS', 'to' : 'BCT', 'cls' : 'SL', 'quota' : 'GN', 'error' : '', 'seats' : [ { 'date' : '10-Sep-14', 'seat' : 'TRAIN DEPARTED' }, { 'date' : '11-Sep-14', 'seat' : 'GNWL91/WL22' }, ] } }";
     train.TrainSeatAvailability = JsonConvert.DeserializeObject<TrainSeatAvailability>(response);
 }
コード例 #3
0
ファイル: ErailApi.cs プロジェクト: siddarthkanted/HackTrain
 //call http://api.erail.in/fare/?key=API_KEY&trainno=12138&stnfrom=NDLS&stnto=CSTM&age=AD&quota=GN&date=05-SEP-2014      
 private void AddTrainFare(Train train)
 {
     string url = "http://api.erail.in/fare/";
     var nameValueCollection = new NameValueCollection();
     CommonNameValueCollection(nameValueCollection, train);
     nameValueCollection["age"] = "AD";
     //string response = CallErailApi(url, nameValueCollection);
     string response =
         "{ 'status' : 'OK', 'result' : { 'trainno' : '12952', 'type' : 'RAJDHANI', 'from' : 'NDLS', 'to' : 'BCT', 'age' : '30', 'quota' : 'GN', 'fare' : [ { 'cls' : '1A', 'fare' : '4680' }, { 'cls' : '2A', 'fare' : '2810' }, { 'cls' : '3A', 'fare' : '2030' } ] } }";
         train.TrainFare = JsonConvert.DeserializeObject<TrainFare>(response);
 }
コード例 #4
0
ファイル: ErailApi.cs プロジェクト: siddarthkanted/HackTrain
        //format dd-MMM-yyyy (ex :05-SEP-2014)
        //if train runs on every monday. Get the date of coming monday.
        private string GetNextTrainRunningDate(Train train)
        {
            DateTime today = DateTime.Today;
            int dayOfWeek = (int) today.DayOfWeek + 1;
            while (true)
            {
                DateTime nextDay = today.AddDays(dayOfWeek);
                if (train.TrainDetails.TrainAttributes.DaysRunning.Day.Contains(nextDay.DayOfWeek.ToString()))
                {
                    break;
                }
                dayOfWeek++;
            }

            DateTime nextTrainRunningDate = today.AddDays(dayOfWeek);
            return nextTrainRunningDate.ToString("dd-MMM-yyyy");
        }