コード例 #1
0
        public JsonPatchDocument <ApiNoteServerRequestModel> CreatePatch(ApiNoteServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiNoteServerRequestModel>();

            patch.Replace(x => x.CallId, model.CallId);
            patch.Replace(x => x.DateCreated, model.DateCreated);
            patch.Replace(x => x.NoteText, model.NoteText);
            patch.Replace(x => x.OfficerId, model.OfficerId);
            return(patch);
        }
コード例 #2
0
        public virtual ApiNoteServerRequestModel MapServerResponseToRequest(
            ApiNoteServerResponseModel response)
        {
            var request = new ApiNoteServerRequestModel();

            request.SetProperties(
                response.CallId,
                response.DateCreated,
                response.NoteText,
                response.OfficerId);
            return(request);
        }
コード例 #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALNoteMapper();
            ApiNoteServerRequestModel model = new ApiNoteServerRequestModel();

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

            response.CallId.Should().Be(1);
            response.DateCreated.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.NoteText.Should().Be("A");
            response.OfficerId.Should().Be(1);
        }
コード例 #4
0
        public virtual ApiNoteServerResponseModel MapServerRequestToResponse(
            int id,
            ApiNoteServerRequestModel request)
        {
            var response = new ApiNoteServerResponseModel();

            response.SetProperties(id,
                                   request.CallId,
                                   request.DateCreated,
                                   request.NoteText,
                                   request.OfficerId);
            return(response);
        }
コード例 #5
0
        public virtual Note MapModelToEntity(
            int id,
            ApiNoteServerRequestModel model
            )
        {
            Note item = new Note();

            item.SetProperties(
                id,
                model.CallId,
                model.DateCreated,
                model.NoteText,
                model.OfficerId);
            return(item);
        }
コード例 #6
0
ファイル: NoteService.cs プロジェクト: codenesium/samples
        public virtual async Task <CreateResponse <ApiNoteServerResponseModel> > Create(
            ApiNoteServerRequestModel model)
        {
            CreateResponse <ApiNoteServerResponseModel> response = ValidationResponseFactory <ApiNoteServerResponseModel> .CreateResponse(await this.NoteModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Note record = this.DalNoteMapper.MapModelToEntity(default(int), model);
                record = await this.NoteRepository.Create(record);

                response.SetRecord(this.DalNoteMapper.MapEntityToModel(record));
                await this.mediator.Publish(new NoteCreatedNotification(response.Record));
            }

            return(response);
        }
コード例 #7
0
ファイル: NoteService.cs プロジェクト: codenesium/samples
        public virtual async Task <UpdateResponse <ApiNoteServerResponseModel> > Update(
            int id,
            ApiNoteServerRequestModel model)
        {
            var validationResult = await this.NoteModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Note record = this.DalNoteMapper.MapModelToEntity(id, model);
                await this.NoteRepository.Update(record);

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

                ApiNoteServerResponseModel apiModel = this.DalNoteMapper.MapEntityToModel(record);
                await this.mediator.Publish(new NoteUpdatedNotification(apiModel));

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