public async Task <MinTemperatureEntity> Post(int locationId, double value, int profileId) { var location = await Db.Locations.Where(x => x.Id == locationId && x.Active).SingleOrDefaultAsync(); if (location == null) { return(null); } // TODO: Solve this //else if (location.Device.OwnerUserId != userId) // return null; var minTemperature = new MinTemperatureEntity() { LocationId = locationId, Value = value, ProfileId = profileId, CreatedAt = Now }; Db.MinTemperatures.Add(minTemperature); await Db.SaveChangesAsync(); await PostRandomGuid(location.DeviceId); return(minTemperature); }
public async Task <List <ProfileDto> > GetDtos(string deviceId, int locationId = -1) { if (locationId == -1) { locationId = await Db.Locations.Where(x => x.DeviceId == deviceId && x.Active).Select(x => x.Id).SingleOrDefaultAsync(); } var profiles = await Db.Profiles.Where(x => x.User.DeviceId == deviceId).ToListAsync(); var profileDtos = new List <ProfileDto>(); foreach (var profile in profiles) { var profileDto = new ProfileDto(); bool?state = null; MinTemperatureEntity minTemp = null; if (profile.TypeId == ProfileType.MODE_AUTO_PROFILE_ID) { minTemp = await minTemperatureRepository.Get(locationId, profile.Id); if (minTemp == null) { minTemp = await minTemperatureRepository.Post(locationId, DEFAULT_TEMP, profile.Id); if (minTemp == null) { throw new RepositoryException($"{profile.Id} 'idli profil ve {locationId} id'li location için MinTemp bilgisi yok ve yenisi oluşturulamıyor."); } } } else if (profile.TypeId == ProfileType.MODE_AUTO_SERVER_PROFILE_ID) { minTemp = await minTemperatureRepository.Get(profile.Id); if (minTemp == null) { throw new RepositoryException($"{profile.Id} 'idli profil ve {locationId} id'li location için MinTemp bilgisi yok ve yenisi oluşturulamıyor."); } var location = await Db.Locations.Where(x => x.Id == minTemp.LocationId && x.Active).SingleOrDefaultAsync(); profileDto.SelectedThermometer = new LocationDto() { Id = location.Id, Name = location.Name, DeviceId = location.DeviceId, DeviceTypeName = DeviceType.GetName(location.Device.TypeId), MinTempValue = minTemp.Value }; } if (profile.TypeId == ProfileType.MODE_MANUAL_ID) { state = await stateRepository.Get(deviceId); } profileDto.Id = profile.Id; profileDto.MinTempValue = minTemp?.Value; profileDto.ProfileName = profile.Name; profileDto.TypeName = ProfileType.GetName(profile.TypeId); profileDto.State = state; profileDto.Active = profile.Active; profileDtos.Add(profileDto); } return(profileDtos); }