public void AddUpdateConfigEntries(ConfigMultiEntries request) { using (var context = new TICPuppyLoveDbContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { context.dbTransaction = dbContextTransaction; ConfigDTO cdto = new ConfigDTO { configs = request.ConfigEntries }; //set inserts first cdto.CreateRefConfigNewUserIntances(); if (cdto.refConfigEntries.Count() > 0) { context.Add(cdto); } //now do updates cdto.CreateRefConfigUpdateInstances(); if (cdto.refConfigEntries.Count() > 0) { context.Update(cdto); } // everything good, commit transaction dbContextTransaction.Commit(); } } }
//long? responseTypeID, //bool byType) public List<long> ExcludeNoPreferenceFromProfile(List<ProfileEntity> matchProfile) { var response = new List<long>(); using (var dbEntities = new TICPuppyLoveDbContext()) { var profileRequest = new List<ProfileResponse>(); var profileResponse = new List<ProfileResponse>(); foreach (ProfileEntity matchResp in matchProfile) { ProfileResponse prof = new ProfileResponse { ProfileEntityResponse = matchResp }; profileRequest.Add(prof); } /* profileResponse = (byType) ? dbEntities.ExcludeNoPreferencesByType(profileRequest, responseTypeID) : dbEntities.ExcludeNoPreferences(profileRequest, responseTypeID); */ profileResponse = dbEntities.ExcludeNoPreferences(profileRequest); response = (from resp in profileResponse select resp.ProfileEntityResponse.ResponseTypeID ).Distinct().ToList(); } return response; }
public Int32 AddProfile(LocationData request) { Int32 response = -1; using (var context = new TICPuppyLoveDbContext()) { using (var dbTran = context.Database.BeginTransaction()) { try { var oParm = new SqlParameter { ParameterName = "@TotalCount", DbType = DbType.Int32, Direction = ParameterDirection.Output }; context.Database.ExecuteSqlCommand( "EXEC SP_AddUpdateLocation @UserID, @Latitude, @Longitude, @Accuracy, @TimeStamp, @TotalCount OUTPUT", new SqlParameter("@UserID", request.UserID), new SqlParameter("@Latitude", request.Latitude), new SqlParameter("@Longitude", request.Longitude), new SqlParameter("@Accuracy", request.Accuracy), new SqlParameter("@TimeStamp", request.Timestamp), oParm ); context.SaveChanges(); response = Convert.ToInt32(oParm.Value); dbTran.Commit(); } catch (Exception ex) { dbTran.Rollback(); throw; } } } return response; }
/// <summary> /// Gets all current locations via ORM. Used for getting all locations with no distance calculation. /// </summary> /// <param name="request"></param> /// <returns></returns> public List<LocationData> GetCurrentLocations(LocationData request) { List<LocationData> response = new List<LocationData>(); using (var dbEntities = new TICPuppyLoveDbContext()) { response = (from loc in dbEntities.Locations //WHERE blah blah blah - Currently we are not filtering based on the request - return all orderby loc.UserID select new LocationData { UserID = loc.UserID, Latitude = loc.Latitude, Longitude = loc.Longitude, Accuracy = loc.Accuracy, Timestamp = loc.TimeStamp } ).ToList(); } return response; }
public Int32 DeleteConfigurations(ConfigMultiEntries request) { Int32 response = -1; using (var context = new TICPuppyLoveDbContext()) { using (var dbContextTransaction = context.Database.BeginTransaction()) { context.dbTransaction = dbContextTransaction; ConfigDTO cdto = new ConfigDTO { configs = request.ConfigEntries }; cdto.refConfigEntries = context.GetRefConfigData(); cdto.refConfigEntries = cdto.GetSpecificRefConfigs(); context.Ref_Config.RemoveRange(cdto.refConfigEntries); response = context.SaveChanges(); // everything good, commit transaction dbContextTransaction.Commit(); } } return response; }
public Int32 RemoveLocation(LocationData request) { Int32 response = -1; using (var dbEntities = new TICPuppyLoveDbContext()) { dbEntities.Locations.RemoveRange( dbEntities.Locations.Where(x => x.UserID == request.UserID)); response = dbEntities.SaveChanges(); } return response; }
public List<LocationData> GetNearestNeighbors(NearestNeighborRequest request) { List<LocationData> response = new List<LocationData>(); using (var context = new TICPuppyLoveDbContext()) { var Latitude = new SqlParameter("@Latitude", request.Latitude); var Longitude = new SqlParameter("@Longitude", request.Longitude); var Radius = new SqlParameter("@Radius", request.Radius); response = context.Database .SqlQuery<LocationData>("SP_GetNearestNeighbors @Latitude, @Longitude, @Radius", Latitude, Longitude, Radius ) .ToList(); } //EF not mapping UserID to the data contract but was able to map it to an alternate name. //Map it back response = GetLocBaseProperties(response); return response; }
public LocationData GetLocationByUserID(LocationData request) { LocationData response = new LocationData(); using (var dbEntities = new TICPuppyLoveDbContext()) { response = (from loc in dbEntities.Locations where loc.UserID == request.UserID select new LocationData { UserID = loc.UserID, Latitude = loc.Latitude, Longitude = loc.Longitude, Accuracy = loc.Accuracy, Timestamp = loc.TimeStamp } ).SingleOrDefault(); } return response; }
public List<LocationData> GetCurrentLocationsWithDistance(LocationData request) { List<LocationData> response = new List<LocationData>(); using (var context = new TICPuppyLoveDbContext()) { var UserID = new SqlParameter("@UserID", request.UserID); var Latitude = new SqlParameter("@Latitude", (request.Latitude > 0 && request.Longitude < 0) ? request.Latitude : SqlDecimal.Null); var Longitude = new SqlParameter("@Longitude", (request.Latitude > 0 && request.Longitude < 0) ? request.Longitude : SqlDecimal.Null); response = context.Database .SqlQuery<LocationData>("SP_GetAllLocationsWithDistance @UserID, @Latitude, @Longitude", UserID, Latitude, Longitude) .ToList(); } //EF not mapping UserID to the data contract but was able to map it to an alternate name. //Map it back response = GetLocBaseProperties(response); return response; }
public List<ConfigEntry> GetAllConfigurations() { List<ConfigEntry> response = new List<ConfigEntry>(); var result = new ConfigDTO(); using (var dbEntities = new TICPuppyLoveDbContext()) { result.refConfigEntries = dbEntities.GetRefConfigData(); response = result.CreateConfigCollection(); } return response; }
public long? GetResponseTypeIDByType(string responseType) { long? response = null; using (var dbEntities = new TICPuppyLoveDbContext()) { response = dbEntities.ResponseTypeID(responseType); } return response; }