public void UpdatePreferences(Guid userId, PreferencesDto preferencesDto) { var preferences = this.PreferencesRepository.GetAll().FirstOrDefault(p => p.UserId == userId); var exists = true; if (preferences == null) { exists = false; preferences = new PreferencesEntity { UserId = userId }; } preferences.MinTemperature = preferencesDto.MinTemperature; preferences.MaxTemperature = preferencesDto.MaxTemperature; preferences.TransportationType = preferencesDto.TransportationType; preferences.RainyTrip = preferencesDto.RainyTrip; preferences.SnowyTrip = preferencesDto.SnowyTrip; if (exists) { this.PreferencesRepository.Update(preferences); } else { this.PreferencesRepository.Insert(preferences); } }
public IActionResult Set([FromBody] PreferencesDto preferences) { var userId = Guid.Parse(HttpContext.User.Identities.First().Name); this.UserService.UpdatePreferences(userId, preferences); return(this.Ok()); }