Exemplo n.º 1
0
        public Scheduling Insert(Scheduling entity)
        {
            try
            {
                entity.SchedulingKey = Guid.NewGuid();

                var address = _addressRepository.Get(entity.Address.AddressKey);

                if (address == null)
                {
                    throw new NotFoundException("Address not found");
                }

                var hasScheduling = _schedulingRepository.Exists(entity);

                if (!hasScheduling)
                {
                    entity.Address = address;
                    return(_schedulingRepository.Insert(entity));
                }

                throw new ForbbidenException("Scheduling already exists");
            }
            catch (ForbbidenException ex)
            {
                throw new ForbbidenException($"Not was possible insert the Scheduling: {ex.Message}");
            }
            catch (NotFoundException ex)
            {
                throw new NotFoundException($"Not was possible insert the Scheduling: {ex.Message}");
            }
            catch (Exception ex)
            {
                throw new InternalServerErrorException($"Not was possible insert the Scheduling: {ex.Message}");
            }
        }