示例#1
0
        public async Task <bool> CreateShuttle(Shuttle inputShuttle)
        {
            _shuttleValidator.Validate(inputShuttle);

            var sameIdShuttles = await _repository.GetAllShuttles(
                new ShuttleFilter { Ids = new List <Guid>()
                                    {
                                        inputShuttle.Id
                                    } });

            if (sameIdShuttles.Any())
            {
                throw new CrewApiException
                      {
                          ExceptionMessage = $"Shuttle with id {inputShuttle.Id} exists in the repository !",
                          Severity         = ExceptionSeverity.Error,
                          Type             = ExceptionType.ServiceException
                      }
            }
            ;

            var sameNameShuttles = await _repository.GetAllShuttles(
                new ShuttleFilter { ToSearch = inputShuttle.Name, PerfectMatch = true });

            if (sameNameShuttles.Any())
            {
                throw new CrewApiException
                      {
                          ExceptionMessage = $"Shuttle name {inputShuttle.Name} is not unique !",
                          Severity         = ExceptionSeverity.Error,
                          Type             = ExceptionType.ServiceException
                      }
            }
            ;

            return(await _repository.CreateShuttle(inputShuttle));
        }