コード例 #1
0
        public async Task Execute(int serviceId, UserClaims userClaims)
        {
            if (userClaims.UserRole == "Admin")
            {
                LambdaLogger.Log($"User role is admin, delete serviceId {serviceId}");
                await _servicesGateway.DeleteService(serviceId).ConfigureAwait(false);
            }
            else
            {
                var service = await _servicesGateway.GetServiceAsync(serviceId).ConfigureAwait(false);

                var user = await _usersGateway.GetUserByIdAsync(userClaims.UserId).ConfigureAwait(false);

                var orgs = user.UserOrganisations.Where(x => x.OrganisationId == service.OrganisationId).ToList();
                if (orgs.Count == 0)
                {
                    LambdaLogger.Log($"UserId {userClaims.UserId} is not in Organisation {service.OrganisationId} for serviceId {serviceId}");
                    throw new UseCaseException
                          {
                              UserErrorMessage = $"Could not delete service with an ID of '{serviceId}'",
                          };
                }
                else
                {
                    LambdaLogger.Log($"UserId {userClaims.UserId} is in Organisation {service.OrganisationId} for serviceId {serviceId} so service can be deleted");
                    await _servicesGateway.DeleteService(serviceId).ConfigureAwait(false);
                }
            }
        }
コード例 #2
0
        public async Task <ServiceResponse> Execute(int serviceId)
        {
            var serviceDomain = await _servicesGateway.GetServiceAsync(serviceId).ConfigureAwait(false);

            if (serviceDomain == null)
            {
                throw new UseCaseException()
                      {
                          UserErrorMessage = $"Could not retrieve the service with an ID of '{serviceId}'",
                      }
            }
            ;

            return(serviceDomain.ToResponse());
        }