public void DeviceProperty_CRUD() { var proxy = new ProxyService <DeviceService>(new DeviceService(new ServiceContext())); //arrange var dto = testUtil.DevicePropertyDto(); //Create var rpInsert = proxy.RunAsync(x => x.InsertDeviceProperty(dto)); rpInsert.Wait(); Assert.True(rpInsert.Result.Data > 0); //Read long identity = rpInsert.Result.Data; var rpGet = proxy.RunAsync(x => x.GetDeviceProperty(identity)); rpGet.Wait(); Assert.True(rpInsert.Result.Data == rpGet.Result.Data.Id); //Update var tmpDto = rpGet.Result.Data; tmpDto.PropertyValue = "Name updated!"; var rpUpdate = proxy.RunAsync(x => x.UpdateDeviceProperty(tmpDto)); rpUpdate.Wait(); var rpUpdateGet = proxy.RunAsync(x => x.GetDeviceProperty(identity)); rpUpdateGet.Wait(); Assert.Equal(rpUpdateGet.Result.Data.PropertyValue, tmpDto.PropertyValue); //Delete var rpDelete = proxy.RunAsync(x => x.DeleteDeviceProperty(identity)); rpDelete.Wait(); var rpDeleteGet = proxy.RunAsync(x => x.GetDeviceProperty(identity)); rpDeleteGet.Wait(); Assert.True(rpDeleteGet.Result.Data == null); //List var queryDto = new DevicePropertyDto { }; var pagingDto = new PagingDto { pageSize = 3, pageNumber = 1 }; var rpList = proxy.RunAsync(x => x.ListDeviceProperty(queryDto, pagingDto));//List rpList.Wait(); Assert.True(rpList?.Result.Data != null && rpList.Result.Data.Any()); //assert //cleaup var rpHardDelete = proxy.RunAsync(x => x.DeleteHardDeviceProperty(identity)); }
public async Task <ServiceResponse <IEnumerable <DevicePropertyDto> > > ListDeviceProperty([FromBody] IDictionary <string, object> data) { if (data == null) { throw new System.ArgumentNullException(nameof(data)); } DevicePropertyDto searchDto = JsonConvert.DeserializeObject <DevicePropertyDto>(data["searchDto"].ToString()); PagingDto pagingDto = JsonConvert.DeserializeObject <PagingDto>(data["pagingDto"].ToString()); return(await Sm.DeviceService.RunAsync(x => x.ListDeviceProperty(searchDto, pagingDto))); }
public ServiceResponse <IEnumerable <DevicePropertyDto> > ListDeviceProperty(DevicePropertyDto devicePropertyDto, PagingDto pagingDto) { var Rm = new RepositoryManager(ServiceContext); IEnumerable <DeviceProperty> list = Rm.DevicePropertyRepository.List(devicePropertyDto, ref pagingDto); IEnumerable <DevicePropertyDto> restulList = list.Select(entity => entity.CopyTo(new DevicePropertyDto())).ToList(); if (list == null || !list.Any()) { throw new ServiceException(ExceptionType.Warning, Translate(MessagesConstants.WRN_RECORD_NOT_FOUND)); } return(new ServiceResponse <IEnumerable <DevicePropertyDto> >(restulList, pagingDto.count)); }
public DevicePropertyDto CopyTo(DevicePropertyDto dto) { dto.DeviceId = this.DeviceId; dto.PropertyId = this.PropertyId; dto.PropertyValue = this.PropertyValue; dto.Version = this.Version; if (dto?.DeviceDto != null) { this.Device.CopyTo(dto.DeviceDto); } if (dto?.PropertyDto != null) { this.Property.CopyTo(dto.PropertyDto); } BaseCopyTo <DevicePropertyDto>(dto); return(dto); }
public DeviceProperty CopyFrom(DevicePropertyDto dto) { this.DeviceId = dto.DeviceId; this.PropertyId = dto.PropertyId; this.PropertyValue = dto.PropertyValue; this.Version = dto.Version; if (dto?.DeviceDto != null) { this.Device.CopyFrom(dto.DeviceDto); } if (dto?.PropertyDto != null) { this.Property.CopyFrom(dto.PropertyDto); } BaseCopyFrom <DeviceProperty>(dto); return(this); }
public ServiceResponse <int> UpdateDeviceProperty(DevicePropertyDto devicePropertyDto) { if (devicePropertyDto == null) { throw new ServiceException(Translate(MessagesConstants.ERR_DATA_NOT_FOUND_TO_SAVE)); } DeviceProperty entity = new DeviceProperty(); var Rm = new RepositoryManager(ServiceContext); int rowsAffected = Rm.DevicePropertyRepository.Update(entity.CopyFrom(devicePropertyDto)); if (rowsAffected > 0) { return(new ServiceResponse <int>(rowsAffected, Translate(MessagesConstants.SCC_DATA_UPDATED))); } throw new ServiceException(Translate(MessagesConstants.ERR_UPDATE)); }
public ServiceResponse <long> InsertDeviceProperty(DevicePropertyDto devicePropertyDto) { if (devicePropertyDto == null) { throw new ServiceException(Translate(MessagesConstants.ERR_DATA_NOT_FOUND_TO_SAVE)); } DeviceProperty entity = new DeviceProperty(); var Rm = new RepositoryManager(ServiceContext); long id = Rm.DevicePropertyRepository.Insert(entity.CopyFrom(devicePropertyDto)); if (id > 0) { return(new ServiceResponse <long>(id, Translate(MessagesConstants.SCC_DATA_INSERTED))); } throw new ServiceException(Translate(MessagesConstants.ERR_INSERT)); }
public async Task <ServiceResponse <int> > PutDeviceProperty(int id, [FromBody] DevicePropertyDto devicepropertyDto) => await Sm.DeviceService.RunAsync(x => x.UpdateDeviceProperty(devicepropertyDto));
public async Task <ServiceResponse <long> > PostDeviceProperty([FromBody] DevicePropertyDto devicepropertyDto) => await Sm.DeviceService.RunAsync(x => x.InsertDeviceProperty(devicepropertyDto));