public async Task <IActionResult> PostCommentsAsync( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "PC269_PostComments/{dailyReportTotalId}")] HttpRequest req, int dailyReportTotalId, CancellationToken cts, ILogger log) { log.LogInformation("PC269 post comments request received"); DailyReportsTotal dailyReportTotal = _context.DailyReportsTotal.FirstOrDefault(b => b.DailyreportId == dailyReportTotalId); // Fix handling of field name main_events ... //List<Comments> newComments = JsonConvert.DeserializeObject<List<Comments>>(await new StreamReader(req.Body).ReadToEndAsync()); dynamic newComments = JsonConvert.DeserializeObject(await new StreamReader(req.Body).ReadToEndAsync()); List <Comments> newCommentsList = PC269Mappings.ObjectToCommentsList(newComments, dailyReportTotalId); foreach (Comments commentElement in newCommentsList) { await _context.Comments.AddAsync(commentElement, cts); await _context.SaveChangesAsync(cts); } return(new OkObjectResult("ok")); }
public async Task <IActionResult> PostDailyReportAsync( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "PC269_PostDailyReportTotal/{assetId}")] HttpRequest req, int assetId, CancellationToken cts, ILogger log) { log.LogInformation("PC269 post daily report request received"); Assets assetInfo = _context.Assets.FirstOrDefault(b => b.AssetId == assetId); if (assetInfo != null) { dynamic newDailyReport = JsonConvert.DeserializeObject(await new StreamReader(req.Body).ReadToEndAsync()); newDailyReport.asset_Id = assetId; DailyReportsTotal dailyReportTotal = PC269Mappings.ObjectToDailyReportsTotal(newDailyReport, assetId, 1); var entity = await _context.DailyReportsTotal.AddAsync(dailyReportTotal, cts); await _context.SaveChangesAsync(cts); // returns the id of the daily report total return(new OkObjectResult(JsonConvert.SerializeObject(entity.Entity.DailyreportId))); } else { log.LogWarning("Trying to insert daily report with invalid asset id"); return(new UnprocessableEntityObjectResult(new { error = "AssetId does not exist, report not inserted" })); } }
public async Task <IActionResult> PostWellTestAsync( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "PC269_PostWellTest/{dailyReportTotalId}")] HttpRequest req, int dailyReportTotalId, CancellationToken cts, ILogger log) { log.LogInformation("PC269 post well test request received"); DailyReportsTotal dailyReportTotal = _context.DailyReportsTotal.FirstOrDefault(b => b.DailyreportId == dailyReportTotalId); dynamic newWellTest = JsonConvert.DeserializeObject(await new StreamReader(req.Body).ReadToEndAsync()); List <WellTests> WellTestList = PC269Mappings.ObjectToWellTestList(newWellTest, dailyReportTotalId); foreach (WellTests wellTest in WellTestList) { await _context.WellTests.AddAsync(wellTest, cts); await _context.SaveChangesAsync(cts); } return(new OkObjectResult("ok")); }
public async Task <IActionResult> PostDailyProductionWellsAsync( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "PC269_PostDailyProductionWells/{dailyReportTotalId}")] HttpRequest req, int dailyReportTotalId, CancellationToken cts, ILogger log) { log.LogInformation("PC269 post daily production wells request received"); DailyReportsTotal dailyReportTotal = _context.DailyReportsTotal.FirstOrDefault(b => b.DailyreportId == dailyReportTotalId); dynamic newDailyProductionWells = JsonConvert.DeserializeObject(await new StreamReader(req.Body).ReadToEndAsync()); List <DailyProductionWells> DailyProductionWellsList = PC269Mappings.ObjectToDailyProductionWellsList(newDailyProductionWells, dailyReportTotalId); foreach (DailyProductionWells dailyProductionWell in DailyProductionWellsList) { await _context.DailyProductionWells.AddAsync(dailyProductionWell, cts); await _context.SaveChangesAsync(cts); } // Return more details... return(new OkObjectResult("ok")); }