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

            patch.Replace(x => x.DateOfLastPing, model.DateOfLastPing);
            patch.Replace(x => x.IsActive, model.IsActive);
            patch.Replace(x => x.Name, model.Name);
            patch.Replace(x => x.PublicId, model.PublicId);
            return(patch);
        }
        public virtual ApiDeviceServerRequestModel MapServerResponseToRequest(
            ApiDeviceServerResponseModel response)
        {
            var request = new ApiDeviceServerRequestModel();

            request.SetProperties(
                response.DateOfLastPing,
                response.IsActive,
                response.Name,
                response.PublicId);
            return(request);
        }
Beispiel #3
0
        public void MapModelToEntity()
        {
            var mapper = new DALDeviceMapper();
            ApiDeviceServerRequestModel model = new ApiDeviceServerRequestModel();

            model.SetProperties(DateTime.Parse("1/1/1987 12:00:00 AM"), true, "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            Device response = mapper.MapModelToEntity(1, model);

            response.DateOfLastPing.Should().Be(DateTime.Parse("1/1/1987 12:00:00 AM"));
            response.IsActive.Should().Be(true);
            response.Name.Should().Be("A");
            response.PublicId.Should().Be(Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
        }
        public virtual ApiDeviceServerResponseModel MapServerRequestToResponse(
            int id,
            ApiDeviceServerRequestModel request)
        {
            var response = new ApiDeviceServerResponseModel();

            response.SetProperties(id,
                                   request.DateOfLastPing,
                                   request.IsActive,
                                   request.Name,
                                   request.PublicId);
            return(response);
        }
Beispiel #5
0
        public virtual Device MapModelToEntity(
            int id,
            ApiDeviceServerRequestModel model
            )
        {
            Device item = new Device();

            item.SetProperties(
                id,
                model.DateOfLastPing,
                model.IsActive,
                model.Name,
                model.PublicId);
            return(item);
        }
Beispiel #6
0
        public virtual async Task <CreateResponse <ApiDeviceServerResponseModel> > Create(
            ApiDeviceServerRequestModel model)
        {
            CreateResponse <ApiDeviceServerResponseModel> response = ValidationResponseFactory <ApiDeviceServerResponseModel> .CreateResponse(await this.DeviceModelValidator.ValidateCreateAsync(model));

            if (response.Success)
            {
                Device record = this.DalDeviceMapper.MapModelToEntity(default(int), model);
                record = await this.DeviceRepository.Create(record);

                response.SetRecord(this.DalDeviceMapper.MapEntityToModel(record));
                await this.mediator.Publish(new DeviceCreatedNotification(response.Record));
            }

            return(response);
        }
Beispiel #7
0
        public virtual async Task <UpdateResponse <ApiDeviceServerResponseModel> > Update(
            int id,
            ApiDeviceServerRequestModel model)
        {
            var validationResult = await this.DeviceModelValidator.ValidateUpdateAsync(id, model);

            if (validationResult.IsValid)
            {
                Device record = this.DalDeviceMapper.MapModelToEntity(id, model);
                await this.DeviceRepository.Update(record);

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

                ApiDeviceServerResponseModel apiModel = this.DalDeviceMapper.MapEntityToModel(record);
                await this.mediator.Publish(new DeviceUpdatedNotification(apiModel));

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