Exemple #1
0
        public JsonPatchDocument <ApiQuoteTweetServerRequestModel> CreatePatch(ApiQuoteTweetServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiQuoteTweetServerRequestModel>();

            patch.Replace(x => x.Content, model.Content);
            patch.Replace(x => x.Date, model.Date);
            patch.Replace(x => x.RetweeterUserId, model.RetweeterUserId);
            patch.Replace(x => x.SourceTweetId, model.SourceTweetId);
            patch.Replace(x => x.Time, model.Time);
            return(patch);
        }
Exemple #2
0
        public virtual ApiQuoteTweetServerRequestModel MapServerResponseToRequest(
            ApiQuoteTweetServerResponseModel response)
        {
            var request = new ApiQuoteTweetServerRequestModel();

            request.SetProperties(
                response.Content,
                response.Date,
                response.RetweeterUserId,
                response.SourceTweetId,
                response.Time);
            return(request);
        }
        public void MapModelToEntity()
        {
            var mapper = new DALQuoteTweetMapper();
            ApiQuoteTweetServerRequestModel model = new ApiQuoteTweetServerRequestModel();

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

            response.Content.Should().Be("A");
            response.Date.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.RetweeterUserId.Should().Be(1);
            response.SourceTweetId.Should().Be(1);
            response.Time.Should().Be(TimeSpan.Parse("01:00:00"));
        }
        public virtual QuoteTweet MapModelToEntity(
            int quoteTweetId,
            ApiQuoteTweetServerRequestModel model
            )
        {
            QuoteTweet item = new QuoteTweet();

            item.SetProperties(
                quoteTweetId,
                model.Content,
                model.Date,
                model.RetweeterUserId,
                model.SourceTweetId,
                model.Time);
            return(item);
        }
Exemple #5
0
        public virtual async Task <CreateResponse <ApiQuoteTweetServerResponseModel> > Create(
            ApiQuoteTweetServerRequestModel model)
        {
            CreateResponse <ApiQuoteTweetServerResponseModel> response = ValidationResponseFactory <ApiQuoteTweetServerResponseModel> .CreateResponse(await this.QuoteTweetModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                QuoteTweet record = this.DalQuoteTweetMapper.MapModelToEntity(default(int), model);
                record = await this.QuoteTweetRepository.Create(record);

                response.SetRecord(this.DalQuoteTweetMapper.MapEntityToModel(record));
                await this.mediator.Publish(new QuoteTweetCreatedNotification(response.Record));
            }

            return(response);
        }
Exemple #6
0
        public virtual async Task <UpdateResponse <ApiQuoteTweetServerResponseModel> > Update(
            int quoteTweetId,
            ApiQuoteTweetServerRequestModel model)
        {
            var validationResult = await this.QuoteTweetModelValidator.ValidateUpdateAsync(quoteTweetId, model);

            if (validationResult.IsValid)
            {
                QuoteTweet record = this.DalQuoteTweetMapper.MapModelToEntity(quoteTweetId, model);
                await this.QuoteTweetRepository.Update(record);

                record = await this.QuoteTweetRepository.Get(quoteTweetId);

                ApiQuoteTweetServerResponseModel apiModel = this.DalQuoteTweetMapper.MapEntityToModel(record);
                await this.mediator.Publish(new QuoteTweetUpdatedNotification(apiModel));

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