public async Task <IActionResult> UnlockSeat() { var unlockSeatParams = new UnlockSeatParams { SaleId = 1, TrainNumber = 1, MoveDate = new DateTime(2019, 12, 19, 00, 00, 00) }; var token = (await _db.AuthTokens.ToListAsync()).SingleOrDefault(); if (await _fadakTrainApi.ValidateTokenWithRequestAsync(token.Value, Company.Fadak)) { var res = await _fadakTrainApi.UnlockSeatAsync(token.Value, unlockSeatParams, 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="unlockSeatParams"></param> /// <param name="company"></param> /// <returns></returns> public async Task <ServiceResult <EmptyResult> > UnlockSeatAsync(string authToken, UnlockSeatParams unlockSeatParams, Company company) { var result = new ServiceResult <EmptyResult>(); _http.DefaultRequestHeaders.Clear(); _http.DefaultRequestHeaders.Add("Authorization", Constants.PreToken + authToken); _content = new StringContent( JsonConvert.SerializeObject(unlockSeatParams), UTF8Encoding.UTF8, "application/json"); _response = await _http.PostAsync(company.ToBaseUrl(ApiUrl.UnlockSeat), _content); if (_response.IsSuccessStatusCode) { var res = JsonConvert.DeserializeObject <IrTrainResult <EmptyResult> >(await _response.Content.ReadAsStringAsync()); error = res.ExceptionId.GetSystemErrorMessage(res.ExceptionMessage); if (res.ExceptionId == 0 && res.ExceptionMessage == null) { 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); }