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

            patch.Replace(x => x.CreationDate, model.CreationDate);
            patch.Replace(x => x.LinkTypeId, model.LinkTypeId);
            patch.Replace(x => x.PostId, model.PostId);
            patch.Replace(x => x.RelatedPostId, model.RelatedPostId);
            return(patch);
        }
Пример #2
0
        public virtual ApiPostLinkServerRequestModel MapServerResponseToRequest(
            ApiPostLinkServerResponseModel response)
        {
            var request = new ApiPostLinkServerRequestModel();

            request.SetProperties(
                response.CreationDate,
                response.LinkTypeId,
                response.PostId,
                response.RelatedPostId);
            return(request);
        }
Пример #3
0
        public virtual ApiPostLinkServerResponseModel MapServerRequestToResponse(
            int id,
            ApiPostLinkServerRequestModel request)
        {
            var response = new ApiPostLinkServerResponseModel();

            response.SetProperties(id,
                                   request.CreationDate,
                                   request.LinkTypeId,
                                   request.PostId,
                                   request.RelatedPostId);
            return(response);
        }
Пример #4
0
        public void MapModelToEntity()
        {
            var mapper = new DALPostLinkMapper();
            ApiPostLinkServerRequestModel model = new ApiPostLinkServerRequestModel();

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

            response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.LinkTypeId.Should().Be(1);
            response.PostId.Should().Be(1);
            response.RelatedPostId.Should().Be(1);
        }
Пример #5
0
        public virtual PostLink MapModelToEntity(
            int id,
            ApiPostLinkServerRequestModel model
            )
        {
            PostLink item = new PostLink();

            item.SetProperties(
                id,
                model.CreationDate,
                model.LinkTypeId,
                model.PostId,
                model.RelatedPostId);
            return(item);
        }
Пример #6
0
        public virtual async Task <CreateResponse <ApiPostLinkServerResponseModel> > Create(
            ApiPostLinkServerRequestModel model)
        {
            CreateResponse <ApiPostLinkServerResponseModel> response = ValidationResponseFactory <ApiPostLinkServerResponseModel> .CreateResponse(await this.PostLinkModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                PostLink record = this.DalPostLinkMapper.MapModelToEntity(default(int), model);
                record = await this.PostLinkRepository.Create(record);

                response.SetRecord(this.DalPostLinkMapper.MapEntityToModel(record));
                await this.mediator.Publish(new PostLinkCreatedNotification(response.Record));
            }

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

            if (validationResult.IsValid)
            {
                PostLink record = this.DalPostLinkMapper.MapModelToEntity(id, model);
                await this.PostLinkRepository.Update(record);

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

                ApiPostLinkServerResponseModel apiModel = this.DalPostLinkMapper.MapEntityToModel(record);
                await this.mediator.Publish(new PostLinkUpdatedNotification(apiModel));

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