Пример #1
0
        public async Task <ActionResult> GetConsumptionByConsumptionId(HttpRequest req, string consumptionId)
        {
            if (!int.TryParse(consumptionId, out int id))
            {
                return(new BadRequestObjectResult(Messages.ErrorIncorrectId));
            }

            ConsumptionView targetConsumption = await consumptionRepository.GetConsumptionByConsumptionId(id);

            // Auth check
            if (!await Authorised(req, targetConsumption.PatientId, true))
            {
                return(new BadRequestObjectResult(Messages.AuthNoAcces));
            }

            var consumptionJson = JsonConvert.SerializeObject(targetConsumption);

            return(consumptionJson != null && targetConsumption.ConsumptionId != 0
                ? (ActionResult) new OkObjectResult(consumptionJson)
                : new BadRequestObjectResult(Messages.ErrorIncorrectId));
        }