public Task <ReportQrCodeExchange> RequestQRcodesReceiving(string url, Dictionary <string, string> requestDataDict) { ReportQrCodeExchange reportQrCodeExchange = new ReportQrCodeExchange(); ResponseMessageDataQRCode responseData = null; try { responseData = SendRequestAsync(url, requestDataDict, "").Result; } catch (Exception ex) { Console.WriteLine(ex.Message); } if (responseData != null) { if (responseData.status.Equals("200") || responseData.status.Equals("OK")) { try { ResponseMessageDataQRCodeSuccessfully responseMessageDataQRCodeSuccessfully = (ResponseMessageDataQRCodeSuccessfully)responseData; reportQrCodeExchange = _servicesQRcodes.CheckQrCodes(responseMessageDataQRCodeSuccessfully); } catch { ResponseMessageDataQRCodeError responseMessageDataQRCodeError = (ResponseMessageDataQRCodeError)responseData; foreach (string str in responseMessageDataQRCodeError.items) { responseMessageDataQRCodeError.items.Append(str); } reportQrCodeExchange.error = responseData.error; reportQrCodeExchange.status = responseData.status; reportQrCodeExchange.dateTimeRequest = responseData.date; } } else { reportQrCodeExchange.error = responseData.error; reportQrCodeExchange.status = responseData.status; reportQrCodeExchange.dateTimeRequest = responseData.date; return(Task.FromResult(reportQrCodeExchange)); } } return(Task.FromResult(reportQrCodeExchange)); }
public async Task <IActionResult> RequestQRcodesReceiving([FromBody] DateTimeDTO dateTimeStr) { string url = "https://etsa.online/app/api/barcodes/get.php"; ReportQrCodeExchange reportQrCodeExchange = new ReportQrCodeExchange(); ResponseMessageDataQRCode responseData = null; string dateTimeNow; string dateTimeTo; DateTime dateTimeFront; DateTime dateTimeFrontTo; if (dateTimeStr != null && dateTimeStr.Date != null && !dateTimeStr.Date.Equals("") && dateTimeStr.Time != null && !dateTimeStr.Time.Equals("") && dateTimeStr.DateTo != null && dateTimeStr.TimeTo != null) { String[] date = dateTimeStr.Date.Split('-'); string[] time = dateTimeStr.Time.Split(':'); String[] dateTo = dateTimeStr.DateTo.Split('-'); string[] timeTo = dateTimeStr.TimeTo.Split(':'); dateTimeFront = new DateTime(Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(date[2]), Convert.ToInt32(time[0]), Convert.ToInt32(time[1]), 00); string month = dateTimeFront.Month.ToString().Length < 2 ? "0" + dateTimeFront.Month.ToString() : dateTimeFront.Month.ToString(); string day = dateTimeFront.Day.ToString().Length < 2 ? "0" + dateTimeFront.Day.ToString() : dateTimeFront.Day.ToString(); string houre = dateTimeFront.Hour.ToString().Length < 2 ? "0" + dateTimeFront.Hour.ToString() : dateTimeFront.Hour.ToString(); string minute = dateTimeFront.Minute.ToString().Length < 2 ? "0" + dateTimeFront.Minute.ToString() : dateTimeFront.Minute.ToString(); dateTimeNow = dateTimeFront.Year.ToString() + "-" + month + "-" + day + " " + houre + ":" + minute + ":" + "00"; dateTimeFrontTo = new DateTime(Convert.ToInt32(dateTo[0]), Convert.ToInt32(dateTo[1]), Convert.ToInt32(dateTo[2]), Convert.ToInt32(timeTo[0]), Convert.ToInt32(timeTo[1]), 00); string monthTo = dateTimeFrontTo.Month.ToString().Length < 2 ? "0" + dateTimeFront.Month.ToString() : dateTimeFront.Month.ToString(); string dayTo = dateTimeFrontTo.Day.ToString().Length < 2 ? "0" + dateTimeFrontTo.Day.ToString() : dateTimeFrontTo.Day.ToString(); string houreTo = dateTimeFrontTo.Hour.ToString().Length < 2 ? "0" + dateTimeFrontTo.Hour.ToString() : dateTimeFrontTo.Hour.ToString(); string minuteTo = dateTimeFrontTo.Minute.ToString().Length < 2 ? "0" + dateTimeFrontTo.Minute.ToString() : dateTimeFrontTo.Minute.ToString(); dateTimeTo = dateTimeFrontTo.Year.ToString() + "-" + monthTo + "-" + dayTo + " " + houreTo + ":" + minuteTo + ":" + "00"; //dateTimeTo = dateTimeFrontTo.ToString("yyyy-MM-dd hh:mm:ss"); } else { DateTime dateTimeUTC = DateTime.UtcNow; dateTimeNow = dateTimeUTC.AddHours(3).ToString("yyyy-MM-dd hh:mm:ss"); dateTimeTo = ""; } Dictionary <string, string> requestMessageDict = new Dictionary <string, string> { ["token"] = "N2U1OThkZDZkZDliZGFiM/lAfhoRNk0D+iJh2Z1h1fpYEUWXkzsbvGg1", ["date"] = dateTimeNow, ["to"] = dateTimeTo }; //try //{ // string jsonRequest = JsonSerializer.Serialize(requestMessage); // string jsonResponseData = await PostRequestHttpAsync(url, jsonRequest); // responseData = JsonSerializer.Deserialize<ResponseMessageDataQRCode>(jsonResponseData); //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //} try { //string jsonResponseData = await PostRequestFormAsync(url, requestMessageDict); //responseData = JsonSerializer.Deserialize<ResponseMessageDataQRCode>(jsonResponseData); responseData = await PostRequestFormAsync(url, requestMessageDict, ""); } catch (Exception ex) { Console.WriteLine(ex.Message); } if (responseData != null) { if (responseData.status.Equals("200") || responseData.status.Equals("OK")) { try { ResponseMessageDataQRCodeSuccessfully responseMessageDataQRCodeSuccessfully = (ResponseMessageDataQRCodeSuccessfully)responseData; reportQrCodeExchange = CheckQrCodes(responseMessageDataQRCodeSuccessfully); }catch { ResponseMessageDataQRCodeError responseMessageDataQRCodeError = (ResponseMessageDataQRCodeError)responseData; foreach (string str in responseMessageDataQRCodeError.items) { responseMessageDataQRCodeError.items.Append(str); } reportQrCodeExchange.error = responseData.error; reportQrCodeExchange.status = responseData.status; reportQrCodeExchange.dateTimeRequest = responseData.date; } } else { reportQrCodeExchange.error = responseData.error; reportQrCodeExchange.status = responseData.status; reportQrCodeExchange.dateTimeRequest = responseData.date; return(Ok(reportQrCodeExchange)); } } List <Item> items = new List <Item>(); items.Add(reportQrCodeExchange.foundQRcodes.Last()); reportQrCodeExchange.foundQRcodes.Clear(); reportQrCodeExchange.foundQRcodes = items; return(Ok(reportQrCodeExchange)); }