public JsonPatchDocument <ApiCommentServerRequestModel> CreatePatch(ApiCommentServerRequestModel model) { var patch = new JsonPatchDocument <ApiCommentServerRequestModel>(); patch.Replace(x => x.CreationDate, model.CreationDate); patch.Replace(x => x.PostId, model.PostId); patch.Replace(x => x.Score, model.Score); patch.Replace(x => x.Text, model.Text); patch.Replace(x => x.UserId, model.UserId); return(patch); }
public virtual ApiCommentServerRequestModel MapServerResponseToRequest( ApiCommentServerResponseModel response) { var request = new ApiCommentServerRequestModel(); request.SetProperties( response.CreationDate, response.PostId, response.Score, response.Text, response.UserId); return(request); }
public virtual ApiCommentServerResponseModel MapServerRequestToResponse( int id, ApiCommentServerRequestModel request) { var response = new ApiCommentServerResponseModel(); response.SetProperties(id, request.CreationDate, request.PostId, request.Score, request.Text, request.UserId); return(response); }
public void MapModelToEntity() { var mapper = new DALCommentMapper(); ApiCommentServerRequestModel model = new ApiCommentServerRequestModel(); model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1, "A", 1); Comment response = mapper.MapModelToEntity(1, model); response.CreationDate.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM")); response.PostId.Should().Be(1); response.Score.Should().Be(1); response.Text.Should().Be("A"); response.UserId.Should().Be(1); }
public virtual Comment MapModelToEntity( int id, ApiCommentServerRequestModel model ) { Comment item = new Comment(); item.SetProperties( id, model.CreationDate, model.PostId, model.Score, model.Text, model.UserId); return(item); }
public virtual async Task <CreateResponse <ApiCommentServerResponseModel> > Create( ApiCommentServerRequestModel model) { CreateResponse <ApiCommentServerResponseModel> response = ValidationResponseFactory <ApiCommentServerResponseModel> .CreateResponse(await this.CommentModelValidator.ValidateCreateAsync(model)); if (response.Success) { Comment record = this.DalCommentMapper.MapModelToEntity(default(int), model); record = await this.CommentRepository.Create(record); response.SetRecord(this.DalCommentMapper.MapEntityToModel(record)); await this.mediator.Publish(new CommentCreatedNotification(response.Record)); } return(response); }
public virtual async Task <UpdateResponse <ApiCommentServerResponseModel> > Update( int id, ApiCommentServerRequestModel model) { var validationResult = await this.CommentModelValidator.ValidateUpdateAsync(id, model); if (validationResult.IsValid) { Comment record = this.DalCommentMapper.MapModelToEntity(id, model); await this.CommentRepository.Update(record); record = await this.CommentRepository.Get(id); ApiCommentServerResponseModel apiModel = this.DalCommentMapper.MapEntityToModel(record); await this.mediator.Publish(new CommentUpdatedNotification(apiModel)); return(ValidationResponseFactory <ApiCommentServerResponseModel> .UpdateResponse(apiModel)); } else { return(ValidationResponseFactory <ApiCommentServerResponseModel> .UpdateResponse(validationResult)); } }