Esempio n. 1
0
        public async Task <ActionResult <ServiceRecipientsModel> > GetAllAsync(string orderId)
        {
            var order = await _orderRepository.GetOrderByIdAsync(orderId);

            if (order is null)
            {
                return(NotFound());
            }

            var primaryOrganisationId = User.GetPrimaryOrganisationId();

            if (primaryOrganisationId != order.OrganisationId)
            {
                return(Forbid());
            }

            var serviceRecipients =
                (await _serviceRecipientRepository.ListServiceRecipientsByOrderIdAsync(orderId)).ToList();

            var recipientModelList = serviceRecipients.Select(recipient => new ServiceRecipientModel
            {
                OdsCode = recipient.OdsCode,
                Name    = recipient.Name
            }).ToList();

            var model = new ServiceRecipientsModel
            {
                ServiceRecipients = recipientModelList
            };

            return(model);
        }