private void PrepareSensor(CreateOrEditSensorDto input, Sensor sensor) { if (input.UserId.HasValue && AbpSession.TenantId.HasValue) { var user = _userManager.GetUser(new UserIdentifier(AbpSession.TenantId, input.UserId.Value)); if (user != null) { sensor.User = user; } } if (AbpSession.TenantId.HasValue) { sensor.TenantId = (int?)AbpSession.TenantId; foreach (var sensorLocation in sensor.Locations) { sensorLocation.TenantId = sensor.TenantId; } foreach (var sensorPicture in sensor.Pictures) { sensorPicture.TenantId = sensor.TenantId; } } }
public async Task <SensorDto> Create(CreateOrEditSensorDto input) { var sensor = ObjectMapper.Map <Sensor>(input); PrepareSensor(input, sensor); var createdSensor = await _sensorRepository.InsertAsync(sensor); UnitOfWorkManager.Current.SaveChanges(); return(ObjectMapper.Map <SensorDto>(createdSensor)); }
public async Task <SensorDto> Update(CreateOrEditSensorDto input) { if (input.Id != null) { var sensor = await _sensorRepository.FirstOrDefaultAsync((int)input.Id); if (sensor != null) { var updated = ObjectMapper.Map(input, sensor); PrepareSensor(input, updated); var output = await _sensorRepository.UpdateAsync(updated); return(ObjectMapper.Map <SensorDto>(output));; } } throw new UserFriendlyException("User update failed"); }
public async Task <SensorDto> CreateOrEdit(CreateOrEditSensorDto input) { return(input.Id == null ? await Create(input) : await Update(input)); }