public void DeleteTopic(int id) { using (var db = new SampleContext()) { Topic topic = db.Topics.Find(id); List <Comment> comments = db.Comments.Where(c => c.TopicId == id).ToList(); foreach (var c in comments) { db.Comments.Remove(c); } db.Topics.Remove(topic); db.SaveChanges(); } }
public bool UserExist(string username, string password) { using (var db = new SampleContext()) { var users = db.Users.Select(c => new { login = c.Username, pas = c.Password }); foreach (var u in users) { if (u.login == username && u.pas == password) { return(true); } } } return(false); }