public async Task <IActionResult> GetWagonAvailableSeatCountAsync() { var getWagonAvailableSeatCountParams = new GetWagonAvailableSeatCountParams { FromStation = 1, ToStation = 191, GoingDate = DateTime.Now.AddDays(3), ReturnDate = DateTime.Now.AddDays(5), Gender = (int)Gender.Family, //کوپه دربست ExclusiveCompartment = false, AdultsCount = 1, ChildrenCount = 0, InfantsCount = 0 }; var token = (await _db.AuthTokens.ToListAsync()).SingleOrDefault(); if (await _fadakTrainApi.ValidateTokenWithRequestAsync(token.Value, Company.Fadak)) { var res = await _fadakTrainApi.GetWagonAvailableSeatCountAsync(token.Value, getWagonAvailableSeatCountParams, Company.Fadak); if (res.Status) { return(Ok(res)); } else { if (res.Unauthorized) { //login again return(Unauthorized(res)); } else { return(BadRequest(res)); } } } else { return(Unauthorized("دوباره لاگین کنید"));; } }
/// <summary> /// /// </summary> /// <param name="authToken"></param> /// <param name="getWagonAvailableSeatCountParams"></param> /// <param name="company"></param> /// <returns></returns> public async Task <ServiceResult <GetWagonAvailableSeatCountResult> > GetWagonAvailableSeatCountAsync(string authToken, GetWagonAvailableSeatCountParams getWagonAvailableSeatCountParams, Company company) { var result = new ServiceResult <GetWagonAvailableSeatCountResult>(); _http.DefaultRequestHeaders.Clear(); _http.DefaultRequestHeaders.Add("Authorization", Constants.PreToken + authToken); _content = new StringContent( JsonConvert.SerializeObject(getWagonAvailableSeatCountParams), UTF8Encoding.UTF8, "application/json"); _response = await _http.PostAsync(company.ToBaseUrl(ApiUrl.GetWagonAvailableSeatCount), _content); if (_response.IsSuccessStatusCode) { var res = JsonConvert.DeserializeObject <IrTrainResult <GetWagonAvailableSeatCountResult> >(await _response.Content.ReadAsStringAsync()); error = res.ExceptionId.GetSystemErrorMessage(res.ExceptionMessage); if (res.ExceptionId == 0 && res.ExceptionMessage == null) { res.Result.GoingResults.OrEmpty().ToList().ForEach(p => { p.MoveDate = new DateTime(p.MoveDate.Year, p.MoveDate.Month, p.MoveDate.Day, Convert.ToInt32(p.ExitTime.Split(':')[0]), Convert.ToInt32(p.ExitTime.Split(':')[1]), Convert.ToInt32(p.ExitTime.Split(':')[2])).ToUniversalTime(); }); res.Result.ReturnResults.OrEmpty().ToList().ForEach(p => { p.MoveDate = new DateTime(p.MoveDate.Year, p.MoveDate.Month, p.MoveDate.Day, Convert.ToInt32(p.ExitTime.Split(':')[0]), Convert.ToInt32(p.ExitTime.Split(':')[1]), Convert.ToInt32(p.ExitTime.Split(':')[2])).ToUniversalTime(); }); result.Status = true; result.Result = res.Result; } else { result.Status = false; result.Message = error; } } else if (_response.StatusCode == HttpStatusCode.Unauthorized) { result.Status = false; result.Unauthorized = true; result.Message = "مشکل در اعتبار سنجی دوباره لاگین کنید"; } else { result.Status = false; result.Message = error; } return(result); }