Beispiel #1
0
        public ResponseModel MapToDestination <TCollectionType>(object source)
        {
            var response = new ResponseModel();

            if (source == null)
            {
                response.Success      = false;
                response.Data         = null;
                response.TotalRecords = 0;
            }
            else if (source.GetType() != typeof(Result))
            {
                var mapper = MapperModelFactory <T, object> .GetMapper();

                var result = source as T;
                var model  = mapper.MapToDestination(result);
                response.Data = model;

                var genericType = model.GetType().GetGenericTypeDefinition();
                if (genericType == typeof(List <>) || genericType == typeof(IEnumerable <>))
                {
                    response.TotalRecords = (model as IEnumerable <TCollectionType> ?? new List <TCollectionType>()).Count();
                }
            }
            else
            {
                var result = source as Result;
                response.Data         = result;
                response.Success      = false;
                response.ErrorMessage = ErrorResponse.GetErrorDetail(ErrorCode.HasLogicError);
                response.ErrorCode    = ((int)ErrorCode.HasLogicError).ToString();
            }

            return(response);
        }
Beispiel #2
0
        public async Task <object> ProcessAction(object value)
        {
            var model = value as PaymentsFilter ?? throw new ArgumentNullException(value.GetType().ToString(), "The value is not implemented.");

            _log.LogInformation($"[Started] Get Payments for: UserId: {model.UserId}");

            var mapper = MapperModelFactory <PaymentsFilter, CoreModel.PaymentsFilter> .GetMapper();

            var modelMap = mapper.MapToDestination(model);

            var validation = await _validationService.ProcessValidation(_validator, modelMap);

            var result = validation as Result;

            if (result?.StatusCode == StatusCode.Failed)
            {
                _log.LogError(result.ErrorCode.ConvertToInt(), GetMessage(result, modelMap));
                return(result);
            }

            var resultModel = _repository.GetMongoQueryable().GetPaymentsQueryable(modelMap).ToList();

            _log.LogInformation($"[Finished] Get Payments for: UserId: {modelMap.UserId}");

            return(resultModel);
        }
Beispiel #3
0
        public ResponseModel MapToDestination(object source)
        {
            var response = new ResponseModel();

            if (source == null)
            {
                response.Success      = false;
                response.Data         = null;
                response.TotalRecords = 0;
            }
            else if (source.GetType() != typeof(Result))
            {
                var mapper = MapperModelFactory <T, object> .GetMapper();

                var result = source as T;
                var model  = mapper.MapToDestination(result);
                response.Data = model;
            }
            else
            {
                var result = source as Result;
                response.Data         = result;
                response.Success      = false;
                response.ErrorMessage = ErrorResponse.GetErrorDetail(ErrorCode.HasLogicError);
                response.ErrorCode    = ((int)ErrorCode.HasLogicError).ToString();
            }

            return(response);
        }
Beispiel #4
0
        public async Task <object> ProcessAction(object value)
        {
            var payment = value as Model.Payment ?? throw new ArgumentNullException(value.GetType().ToString(), "The value is not implemented.");

            _log.LogInformation($"[Started] Payment process for Payment: {payment.PaymentId} - User: {payment.UserId}");
            var mapper = MapperModelFactory <Model.Payment, payment_gateway_repository.Model.Payment> .GetMapper();

            var model = mapper.MapToDestination(payment);

            var validator = await _validationService.ProcessValidation(_validator, model);

            var result = validator as Result;

            if (result?.StatusCode == StatusCode.Failed)
            {
                _log.LogError(result.ErrorCode.ConvertToInt(), GetMessage(result, model));
                return(result);
            }

            //Process the bank payment
            result = new ProcessPayment(_bankProcessor, model).Process();
            if (result?.StatusCode == StatusCode.Failed)
            {
                _log.LogError(result.ErrorCode.ConvertToInt(), GetMessage(result, model));
                return(result);
            }

            //Save the transaction in DB
            var saved = await _repository.AddItemAsync(model);

            result = new NoSavedToStorage(saved, "Payment").Process();
            if (result?.StatusCode == StatusCode.Failed)
            {
                _log.LogCritical(result.ErrorCode.ConvertToInt(), GetMessage(result, model));
                return(result);
            }

            _log.LogInformation($"[Finished] Payment process for Payment: {payment.PaymentId} - User: {payment.UserId}");

            return(model);
        }
Beispiel #5
0
        public async Task <object> ProcessAction(object value)
        {
            var model = value as Model.User ?? throw new ArgumentNullException(value.GetType().ToString(), "The value is not implemented.");

            _log.LogInformation($"[Started] User Registration for: UserId: {model.UserId} - Username: {model.UserLogin.Username}");

            var mapper = MapperModelFactory <Model.User, payment_gateway_repository.Model.User> .GetMapper();

            var modelMap = mapper.MapToDestination(model);

            //For a User and in order to make a payment has to be registered in the system so we can process the data
            var token = _userService.Authenticate(modelMap, false);

            modelMap.UserLogin.Token = token;

            var validation = await _validationService.ProcessValidation(_validator, modelMap);

            var result = validation as Result;

            if (result?.StatusCode == StatusCode.Failed)
            {
                _log.LogError(result.ErrorCode.ConvertToInt(), GetMessage(result, modelMap));
                return(result);
            }

            var saved = await _userRepository.AddItemAsync(modelMap);

            result = new NoSavedToStorage(saved, "User").Process();
            if (result?.StatusCode == StatusCode.Failed)
            {
                _log.LogCritical(result.ErrorCode.ConvertToInt(), GetMessage(result, modelMap));
                return(result);
            }

            _log.LogInformation($"[Finished] User Registration for: UserId: {model.UserId} - Username: {model.UserLogin.Username}");

            return(modelMap);
        }