public void Post([FromBody] Sighting sighting) { GMPRestApi.Models.Data.GMPMissingPersonEntities entities = new GMPRestApi.Models.Data.GMPMissingPersonEntities(); Models.Data.misper_ person = entities.misper_.Where(x => x.Unique_ID == sighting.UserID).FirstOrDefault(); if (person == null) { throw new HttpException("Person not found"); } else { var socialMediaType = entities.LocationTypes.Where(x => x.LocationCode == "APSIG").FirstOrDefault(); var location = new Models.Data.Location(); location.Unique_ID = person.Unique_ID; location.ContactNumber = sighting.ContactNumber; location.Latitude = sighting.Latitude; location.LocationTypeID = socialMediaType.ID; location.Verified = "N"; location.SightingDate = DateTime.Now; entities.Locations.Add(location); entities.Locations.AddOrUpdate(); entities.SaveChanges(); person.Locations.Add(location); var phoneData = new Models.Data.PhoneData(); location.PhoneDatas.Add(phoneData); phoneData.LocationID = location.ID; phoneData.DeviceID = sighting.DeviceID; entities.PhoneDatas.AddOrUpdate(); entities.misper_.AddOrUpdate(); entities.SaveChanges(); } }
public void Post([FromBody] Sighting sighting, int locationType) { GMPRestApi.Models.Data.GMPMissingPersonEntities entities = new GMPRestApi.Models.Data.GMPMissingPersonEntities(); Models.Data.misper_ person = entities.misper_.Where(x => x.Unique_ID == sighting.UserID).FirstOrDefault(); if (person == null) { throw new HttpException("Person not found"); } else { var location = new Models.Data.Location(); location.Unique_ID = person.Unique_ID; location.ContactNumber = sighting.ContactNumber; location.Latitude = sighting.Latitude; location.LocationTypeID = locationType; person.Locations.Add(location); entities.Locations.Add(location); entities.Locations.AddOrUpdate(); entities.SaveChanges(); } }