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

            patch.Replace(x => x.Name, model.Name);
            return(patch);
        }
        public virtual ApiUnitDispositionServerRequestModel MapServerResponseToRequest(
            ApiUnitDispositionServerResponseModel response)
        {
            var request = new ApiUnitDispositionServerRequestModel();

            request.SetProperties(
                response.Name);
            return(request);
        }
示例#3
0
        public void MapModelToEntity()
        {
            var mapper = new DALUnitDispositionMapper();
            ApiUnitDispositionServerRequestModel model = new ApiUnitDispositionServerRequestModel();

            model.SetProperties("A");
            UnitDisposition response = mapper.MapModelToEntity(1, model);

            response.Name.Should().Be("A");
        }
        public virtual ApiUnitDispositionServerResponseModel MapServerRequestToResponse(
            int id,
            ApiUnitDispositionServerRequestModel request)
        {
            var response = new ApiUnitDispositionServerResponseModel();

            response.SetProperties(id,
                                   request.Name);
            return(response);
        }
        public virtual UnitDisposition MapModelToEntity(
            int id,
            ApiUnitDispositionServerRequestModel model
            )
        {
            UnitDisposition item = new UnitDisposition();

            item.SetProperties(
                id,
                model.Name);
            return(item);
        }
        public virtual async Task <CreateResponse <ApiUnitDispositionServerResponseModel> > Create(
            ApiUnitDispositionServerRequestModel model)
        {
            CreateResponse <ApiUnitDispositionServerResponseModel> response = ValidationResponseFactory <ApiUnitDispositionServerResponseModel> .CreateResponse(await this.UnitDispositionModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                UnitDisposition record = this.DalUnitDispositionMapper.MapModelToEntity(default(int), model);
                record = await this.UnitDispositionRepository.Create(record);

                response.SetRecord(this.DalUnitDispositionMapper.MapEntityToModel(record));
                await this.mediator.Publish(new UnitDispositionCreatedNotification(response.Record));
            }

            return(response);
        }
        public virtual async Task <UpdateResponse <ApiUnitDispositionServerResponseModel> > Update(
            int id,
            ApiUnitDispositionServerRequestModel model)
        {
            var validationResult = await this.UnitDispositionModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                UnitDisposition record = this.DalUnitDispositionMapper.MapModelToEntity(id, model);
                await this.UnitDispositionRepository.Update(record);

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

                ApiUnitDispositionServerResponseModel apiModel = this.DalUnitDispositionMapper.MapEntityToModel(record);
                await this.mediator.Publish(new UnitDispositionUpdatedNotification(apiModel));

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