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

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

            request.SetProperties(
                response.Name);
            return(request);
        }
        public virtual ApiVehicleServerResponseModel MapServerRequestToResponse(
            int id,
            ApiVehicleServerRequestModel request)
        {
            var response = new ApiVehicleServerResponseModel();

            response.SetProperties(id,
                                   request.Name);
            return(response);
        }
Exemple #4
0
        public void MapModelToEntity()
        {
            var mapper = new DALVehicleMapper();
            ApiVehicleServerRequestModel model = new ApiVehicleServerRequestModel();

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

            response.Name.Should().Be("A");
        }
Exemple #5
0
        public virtual Vehicle MapModelToEntity(
            int id,
            ApiVehicleServerRequestModel model
            )
        {
            Vehicle item = new Vehicle();

            item.SetProperties(
                id,
                model.Name);
            return(item);
        }
Exemple #6
0
        public virtual async Task <CreateResponse <ApiVehicleServerResponseModel> > Create(
            ApiVehicleServerRequestModel model)
        {
            CreateResponse <ApiVehicleServerResponseModel> response = ValidationResponseFactory <ApiVehicleServerResponseModel> .CreateResponse(await this.VehicleModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Vehicle record = this.DalVehicleMapper.MapModelToEntity(default(int), model);
                record = await this.VehicleRepository.Create(record);

                response.SetRecord(this.DalVehicleMapper.MapEntityToModel(record));
                await this.mediator.Publish(new VehicleCreatedNotification(response.Record));
            }

            return(response);
        }
Exemple #7
0
        public virtual async Task <UpdateResponse <ApiVehicleServerResponseModel> > Update(
            int id,
            ApiVehicleServerRequestModel model)
        {
            var validationResult = await this.VehicleModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Vehicle record = this.DalVehicleMapper.MapModelToEntity(id, model);
                await this.VehicleRepository.Update(record);

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

                ApiVehicleServerResponseModel apiModel = this.DalVehicleMapper.MapEntityToModel(record);
                await this.mediator.Publish(new VehicleUpdatedNotification(apiModel));

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