public static List <Category> GetCategories() { using (Vacancy_ModelContainer db = new Vacancy_ModelContainer()) { return(db.CategorySet.ToList()); } }
public static void setVacancies(string url, string name) { Category category = GetCategory(url); category.Category_Name = name; using (Vacancy_ModelContainer db = new Vacancy_ModelContainer()) { if (!db.CategorySet.Any(a => a.Category_Name == category.Category_Name)) { db.CategorySet.Add(category); db.SaveChanges(); } category.Id = db.CategorySet.Where(w => w.Category_Name == category.Category_Name).Select(s => s.Id).Single(); if (!Equal(category.Vacancy.ToList(), db.CategorySet.Where(w => w.Category_Name == category.Category_Name).Single().Vacancy.ToList())) { db.Database.ExecuteSqlCommand("delete from VacancySet where CategoryId =" + db.CategorySet.Where(g => g.Category_Name == category.Category_Name).Select(s => s.Id).Single().ToString()); db.VacancySet.AddRange(category.Vacancy.ToList()); db.SaveChanges(); } } }