Пример #1
0
        public JsonPatchDocument <ApiTransactionServerRequestModel> CreatePatch(ApiTransactionServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiTransactionServerRequestModel>();

            patch.Replace(x => x.Amount, model.Amount);
            patch.Replace(x => x.GatewayConfirmationNumber, model.GatewayConfirmationNumber);
            patch.Replace(x => x.TransactionStatusId, model.TransactionStatusId);
            return(patch);
        }
Пример #2
0
        public virtual ApiTransactionServerRequestModel MapServerResponseToRequest(
            ApiTransactionServerResponseModel response)
        {
            var request = new ApiTransactionServerRequestModel();

            request.SetProperties(
                response.Amount,
                response.GatewayConfirmationNumber,
                response.TransactionStatusId);
            return(request);
        }
Пример #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALTransactionMapper();
            ApiTransactionServerRequestModel model = new ApiTransactionServerRequestModel();

            model.SetProperties(1m, "A", 1);
            Transaction response = mapper.MapModelToEntity(1, model);

            response.Amount.Should().Be(1m);
            response.GatewayConfirmationNumber.Should().Be("A");
            response.TransactionStatusId.Should().Be(1);
        }
Пример #4
0
        public virtual ApiTransactionServerResponseModel MapServerRequestToResponse(
            int id,
            ApiTransactionServerRequestModel request)
        {
            var response = new ApiTransactionServerResponseModel();

            response.SetProperties(id,
                                   request.Amount,
                                   request.GatewayConfirmationNumber,
                                   request.TransactionStatusId);
            return(response);
        }
Пример #5
0
        public virtual Transaction MapModelToEntity(
            int id,
            ApiTransactionServerRequestModel model
            )
        {
            Transaction item = new Transaction();

            item.SetProperties(
                id,
                model.Amount,
                model.GatewayConfirmationNumber,
                model.TransactionStatusId);
            return(item);
        }
Пример #6
0
        public virtual async Task <CreateResponse <ApiTransactionServerResponseModel> > Create(
            ApiTransactionServerRequestModel model)
        {
            CreateResponse <ApiTransactionServerResponseModel> response = ValidationResponseFactory <ApiTransactionServerResponseModel> .CreateResponse(await this.TransactionModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Transaction record = this.DalTransactionMapper.MapModelToEntity(default(int), model);
                record = await this.TransactionRepository.Create(record);

                response.SetRecord(this.DalTransactionMapper.MapEntityToModel(record));
                await this.mediator.Publish(new TransactionCreatedNotification(response.Record));
            }

            return(response);
        }
Пример #7
0
        public virtual async Task <UpdateResponse <ApiTransactionServerResponseModel> > Update(
            int id,
            ApiTransactionServerRequestModel model)
        {
            var validationResult = await this.TransactionModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Transaction record = this.DalTransactionMapper.MapModelToEntity(id, model);
                await this.TransactionRepository.Update(record);

                record = await this.TransactionRepository.Get(id);

                ApiTransactionServerResponseModel apiModel = this.DalTransactionMapper.MapEntityToModel(record);
                await this.mediator.Publish(new TransactionUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiTransactionServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiTransactionServerResponseModel> .UpdateResponse(validationResult));
            }
        }