public async Task <Model.Training> AddAsync(Model.Training training)
        {
            if (training == null)
            {
                throw new ArgumentNullException(nameof(training));
            }

            var model = _mapper.Map <DA.Model.Training>(training);
            var added = await _repository.AddAsync(model);

            return(_mapper.Map <BL.Model.Training>(added));
        }
        public async Task <SaveTrainingResponse> SaveAsync(Training Training)
        {
            try
            {
                await _trainingRepository.AddAsync(Training);

                await _unitOfWork.CompleteAsync();

                return(new SaveTrainingResponse(Training));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new SaveTrainingResponse($"An error occurred when saving the Training: {ex.Message}"));
            }
        }
Exemple #3
0
        //CRUD
        public async Task <TrainingResponse> SaveAsync(Training training)
        {
            if (_coordinatorRepository.FindById(training.CoordinatorId) != null)
            {
                try
                {
                    await _trainingRepository.AddAsync(training);

                    await _unitOfWork.CompleteAsync();

                    return(new TrainingResponse(training));
                }
                catch (Exception e)
                {
                    return(new TrainingResponse($"An error ocurred while saving {e.Message}"));
                }
            }
            else
            {
                return(new TrainingResponse($"The coordinator with id {training.CoordinatorId}, doesn't exist"));
            }
        }
Exemple #4
0
 public async Task <Training> AddToRepositoryAsync(Training training)
 {
     ValidateTraining(training);
     return(await repository.AddAsync(training));
 }