示例#1
0
        public virtual ApiTransactionServerResponseModel MapEntityToModel(
            Transaction item)
        {
            var model = new ApiTransactionServerResponseModel();

            model.SetProperties(item.Id,
                                item.Amount,
                                item.ArtistId,
                                item.DateCreated,
                                item.StripeTransactionId);
            if (item.ArtistIdNavigation != null)
            {
                var artistIdModel = new ApiArtistServerResponseModel();
                artistIdModel.SetProperties(
                    item.ArtistIdNavigation.Id,
                    item.ArtistIdNavigation.AspNetUserId,
                    item.ArtistIdNavigation.Bio,
                    item.ArtistIdNavigation.ExternalId,
                    item.ArtistIdNavigation.Facebook,
                    item.ArtistIdNavigation.Name,
                    item.ArtistIdNavigation.SoundCloud,
                    item.ArtistIdNavigation.Twitter,
                    item.ArtistIdNavigation.Venmo,
                    item.ArtistIdNavigation.Website);

                model.SetArtistIdNavigation(artistIdModel);
            }

            return(model);
        }
        public virtual ApiTransactionClientRequestModel MapServerResponseToClientRequest(
            ApiTransactionServerResponseModel response)
        {
            var request = new ApiTransactionClientRequestModel();

            request.SetProperties(
                response.Amount,
                response.ArtistId,
                response.DateCreated,
                response.StripeTransactionId);
            return(request);
        }
        public virtual ApiTransactionServerResponseModel MapServerRequestToResponse(
            int id,
            ApiTransactionServerRequestModel request)
        {
            var response = new ApiTransactionServerResponseModel();

            response.SetProperties(id,
                                   request.Amount,
                                   request.ArtistId,
                                   request.DateCreated,
                                   request.StripeTransactionId);
            return(response);
        }
        public void MapEntityToModel()
        {
            var         mapper = new DALTransactionMapper();
            Transaction item   = new Transaction();

            item.SetProperties(1, 1m, 1, DateTime.Parse("1/1/1987 12:00:00 AM"), "A");
            ApiTransactionServerResponseModel response = mapper.MapEntityToModel(item);

            response.Amount.Should().Be(1m);
            response.ArtistId.Should().Be(1);
            response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.Id.Should().Be(1);
            response.StripeTransactionId.Should().Be("A");
        }
        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));
            }
        }
 public TransactionUpdatedNotification(ApiTransactionServerResponseModel record)
 {
     this.Record = record;
 }