Пример #1
0
        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();
            }
        }
Пример #2
0
 public void AddTopic(Topic topic)
 {
     using (var db = new SampleContext())
     {
         db.Topics.Add(topic);
         db.SaveChanges();
     }
 }
Пример #3
0
 public void AddComment(Comment comment)
 {
     using (var db = new SampleContext())
     {
         db.Comments.Add(comment);
         db.SaveChanges();
     }
 }
Пример #4
0
 public void AddSection(Section section)
 {
     using (var db = new SampleContext())
     {
         db.Sections.Add(section);
         db.SaveChanges();
     }
 }
Пример #5
0
 public void Add(User user)
 {
     using (var db = new SampleContext())
     {
         db.Users.Add(user);
         db.SaveChanges();
     }
 }
Пример #6
0
 public void AddStream(Stream stream)
 {
     using (var db = new SampleContext())
     {
         db.Streams.Add(stream);
         db.SaveChanges();
     }
 }
Пример #7
0
 public void DeleteComment(int id)
 {
     using (var db = new SampleContext())
     {
         Comment comment = db.Comments.Find(id);
         db.Comments.Remove(comment);
         db.SaveChanges();
     }
 }
Пример #8
0
 public void EditPassword(int id, string password)
 {
     using (var db = new SampleContext())
     {
         var user = db.Users.Find(id);
         user.Password = password;
         db.SaveChanges();
     }
 }
Пример #9
0
 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();
     }
 }
Пример #10
0
 public void Decrease(int id)
 {
     using (var db = new SampleContext())
     {
         var user = db.Users.Find(id);
         user.Role = "user";
         db.SaveChanges();
     }
 }
Пример #11
0
 public void BanUser(int id)
 {
     using (var db = new SampleContext())
     {
         var user = db.Users.Find(id);
         user.IsBaned = true;
         db.SaveChanges();
     }
 }
Пример #12
0
 public void DeleteStream(int id)
 {
     using (var db = new SampleContext())
     {
         Stream stream = db.Streams.Find(id);
         db.Streams.Remove(stream);
         db.SaveChanges();
     }
 }
Пример #13
0
        public void UpdateMessages(int id)
        {
            User user;

            using (var db = new SampleContext())
            {
                user           = db.Users.Find(id);
                user.Messages += 1;
                db.SaveChanges();
            }
        }
Пример #14
0
 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();
     }
 }