public async Task <IActionResult> Edit(int id, [Bind("SavedLocationId,UserId,LocationId")] SavedLocation savedLocation) { if (id != savedLocation.SavedLocationId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(savedLocation); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SavedLocationExists(savedLocation.SavedLocationId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["LocationId"] = new SelectList(_context.Locations, "LocationId", "Description", savedLocation.LocationId); ViewData["UserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", savedLocation.UserId); return(View(savedLocation)); }
// POST api/<controller> public IActionResult Post([FromBody] SavedLocation savedLocation) { if (savedLocation == null) { return(BadRequest("Location is null.")); } _dataRepository.Add(savedLocation); return(Ok(savedLocation)); }
public IActionResult Get(long id) { SavedLocation savedLocation = _dataRepository.Get(id); if (savedLocation == null) { return(NotFound("The Location record couldn't be found.")); } return(Ok(savedLocation)); }
public Task <int> SaveItemAsync(SavedLocation item) { if (item.ID != 0) { return(database.UpdateAsync(item)); } else { return(database.InsertAsync(item)); } }
public int SaveItem(SavedLocation item) { if (item.ID != 0) { return(database.Update(item)); } else { return(database.Insert(item)); } }
public void Like() { if (inputfield.text == "") { return; } SavedLocation savedlocation = Instantiate(savedLocationPrefab, savedlocationContent).GetComponent <SavedLocation>(); savedlocation.Initialize(geouserinput.Coordinate, inputfield.text); DataSender.Instance.OnSaveLocation(inputfield.text, geouserinput.Coordinate.x, geouserinput.Coordinate.y); }
public IActionResult Delete(long id) { SavedLocation savedLocation = _dataRepository.Get(id); if (savedLocation == null) { return(NotFound("The Employee record couldn't be found.")); } _dataRepository.Delete(savedLocation); return(NoContent()); }
private void CreateSavedLocationsConfigFile(string file) { scalebar.GetScalebarDistanceParams(out _, out _, out _, out int number, out string unit); int distance = number * (unit.Equals("km") ? 1000 : 1); var firstEntry = new SavedLocation { name = "Default", lat = map.Latitude, lon = map.Longitude, distance = distance }; savedLocations.Add(firstEntry); string line = $"{firstEntry.name},{firstEntry.lat},{firstEntry.lon},{firstEntry.distance}"; #if !UNITY_WEBGL using (StreamWriter sw = new StreamWriter(file, false)) { sw.WriteLine(line); } #endif }
public SaveUserFavoriteResponse SaveUserFavorite(SaveUserFavoriteRequest request) { var response = new SaveUserFavoriteResponse() { Success = false, Message = "Unable to save user favorite" }; try { //Check to see if we have already created the 5 digit unique user code. //Not going to check to see if we get a duplicate code for this exercise var userCodeExists = request.WeathermanEntities.UserCodes.Any(w => w.UserId == request.UserId); //Will add the code if it does not exist for the logged in user. if (!userCodeExists) { var userCode = new UserCode { UserId = request.UserId }; var typingMonkey = new TypingMonkey(); userCode.Code = typingMonkey.TypeAway(5); request.WeathermanEntities.UserCodes.Add(userCode); } var savedLocation = new SavedLocation { //Did not get a chance to implement saving the city yet. City = string.Empty, ZipCode = request.PostalCode, UserId = request.UserId }; request.WeathermanEntities.SavedLocations.Add(savedLocation); request.WeathermanEntities.SaveChanges(); } catch (Exception exception) { response.Success = false; response.Exception = exception; return(response); } response.Success = true; response.Message = string.Empty; return(response); }
public ActionResult Like(int locId) { if (ModelState.IsValid) { SavedLocation savLoc = new SavedLocation(); savLoc.UserId = Int32.Parse(HttpContext.Session.GetString("UserID")); savLoc.LocationId = locId; _context.Add(savLoc); _context.SaveChanges(); // Comment out to not save changes to database ViewedLocation viewLoc = new ViewedLocation(); viewLoc.UserId = Int32.Parse(HttpContext.Session.GetString("UserID")); viewLoc.LocationId = locId; _context.Add(viewLoc); //_context.SaveChanges(); } return(RedirectToAction("Dashboard")); }
protected async void GetWeather(object sender, EventArgs args) { if (!string.IsNullOrEmpty(ViewModel.Zip)) { ViewModel.CurrentWeather = await _weatherService.GetTemp(ViewModel.Zip, apikey); var loc = new SavedLocation { Name = ViewModel.CurrentWeather.Name, Temp = ViewModel.CurrentWeather.Main.Temp, Zip = ViewModel.Zip }; if (ViewModel.Locations.Count(x => x.Zip == loc.Zip) <= 0) { App.Database.SaveItem(loc); ViewModel.Locations.Add(loc); } } }
// GET: SavedLocations/Delete/5 public async Task <IActionResult> Delete(SavedLocation savedLocation1, int id) { if (id == null) { return(NotFound()); } var savedLocation = await _context.SavedLocations .Include(s => s.Location) .Include(s => s.User) .FirstOrDefaultAsync(m => m.SavedLocationId == id); if (savedLocation == null) { return(NotFound()); } savedLocation1.LocationId = savedLocation.LocationId; savedLocation1.SavedLocationId = id; return(View(savedLocation1)); }
public async Task <IActionResult> Create([Bind("UserId,LocationId")] SavedLocation savedLocation, int id) { ModelState.Remove("User"); ModelState.Remove("Location"); ModelState.Remove("LocationId"); if (ModelState.IsValid) { var CurrentUser = await GetCurrentUserAsync(); savedLocation.UserId = CurrentUser.Id; savedLocation.LocationId = id; _context.Add(savedLocation); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(savedLocation)); }
private async void OnSearchTapped(object obj) { Current = await _weatherService.GetTemp(ZipCode, apikey); Temp = Current.Main.Temp.ToString(); City = Current.Name; Current.Zip = ZipCode; Icon = $"http://openweathermap.org/img/w/{Current.WeatherWeather[0].Icon}.png"; var exists = SavedLocations.Any(x => x.Name == City); if (!exists) { var save = new SavedLocation { Zip = ZipCode, Name = City }; await App.Database.SaveItemAsync(save); SavedLocations.Add(Current); } }
public Task <int> DeleteItemAsync(SavedLocation item) { return(database.DeleteAsync(item)); }
public WeatherDetail(SavedLocation data) { InitializeComponent(); this.Title = data.Name; }
public void AddLocation(string name, double longitude, double latitude) { SavedLocation savedlocation = Instantiate(savedLocationPrefab, savedlocationContent).GetComponent <SavedLocation>(); savedlocation.Initialize(new Mapbox.Utils.Vector2d(longitude, latitude), name); }
public WeatherDetail(SavedLocation data) { InitializeComponent(); this.BindingContext = data; }