Beispiel #1
0
        public async Task <Result <Exception, Guid> > Handle(CreateCommand request, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <Scheduling>(request);

            foreach (var serviceProvidedId in request.ProvidedServices)
            {
                var providedServiceCallback = await _providedServiceRepository.GetByIdAsync(serviceProvidedId);

                if (providedServiceCallback.IsSuccess)
                {
                    entity.ProvidedServices.Add(providedServiceCallback.Success);
                }
            }

            var employeeCallback = await _employeeRepository.GetByIdAsync(request.EmployeeId);

            if (employeeCallback.IsFailure)
            {
                return(new Exception());
            }

            var entityCreated = await _repository.CreateAsync(entity);

            if (entityCreated.IsFailure)
            {
                return(entityCreated.Failure);
            }

            return(entityCreated.Success.Id);
        }