public void EditName(int id, string username) { using (var db = new SampleContext()) { var user = db.Users.Find(id); var comments = db.Comments.Where(c => c.AuthorId == id).ToList(); var topics = db.Topics.Where(t => t.AuthorId == id).ToList(); if (comments != null) { foreach (var c in comments) { c.Author = username; } } if (topics != null) { foreach (var t in topics) { t.Author = username; } } user.Username = username; db.SaveChanges(); } }
public void AddTopic(Topic topic) { using (var db = new SampleContext()) { db.Topics.Add(topic); db.SaveChanges(); } }
public void AddComment(Comment comment) { using (var db = new SampleContext()) { db.Comments.Add(comment); db.SaveChanges(); } }
public void AddSection(Section section) { using (var db = new SampleContext()) { db.Sections.Add(section); db.SaveChanges(); } }
public void Add(User user) { using (var db = new SampleContext()) { db.Users.Add(user); db.SaveChanges(); } }
public void AddStream(Stream stream) { using (var db = new SampleContext()) { db.Streams.Add(stream); db.SaveChanges(); } }
public void DeleteComment(int id) { using (var db = new SampleContext()) { Comment comment = db.Comments.Find(id); db.Comments.Remove(comment); db.SaveChanges(); } }
public void EditPassword(int id, string password) { using (var db = new SampleContext()) { var user = db.Users.Find(id); user.Password = password; db.SaveChanges(); } }
public void ConfirmEmail(string userName) { using (var db = new SampleContext()) { var user = db.Users.Where(u => u.Username == userName).FirstOrDefault(); user.ConfirmedEmail = true; db.SaveChanges(); } }
public void Decrease(int id) { using (var db = new SampleContext()) { var user = db.Users.Find(id); user.Role = "user"; db.SaveChanges(); } }
public void BanUser(int id) { using (var db = new SampleContext()) { var user = db.Users.Find(id); user.IsBaned = true; db.SaveChanges(); } }
public void DeleteStream(int id) { using (var db = new SampleContext()) { Stream stream = db.Streams.Find(id); db.Streams.Remove(stream); db.SaveChanges(); } }
public void UpdateMessages(int id) { User user; using (var db = new SampleContext()) { user = db.Users.Find(id); user.Messages += 1; db.SaveChanges(); } }
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(); } }