示例#1
0
        public JsonPatchDocument <ApiLocationServerRequestModel> CreatePatch(ApiLocationServerRequestModel model)
        {
            var patch = new JsonPatchDocument <ApiLocationServerRequestModel>();

            patch.Replace(x => x.GpsLat, model.GpsLat);
            patch.Replace(x => x.GpsLong, model.GpsLong);
            patch.Replace(x => x.LocationName, model.LocationName);
            return(patch);
        }
示例#2
0
        public virtual ApiLocationServerRequestModel MapServerResponseToRequest(
            ApiLocationServerResponseModel response)
        {
            var request = new ApiLocationServerRequestModel();

            request.SetProperties(
                response.GpsLat,
                response.GpsLong,
                response.LocationName);
            return(request);
        }
示例#3
0
        public virtual ApiLocationServerResponseModel MapServerRequestToResponse(
            int locationId,
            ApiLocationServerRequestModel request)
        {
            var response = new ApiLocationServerResponseModel();

            response.SetProperties(locationId,
                                   request.GpsLat,
                                   request.GpsLong,
                                   request.LocationName);
            return(response);
        }
示例#4
0
        public void MapModelToEntity()
        {
            var mapper = new DALLocationMapper();
            ApiLocationServerRequestModel model = new ApiLocationServerRequestModel();

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

            response.GpsLat.Should().Be(1);
            response.GpsLong.Should().Be(1);
            response.LocationName.Should().Be("A");
        }
示例#5
0
        public virtual Location MapModelToEntity(
            int locationId,
            ApiLocationServerRequestModel model
            )
        {
            Location item = new Location();

            item.SetProperties(
                locationId,
                model.GpsLat,
                model.GpsLong,
                model.LocationName);
            return(item);
        }
示例#6
0
        public virtual async Task <CreateResponse <ApiLocationServerResponseModel> > Create(
            ApiLocationServerRequestModel model)
        {
            CreateResponse <ApiLocationServerResponseModel> response = ValidationResponseFactory <ApiLocationServerResponseModel> .CreateResponse(await this.LocationModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Location record = this.DalLocationMapper.MapModelToEntity(default(int), model);
                record = await this.LocationRepository.Create(record);

                response.SetRecord(this.DalLocationMapper.MapEntityToModel(record));
                await this.mediator.Publish(new LocationCreatedNotification(response.Record));
            }

            return(response);
        }
示例#7
0
        public virtual async Task <UpdateResponse <ApiLocationServerResponseModel> > Update(
            int locationId,
            ApiLocationServerRequestModel model)
        {
            var validationResult = await this.LocationModelValidator.ValidateUpdateAsync(locationId, model);

            if (validationResult.IsValid)
            {
                Location record = this.DalLocationMapper.MapModelToEntity(locationId, model);
                await this.LocationRepository.Update(record);

                record = await this.LocationRepository.Get(locationId);

                ApiLocationServerResponseModel apiModel = this.DalLocationMapper.MapEntityToModel(record);
                await this.mediator.Publish(new LocationUpdatedNotification(apiModel));

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