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

            patch.Replace(x => x.Action, model.Action);
            patch.Replace(x => x.DeviceId, model.DeviceId);
            patch.Replace(x => x.Name, model.Name);
            return(patch);
        }
        public virtual ApiDeviceActionServerRequestModel MapServerResponseToRequest(
            ApiDeviceActionServerResponseModel response)
        {
            var request = new ApiDeviceActionServerRequestModel();

            request.SetProperties(
                response.Action,
                response.DeviceId,
                response.Name);
            return(request);
        }
예제 #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALDeviceActionMapper();
            ApiDeviceActionServerRequestModel model = new ApiDeviceActionServerRequestModel();

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

            response.Action.Should().Be("A");
            response.DeviceId.Should().Be(1);
            response.Name.Should().Be("A");
        }
        public virtual ApiDeviceActionServerResponseModel MapServerRequestToResponse(
            int id,
            ApiDeviceActionServerRequestModel request)
        {
            var response = new ApiDeviceActionServerResponseModel();

            response.SetProperties(id,
                                   request.Action,
                                   request.DeviceId,
                                   request.Name);
            return(response);
        }
예제 #5
0
        public virtual DeviceAction MapModelToEntity(
            int id,
            ApiDeviceActionServerRequestModel model
            )
        {
            DeviceAction item = new DeviceAction();

            item.SetProperties(
                id,
                model.Action,
                model.DeviceId,
                model.Name);
            return(item);
        }
예제 #6
0
        public virtual async Task <CreateResponse <ApiDeviceActionServerResponseModel> > Create(
            ApiDeviceActionServerRequestModel model)
        {
            CreateResponse <ApiDeviceActionServerResponseModel> response = ValidationResponseFactory <ApiDeviceActionServerResponseModel> .CreateResponse(await this.DeviceActionModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                DeviceAction record = this.DalDeviceActionMapper.MapModelToEntity(default(int), model);
                record = await this.DeviceActionRepository.Create(record);

                response.SetRecord(this.DalDeviceActionMapper.MapEntityToModel(record));
                await this.mediator.Publish(new DeviceActionCreatedNotification(response.Record));
            }

            return(response);
        }
예제 #7
0
        public virtual async Task <UpdateResponse <ApiDeviceActionServerResponseModel> > Update(
            int id,
            ApiDeviceActionServerRequestModel model)
        {
            var validationResult = await this.DeviceActionModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                DeviceAction record = this.DalDeviceActionMapper.MapModelToEntity(id, model);
                await this.DeviceActionRepository.Update(record);

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

                ApiDeviceActionServerResponseModel apiModel = this.DalDeviceActionMapper.MapEntityToModel(record);
                await this.mediator.Publish(new DeviceActionUpdatedNotification(apiModel));

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