Exemple #1
0
        public virtual ApiVehicleOfficerServerResponseModel MapEntityToModel(
            VehicleOfficer item)
        {
            var model = new ApiVehicleOfficerServerResponseModel();

            model.SetProperties(item.Id,
                                item.OfficerId,
                                item.VehicleId);
            if (item.OfficerIdNavigation != null)
            {
                var officerIdModel = new ApiOfficerServerResponseModel();
                officerIdModel.SetProperties(
                    item.OfficerIdNavigation.Id,
                    item.OfficerIdNavigation.Badge,
                    item.OfficerIdNavigation.Email,
                    item.OfficerIdNavigation.FirstName,
                    item.OfficerIdNavigation.LastName,
                    item.OfficerIdNavigation.Password);

                model.SetOfficerIdNavigation(officerIdModel);
            }

            if (item.VehicleIdNavigation != null)
            {
                var vehicleIdModel = new ApiVehicleServerResponseModel();
                vehicleIdModel.SetProperties(
                    item.VehicleIdNavigation.Id,
                    item.VehicleIdNavigation.Name);

                model.SetVehicleIdNavigation(vehicleIdModel);
            }

            return(model);
        }
        public virtual ApiVehicleOfficerClientRequestModel MapServerResponseToClientRequest(
            ApiVehicleOfficerServerResponseModel response)
        {
            var request = new ApiVehicleOfficerClientRequestModel();

            request.SetProperties(
                response.OfficerId,
                response.VehicleId);
            return(request);
        }
        public virtual ApiVehicleOfficerServerResponseModel MapServerRequestToResponse(
            int id,
            ApiVehicleOfficerServerRequestModel request)
        {
            var response = new ApiVehicleOfficerServerResponseModel();

            response.SetProperties(id,
                                   request.OfficerId,
                                   request.VehicleId);
            return(response);
        }
        public void MapEntityToModel()
        {
            var            mapper = new DALVehicleOfficerMapper();
            VehicleOfficer item   = new VehicleOfficer();

            item.SetProperties(1, 1, 1);
            ApiVehicleOfficerServerResponseModel response = mapper.MapEntityToModel(item);

            response.Id.Should().Be(1);
            response.OfficerId.Should().Be(1);
            response.VehicleId.Should().Be(1);
        }
        public virtual async Task <UpdateResponse <ApiVehicleOfficerServerResponseModel> > Update(
            int id,
            ApiVehicleOfficerServerRequestModel model)
        {
            var validationResult = await this.VehicleOfficerModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                VehicleOfficer record = this.DalVehicleOfficerMapper.MapModelToEntity(id, model);
                await this.VehicleOfficerRepository.Update(record);

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

                ApiVehicleOfficerServerResponseModel apiModel = this.DalVehicleOfficerMapper.MapEntityToModel(record);
                await this.mediator.Publish(new VehicleOfficerUpdatedNotification(apiModel));

                return(ValidationResponseFactory <ApiVehicleOfficerServerResponseModel> .UpdateResponse(apiModel));
            }
            else
            {
                return(ValidationResponseFactory <ApiVehicleOfficerServerResponseModel> .UpdateResponse(validationResult));
            }
        }
Exemple #6
0
 public VehicleOfficerUpdatedNotification(ApiVehicleOfficerServerResponseModel record)
 {
     this.Record = record;
 }