public void DeleteCity(int CityId, bool IsRemote) { var city = _dbContext.DictionaryCity.Include(x => x.Location).Where(x => x.DictionaryCityId == CityId).First(); var location = city.Location.ToList(); foreach (var loc in location) { var result = _dbContext.Conference.Where(b => b.LocationId == loc.LocationId); if (result != null) { foreach (var conf in result) { if (IsRemote) { conf.LocationId = 161; } else { conf.LocationId = 162; } } } _dbContext.Remove(loc); } _dbContext.Remove(city); _dbContext.SaveChanges(); }
public void DeleteSpeaker(int SpeakerId) { List <SpeakerxConference> conferencesWithDeletedSpeaker = _dbContext.SpeakerxConference.Where(x => x.SpeakerId == SpeakerId).ToList(); Speaker defaultSpeaker = _dbContext.Speaker.FirstOrDefault(x => x.SpeakerId == 30); foreach (var sxc in conferencesWithDeletedSpeaker) { _dbContext.Remove(sxc); _dbContext.SaveChanges(); _dbContext.SpeakerxConference.Add(new SpeakerxConference() { SpeakerId = 30, IsMainSpeaker = true, ConferenceId = sxc.ConferenceId, Conference = sxc.Conference, Speaker = defaultSpeaker }); _dbContext.SaveChanges(); } Speaker current = _dbContext.Speaker.FirstOrDefault(x => x.SpeakerId == SpeakerId); _dbContext.Remove(current); _dbContext.SaveChanges(); }
public bool DeleteType(int TypeId, bool IsRemote) { try { _dbContext.Remove(_dbContext.DictionaryConferenceType.First(a => a.DictionaryConferenceTypeId == TypeId)); _dbContext.SaveChanges(); return(true); } catch { return(false); } }
public bool DeleteCategory(int CategoryId) { try { _dbContext.Remove(_dbContext.DictionaryConferenceCategory.First(a => a.DictionaryConferenceCategoryId == CategoryId)); _dbContext.SaveChanges(); return(true); } catch { return(false); } }
public void DeleteCountry(int CountryId, bool IsRemote) { var country = _dbContext.DictionaryCountry.Where(x => x.DictionaryCountryId == CountryId).FirstOrDefault(); var countys = _dbContext.DictionaryCounty.Where(x => x.DictionaryCountryId == CountryId).ToList(); foreach (var county in countys) { var cities = _dbContext.DictionaryCity.Where(x => x.DictionaryCountyId == county.DictionaryCountyId).ToList(); foreach (var city in cities) { var location = _dbContext.Location.Where(x => x.CityId == city.DictionaryCityId).ToList(); foreach (var loc in location) { var result = _dbContext.Conference.Where(b => b.LocationId == loc.LocationId).Include(x => x.ConferenceType).ToList(); if (result != null) { foreach (var conf in result) { if (conf.ConferenceType.IsRemote) { conf.LocationId = 161; } else { conf.LocationId = 162; } } } _dbContext.Remove(loc); } _dbContext.Remove(city); } _dbContext.Remove(county); } _dbContext.Remove(country); _dbContext.SaveChanges(); }
public bool DeleteCounty(int CountyId) { try { var county = _dbContext.DictionaryCounty.Where(x => x.DictionaryCountyId == CountyId).FirstOrDefault(); var city = _dbContext.DictionaryCity.Where(x => x.DictionaryCountyId == CountyId).ToList(); foreach (var c in city) { var location = _dbContext.Location.Where(x => x.CityId == c.DictionaryCityId); foreach (var loc in location) { var result = _dbContext.Conference.Where(b => b.LocationId == loc.LocationId).Include(x => x.ConferenceType); if (result != null) { foreach (var conf in result) { if (conf.ConferenceType.IsRemote) { conf.LocationId = 161; } else { conf.LocationId = 162; } } } _dbContext.Remove(loc); } _dbContext.Remove(c); } _dbContext.Remove(county); _dbContext.SaveChanges(); return(true); } catch { return(false); } }