public IHttpActionResult Post(LocationViewModel location) { var userId = User.Identity.GetUserId(); _repo.SetNewLocation(location, userId); return Ok(); }
public IHttpActionResult Put(LocationViewModel location) { _repo.UpdateLocation(location); return Ok(); }
public void UpdateLocation(LocationViewModel location) { var loc = _db.Locations.Where(l => l.LocationId == location.LocationId).FirstOrDefault(); if(loc != null) { if (location.Name != null) loc.Name = location.Name; if (location.Address != null) loc.Address = location.Address; if (location.State != null) loc.State = location.State; if (location.City != null) loc.City = location.City; if (location.FullAddress != null) loc.FullAddress = location.FullAddress; if (!location.Longitude.Equals(0)) loc.Longitude = location.Longitude; if (!location.Latitude.Equals(0)) loc.Latitude = location.Latitude; if (location.ZipCode != 0) loc.ZipCode = location.ZipCode; if (location.Country != null) loc.Country = location.Country; if (!location.Radius.Equals(0)) loc.Radius = location.Radius; } _db.SaveChanges(); }
public void SetNewLocation(LocationViewModel location, string userId) { var oldLoc = _db.Locations.Where(l => l.UserId == userId && l.IsActive).FirstOrDefault(); if(oldLoc != null) { oldLoc.IsActive = false; } var loc = new Location { Name = location.Name, Latitude = location.Latitude, Longitude = location.Longitude, Address = location.Address, City = location.City, State = location.State, ZipCode = location.ZipCode, Country = location.Country, FullAddress = location.FullAddress, Radius = location.Radius, IsActive = true, IsCurrentLocation = location.IsCurrentLocation, UserId = userId }; _db.Locations.Add(loc); _db.SaveChanges(); }