public async Task <IResponse> AddAsync(string requestId, SModel SaveModel, CancellationToken cancellationToken = default(CancellationToken))
        {
            MethodBase m = MethodBase.GetCurrentMethod();

            _logger.LogInformation(ServiceResource.ServiceStart, m.Name, requestId);

            //Check for NUll
            if (SaveModel == null)
            {
                throw new ArgumentNullException("SaveModel");
            }

            //Do Validator
            var validationResult = _validator.Validate(SaveModel);

            if (!validationResult.IsValid)
            {
                _logger.LogInformation(ServiceResource.ServiceValidationError, m.Name, requestId);

                return(new ValidationErrorsReponse(requestId, "Save Model Validation Failure.",
                                                   validationResult.Errors.Select(e => new ValidationError(e.PropertyName, e.ErrorMessage)).ToList()));
            }


            try
            {
                TEntity entity = Mapper.Map <SModel, TEntity>(SaveModel);
                await _repository.AddAsync(requestId, entity);

                await _unitOfWork.SaveAsync(requestId, cancellationToken);

                _logger.LogInformation(ServiceResource.ServiceEnd, m.Name, requestId);
                return(new SuccessResponse(requestId)
                {
                    Success = true
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(
                    new EventId(ServiceError.DataUpdateServiceError.Code, ServiceError.DataUpdateServiceError.Error), ex,
                    _localizer[ServiceResource.ServiceError], m.Name, requestId);

                return(new ServiceErrorReponse(requestId)
                {
                    Message = ex.Message, ServiceErrors = new[] { ServiceError.DataUpdateServiceError }
                });
            }
        }
Esempio n. 2
0
        public async Task <ConfirmationAchatViewModel> PostTicketAsync(BuyTicketViewModel buyTicketViewModel)
        {
            ConfirmationAchatViewModel vm = new ConfirmationAchatViewModel();

            vm.DateAchat = DateTime.Now;
            Ticket ticket = null;

            try
            {
                ticket = await _unitOfWorkAsync.TicketRepositoryAsync.AddTicketAsync(buyTicketViewModel.Course.CourseId, buyTicketViewModel.AcheteurSelectionne, buyTicketViewModel.NbPlaces);

                await _unitOfWorkAsync.SaveAsync();

                vm.EstEnregistre = (ticket != null);

                vm.Course = buyTicketViewModel.Course;
            }
            catch (Exception)
            {
                vm.EstEnregistre = false;
            }

            if (vm.EstEnregistre)
            {
                vm.Message   = "Nous avons pré-enregistré votre achat. Vous devez attendre sa confirmation par email pour qu'il soit définitif";
                vm.NbTickets = ticket.NbPlaces;
            }
            else
            {
                vm.Message = "Il n'a pas été possible d'enregistrer votre achat";
            }
            return(vm);
        }
Esempio n. 3
0
        public async Task SetBetAsync(int idCourse, int idConcurrent)
        {
            await _unitOfWorkAsync.CompetitorRepositoryAsync.SetBetAsync(idCourse, idConcurrent);

            await _unitOfWorkAsync.SaveAsync();
        }