コード例 #1
0
        public ActionResult Delete(int?id)
        {
            var client = db.Clients.Where(c => c.Id == id).Select(c => c).SingleOrDefault();
            var user   = db.Users.Where(u => u.Id == client.ApplicationId).Select(u => u).SingleOrDefault();
            var forums = db.Fora.Where(f => f.ClientId == client.Id).Select(f => f).ToList();

            foreach (var item in forums)
            {
                var           contents      = db.Contents.Where(c => c.ForumId == item.Id).Select(c => c).ToList();
                List <Client> checkedClient = new List <Client>();
                foreach (var content in contents)
                {
                    var contentclient = db.Clients.Where(c => c.Id == item.ClientId).Select(c => c).SingleOrDefault();
                    if (!checkedClient.Contains(contentclient))
                    {
                        InboxMessege messege = new InboxMessege();
                        messege.Messege = "The forum '" + item.Name + "' and all its contents has been deleted.";
                        messege.InboxId = contentclient.InboxId;
                        db.InboxMesseges.Add(messege);
                        checkedClient.Add(contentclient);
                    }
                    db.Contents.Remove(content);
                }
                db.Fora.Remove(item);
            }
            db.Users.Remove(user);
            db.Clients.Remove(client);
            db.SaveChanges();
            return(View("Index", "Home"));
        }
コード例 #2
0
 public ActionResult Index(Content content, string IsCreate, string message)
 {
     if (ModelState.IsValid)
     {
         var           userId        = User.Identity.GetUserId();
         var           clientId      = db.Clients.Where(c => c.ApplicationId == userId).Select(c => c.Id).SingleOrDefault();
         var           forum         = db.Fora.Where(f => f.Id == content.ForumId).Select(f => f).SingleOrDefault();
         var           contents      = db.Contents.Where(c => c.ForumId == forum.Id).Select(c => c).ToList();
         List <Client> checkedClient = new List <Client>();
         if (message != null && IsCreate != "yes")
         {
             var newContent = db.Contents.Where(c => c.Id == content.Id).SingleOrDefault();
             newContent.Message = message;
             foreach (var item in contents)
             {
                 var client = db.Clients.Where(c => c.Id == item.ClientId).Select(c => c).SingleOrDefault();
                 if (!checkedClient.Contains(client) && client.Id != clientId)
                 {
                     InboxMessege messege = new InboxMessege();
                     messege.Messege = "A message has been edited from '" + forum.Name + "'.";
                     messege.InboxId = client.InboxId;
                     db.InboxMesseges.Add(messege);
                     checkedClient.Add(client);
                 }
             }
             db.SaveChanges();
         }
         else
         {
             content.ClientId = clientId;
             db.Contents.Add(content);
             foreach (var item in contents)
             {
                 var client = db.Clients.Where(c => c.Id == item.ClientId).Select(c => c).SingleOrDefault();
                 if (!checkedClient.Contains(client) && client.Id != clientId)
                 {
                     InboxMessege messege = new InboxMessege();
                     messege.Messege = "A message has been added to '" + forum.Name + "'.";
                     messege.InboxId = client.InboxId;
                     db.InboxMesseges.Add(messege);
                     checkedClient.Add(client);
                 }
             }
             db.SaveChanges();
         }
         return(RedirectToAction("Index", new { forumId = content.ForumId, contentId = content.Id }));
     }
     ViewBag.Forum = content.ForumId;
     return(View(content));
 }
コード例 #3
0
        // GET: Contents/Delete/5
        public ActionResult Delete(int?id, bool?isTrue)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Content content = db.Contents.Find(id);
            var     forumId = content.ForumId;

            if (content == null)
            {
                return(View(content));
            }
            else
            {
                var           forum         = db.Fora.Where(f => f.Id == content.ForumId).Select(f => f).SingleOrDefault();
                var           contents      = db.Contents.Where(c => c.ForumId == forum.Id).Select(c => c).ToList();
                List <Client> checkedClient = new List <Client>();
                foreach (var item in contents)
                {
                    var client = db.Clients.Where(c => c.Id == item.ClientId).Select(c => c).SingleOrDefault();
                    if (client != null)
                    {
                        if (!checkedClient.Contains(client) && client.Id != content.ClientId)
                        {
                            InboxMessege messege = new InboxMessege();
                            messege.Messege = "A message has been deleted from '" + forum.Name + "'.";
                            messege.InboxId = client.InboxId;
                            db.InboxMesseges.Add(messege);
                            checkedClient.Add(client);
                        }
                    }
                }
                db.Contents.Remove(content);
                db.SaveChanges();
                return(RedirectToAction("Index", new { forumId, contentId = content.Id, isTrue }));
            }
        }
コード例 #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Forum         forum         = db.Fora.Find(id);
            var           contents      = db.Contents.Where(c => c.ForumId == id).Select(c => c).ToList();
            List <Client> checkedClient = new List <Client>();

            foreach (var item in contents)
            {
                var client = db.Clients.Where(c => c.Id == item.ClientId).Select(c => c).SingleOrDefault();
                if (!checkedClient.Contains(client) && client.Id != forum.ClientId)
                {
                    InboxMessege messege = new InboxMessege();
                    messege.Messege = "The forum '" + forum.Name + "' and all its contents has been deleted.";
                    messege.InboxId = client.InboxId;
                    db.InboxMesseges.Add(messege);
                    checkedClient.Add(client);
                }
                db.Contents.Remove(item);
            }
            db.Fora.Remove(forum);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #5
0
 public ActionResult Edit(Forum forum)
 {
     if (ModelState.IsValid)
     {
         db.Entry(forum).State = EntityState.Modified;
         var           contents      = db.Contents.Where(c => c.ForumId == forum.Id).Select(c => c).ToList();
         List <Client> checkedClient = new List <Client>();
         foreach (var item in contents)
         {
             var client = db.Clients.Where(c => c.Id == item.ClientId).Select(c => c).SingleOrDefault();
             if (!checkedClient.Contains(client))
             {
                 InboxMessege messege = new InboxMessege();
                 messege.Messege = "The forum '" + forum.Name + "' has been altered.";
                 messege.InboxId = client.InboxId;
                 db.InboxMesseges.Add(messege);
                 checkedClient.Add(client);
             }
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(forum));
 }