private async Task <TestUtilityHeader> RegisterTransaction(TestUtilityHeader testResult, string url) { try { using (HttpClient client = new HttpClient()) { var data = JsonConvert.SerializeObject(testResult); StringContent request = new StringContent(data, Encoding.UTF8, "application/json"); string endpoint = url + "api/UtilityApp/RegisterTransaction"; //url + "api/Utility/WriteTransactionLoad"; //client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "50185b70341b4f5aa5e1d3307a261798"); using (var Response = await client.PostAsync(endpoint, request)) { if (Response.StatusCode == System.Net.HttpStatusCode.OK) { string content = await Response.Content.ReadAsStringAsync(); string header = JsonConvert.DeserializeObject(content).ToString(); testResult = JsonConvert.DeserializeObject <TestUtilityHeader>(header); return(testResult); } else { return(testResult); } } } } catch (Exception ex) { throw ex; } }
public async Task <TestUtilityHeader> RegisterTransaction(TestUtilityHeader header) { try { var lastBatch = _db.TestUtilityHeader.AsNoTracking().Where(x => x.PartnerId == header.PartnerId).OrderByDescending(x => x.Id).FirstOrDefault(); if (lastBatch == null) { header.Batch = "89" + DateTime.UtcNow.ToString("yy") + header.PartnerId.ToString().PadLeft(3, '0') + "00001"; } else { if (!string.IsNullOrWhiteSpace(lastBatch.Batch)) { string number = lastBatch.Batch.ToString(); string lastFive = number.Substring(number.Length - 5); int newNumber = Convert.ToInt32(lastFive) + 1; header.Batch = "89" + DateTime.UtcNow.ToString("yy") + header.PartnerId.ToString().PadLeft(3, '0') + newNumber.ToString().PadLeft(5, '0'); } else { header.Batch = "89" + DateTime.UtcNow.ToString("yy") + header.PartnerId.ToString().PadLeft(3, '0') + "00001"; } } _db.TestUtilityHeader.Add(header); int count = await _db.SaveChangesAsync(); return(header); } catch (Exception ex) { throw ex; } }
public async Task <TestUtilityHeader> RegisterTransaction([FromBody] TestUtilityHeader testUtilityHeader) { try { var result = await _utilityService.RegisterTransaction(testUtilityHeader); return(result); } catch (Exception ex) { throw ex; } // return false; }
public async Task <bool> WriteTransaction(List <TestUtilityLoadTestDetail> details) { try { _db.TestUtilityLoadTestDetail.AddRange(details); int count = await _db.SaveChangesAsync(); if (count > 0) { TestUtilityHeader header = _db.TestUtilityHeader.FirstOrDefault(x => x.Id == details.FirstOrDefault().HdrId); header.SuccessCount = details.Count(x => x.IsConfirmed); header.FailureCount = details.Count(x => !x.IsConfirmed); _db.Update <TestUtilityHeader>(header); _db.SaveChanges(); } return(count > 0); } catch (Exception ex) { throw ex; } }