public async Task <Tuple <bool, string> > AddReport(ReportWalk report) { var walk = await _dbContext.Walks .Include(w => w.ReportWalks) .Where(w => w.ReportWalks == null || w.ReportWalks.Count == 0) .FirstOrDefaultAsync(r => r.Id == report.WalkId); if (walk == null) { return(new Tuple <bool, string>(false, "report already made or pending walk")); } try { await _dbContext.Reports.AddAsync(report); await _dbContext.SaveChangesAsync(); return(new Tuple <bool, string>(true, "success")); } catch (Exception e) { return(new Tuple <bool, string>(false, e.Message)); } }
public async Task <IActionResult> PostReport([FromBody] ReportWalk report) { var username = User.Claims.Where(c => c.Type == ClaimTypes.Name).FirstOrDefault().Value; var walker = await _repository.GetWalkerByUserName(username); if (!walker.Walks.Select(w => w.Id).Contains(report.WalkId)) { return(BadRequest(new { message = "not your walk" })); } var result = await _repository.AddReport(report); if (!result.Item1) { return(BadRequest(new { message = result.Item2 })); } return(Ok(new { message = result.Item2 })); }