Exemplo n.º 1
0
        public JsonPatchDocument <ApiDirectTweetServerRequestModel> CreatePatch(ApiDirectTweetServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiDirectTweetServerRequestModel>();

            patch.Replace(x => x.Content, model.Content);
            patch.Replace(x => x.Date, model.Date);
            patch.Replace(x => x.TaggedUserId, model.TaggedUserId);
            patch.Replace(x => x.Time, model.Time);
            return(patch);
        }
Exemplo n.º 2
0
        public virtual ApiDirectTweetServerRequestModel MapServerResponseToRequest(
            ApiDirectTweetServerResponseModel response)
        {
            var request = new ApiDirectTweetServerRequestModel();

            request.SetProperties(
                response.Content,
                response.Date,
                response.TaggedUserId,
                response.Time);
            return(request);
        }
Exemplo n.º 3
0
        public void MapModelToEntity()
        {
            var mapper = new DALDirectTweetMapper();
            ApiDirectTweetServerRequestModel model = new ApiDirectTweetServerRequestModel();

            model.SetProperties("A", DateTime.Parse("1/1/1987 12:00:00 AM"), 1, TimeSpan.Parse("01:00:00"));
            DirectTweet response = mapper.MapModelToEntity(1, model);

            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.TaggedUserId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
        }
Exemplo n.º 4
0
        public virtual ApiDirectTweetServerResponseModel MapServerRequestToResponse(
            int tweetId,
            ApiDirectTweetServerRequestModel request)
        {
            var response = new ApiDirectTweetServerResponseModel();

            response.SetProperties(tweetId,
                                   request.Content,
                                   request.Date,
                                   request.TaggedUserId,
                                   request.Time);
            return(response);
        }
Exemplo n.º 5
0
        public virtual DirectTweet MapModelToEntity(
            int tweetId,
            ApiDirectTweetServerRequestModel model
            )
        {
            DirectTweet item = new DirectTweet();

            item.SetProperties(
                tweetId,
                model.Content,
                model.Date,
                model.TaggedUserId,
                model.Time);
            return(item);
        }
Exemplo n.º 6
0
        public virtual async Task <CreateResponse <ApiDirectTweetServerResponseModel> > Create(
            ApiDirectTweetServerRequestModel model)
        {
            CreateResponse <ApiDirectTweetServerResponseModel> response = ValidationResponseFactory <ApiDirectTweetServerResponseModel> .CreateResponse(await this.DirectTweetModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                DirectTweet record = this.DalDirectTweetMapper.MapModelToEntity(default(int), model);
                record = await this.DirectTweetRepository.Create(record);

                response.SetRecord(this.DalDirectTweetMapper.MapEntityToModel(record));
                await this.mediator.Publish(new DirectTweetCreatedNotification(response.Record));
            }

            return(response);
        }
Exemplo n.º 7
0
        public virtual async Task <UpdateResponse <ApiDirectTweetServerResponseModel> > Update(
            int tweetId,
            ApiDirectTweetServerRequestModel model)
        {
            var validationResult = await this.DirectTweetModelValidator.ValidateUpdateAsync(tweetId, model);

            if (validationResult.IsValid)
            {
                DirectTweet record = this.DalDirectTweetMapper.MapModelToEntity(tweetId, model);
                await this.DirectTweetRepository.Update(record);

                record = await this.DirectTweetRepository.Get(tweetId);

                ApiDirectTweetServerResponseModel apiModel = this.DalDirectTweetMapper.MapEntityToModel(record);
                await this.mediator.Publish(new DirectTweetUpdatedNotification(apiModel));

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