public async Task <ActionResult> GetConsumptionsForPatientBetweenDates(HttpRequest req) { DateTime startDate; DateTime endDate; string patientIdString; try { patientIdString = req.Query["patientId"]; startDate = DateTime.ParseExact(req.Query["startDate"], "yyyy-MM-dd", CultureInfo.InvariantCulture); endDate = DateTime.ParseExact(req.Query["endDate"], "yyyy-MM-dd", CultureInfo.InvariantCulture); } catch (FormatException) { return(new BadRequestObjectResult(Messages.ErrorInvalidDateValues)); } catch (Exception) { return(new BadRequestObjectResult(Messages.ErrorMissingValues)); } if (!int.TryParse(patientIdString, out int patientId)) { return(new BadRequestObjectResult(Messages.ErrorIncorrectId)); } // Auth check if (!await Authorised(req, patientId, true)) { return(new BadRequestObjectResult(Messages.AuthNoAcces)); } PatientConsumptionsView consumptions = new PatientConsumptionsView(await consumptionRepository.GetConsumptionsForPatientBetweenDates(patientId, startDate, endDate)); var consumptionJson = JsonConvert.SerializeObject(consumptions); return(consumptionJson != null ? (ActionResult) new OkObjectResult(consumptionJson) : new BadRequestObjectResult(Messages.ErrorIncorrectId)); }