public async Task <SnowReport> Post([FromBody] SnowReportContract clientReport) { var report = clientReport.ToDomain(); ValidationResult vld = await ValidatorSvc.ValidateSnowReport(report); if (!vld.Success) { Response.StatusCode = 400; var jsonString = JsonConvert.SerializeObject(vld); Response.ContentType = new MediaTypeHeaderValue("application/json").ToString(); await Response.WriteAsync(jsonString, Encoding.UTF8); return(null); } SnowReport rtn = await UserReportsSvc.SaveSnowReport(report); //this happens if the given poster has already provided a report for the day //TODO: handle this more elegantly if (rtn == null) { Response.StatusCode = 204; var jsonString = "{\"message\":\"You have already submitted a report for today.\"}"; Response.ContentType = new MediaTypeHeaderValue("application/json").ToString(); await Response.WriteAsync(jsonString, Encoding.UTF8); return(null); } return(rtn); }
public async Task <ValidationResult> ValidateSnowReport(SnowReport report) { //see comments above ValidationResult rtn = new ValidationResult(); var baseResult = this.ValidateEntity <ReportBase>(report as ReportBase); var coreResult = this.ValidateEntity <SnowReport>(report); await Task.WhenAll(baseResult, coreResult); rtn.AddValidationResults(new ValidationResult[2] { baseResult.Result, coreResult.Result }); return(rtn); }
public Task <SnowReport> SaveSnowReport(SnowReport report) { return(this.SaveReport <SnowReport>(report)); }
public async Task <SnowReport> Get(long id) { SnowReport report = await UserReportsSvc.GetSnowReport(id); return(report); }