public JsonPatchDocument <ApiTweetServerRequestModel> CreatePatch(ApiTweetServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiTweetServerRequestModel>();

            patch.Replace(x => x.Content, model.Content);
            patch.Replace(x => x.Date, model.Date);
            patch.Replace(x => x.LocationId, model.LocationId);
            patch.Replace(x => x.Time, model.Time);
            patch.Replace(x => x.UserUserId, model.UserUserId);
            return(patch);
        }
        public virtual ApiTweetServerRequestModel MapServerResponseToRequest(
            ApiTweetServerResponseModel response)
        {
            var request = new ApiTweetServerRequestModel();

            request.SetProperties(
                response.Content,
                response.Date,
                response.LocationId,
                response.Time,
                response.UserUserId);
            return(request);
        }
        public virtual ApiTweetServerResponseModel MapServerRequestToResponse(
            int tweetId,
            ApiTweetServerRequestModel request)
        {
            var response = new ApiTweetServerResponseModel();

            response.SetProperties(tweetId,
                                   request.Content,
                                   request.Date,
                                   request.LocationId,
                                   request.Time,
                                   request.UserUserId);
            return(response);
        }
Exemplo n.º 4
0
        public void MapModelToEntity()
        {
            var mapper = new DALTweetMapper();
            ApiTweetServerRequestModel model = new ApiTweetServerRequestModel();

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

            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LocationId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
            response.UserUserId.Should().Be(1);
        }
Exemplo n.º 5
0
        public virtual async Task <CreateResponse <ApiTweetServerResponseModel> > Create(
            ApiTweetServerRequestModel model)
        {
            CreateResponse <ApiTweetServerResponseModel> response = ValidationResponseFactory <ApiTweetServerResponseModel> .CreateResponse(await this.TweetModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Tweet record = this.DalTweetMapper.MapModelToEntity(default(int), model);
                record = await this.TweetRepository.Create(record);

                response.SetRecord(this.DalTweetMapper.MapEntityToModel(record));
                await this.mediator.Publish(new TweetCreatedNotification(response.Record));
            }

            return(response);
        }
Exemplo n.º 6
0
        public virtual Tweet MapModelToEntity(
            int tweetId,
            ApiTweetServerRequestModel model
            )
        {
            Tweet item = new Tweet();

            item.SetProperties(
                tweetId,
                model.Content,
                model.Date,
                model.LocationId,
                model.Time,
                model.UserUserId);
            return(item);
        }
Exemplo n.º 7
0
        public virtual async Task <UpdateResponse <ApiTweetServerResponseModel> > Update(
            int tweetId,
            ApiTweetServerRequestModel model)
        {
            var validationResult = await this.TweetModelValidator.ValidateUpdateAsync(tweetId, model);

            if (validationResult.IsValid)
            {
                Tweet record = this.DalTweetMapper.MapModelToEntity(tweetId, model);
                await this.TweetRepository.Update(record);

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

                ApiTweetServerResponseModel apiModel = this.DalTweetMapper.MapEntityToModel(record);
                await this.mediator.Publish(new TweetUpdatedNotification(apiModel));

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