public ActionResult Create([Bind(Include = "Id,tForumThemes_name,tForumThemes_datetime,tForumThemes_desc,tForumThemes_top,tForumThemes_close")] int? id, tForumThemes tForumThemes)
        {
            tForumThemes.tForumList = _db.tForumLists.Find(id);
            tForumThemes.tForumThemes_datetime = DateTime.Now;
            tForumThemes.tUsers = _db.Users.First(a => a.UserName == User.Identity.Name);
            tForumThemes.tForumThemes_hide = false;

            var userId = tForumThemes.tUsers.Id;
            if (tForumThemes.tForumThemes_desc != null)
            {
                tForumThemes.tForumThemes_desc = WebUtility.HtmlDecode(tForumThemes.tForumThemes_desc);
            }
            if (!ModelState.IsValid) return View(tForumThemes);
            if (User.IsInRole("user"))
            {
                //это я поставлю на всякий случай - защита от самого себя
                //пользователь не может создавать закрепленные темы
                tForumThemes.tForumThemes_top = false;
                tForumThemes.tForumThemes_close = false;
            }
            _db.tForumThemes.Add(tForumThemes);
            _db.SaveChanges();
            var r = _db.Roles.ToList();
            foreach (var item in r)
            {
                //по ролям
                foreach (var item2 in _db.Users.Where(a => a.Roles.Any(b => b.RoleId == item.Id)).Where(a => a.Id != userId))
                {
                    //по пользователям в роли
                    if (
                        _db.tUserNewThemes.Where(a => a.tUsers.Id == item2.Id)
                            .Any(b => b.tForumThemes.Id == tForumThemes.Id)) continue;
                    var n = new tUserNewThemes { tForumThemes = tForumThemes, tUsers = item2 };
                    _db.tUserNewThemes.Add(n);
                    _db.SaveChanges();
                }
            }
            //отсылаем сообщение всем модераторам
            var val = Url.RequestContext.HttpContext.Request.Url.Scheme;
            var href = Url.Action("Index", "ForumMessages", new { id = tForumThemes.Id, id_list = tForumThemes.tForumList.Id }, val);
            Code.Notify.NewThemes(tForumThemes.Id, href, userId);

            return RedirectToAction("Index", "ForumMessages", new { id = tForumThemes.Id });
        }
        public ActionResult Create([Bind(Include = "tForumMessages_messages")] int? id, tForumMessages tForumMessages)
        {
            tForumMessages.tForumThemes = _db.tForumThemes.Find(id);
            tForumMessages.tUsers = _db.Users.First(a => a.UserName == User.Identity.Name);
            tForumMessages.tForumMessages_datetime = DateTime.Now;
            tForumMessages.tForumMessages_hide = false;
            var userId = tForumMessages.tUsers.Id;
            if (tForumMessages.tForumMessages_messages != null)
            {
                tForumMessages.tForumMessages_messages = WebUtility.HtmlDecode(tForumMessages.tForumMessages_messages);
            }
            if (!ModelState.IsValid)
                return RedirectToAction("Index", new {id, id_list = tForumMessages.tForumThemes.tForumList.Id});

            _db.tForumMessages.Add(tForumMessages);
            _db.SaveChanges();
            var r = _db.Roles.ToList();
            foreach (var item2 in r.SelectMany(item => _db.Users.Where(a => a.Roles.Any(b => b.RoleId == item.Id)).Where(a => a.Id != userId)))
            {
                //по пользователям в роли
                if (!_db.tUserNewThemes.Where(a => a.tUsers.Id == item2.Id).Any(b => b.tForumThemes.Id == tForumMessages.tForumThemes.Id))
                {
                    var n = new tUserNewThemes {tForumThemes = tForumMessages.tForumThemes, tUsers = item2};
                    _db.tUserNewThemes.Add(n);
                    _db.SaveChanges();
                }
                //Также новое сообщение
                if (
                    _db.tUserNewMessages.Where(a => a.tUsers.Id == item2.Id)
                        .Any(b => b.tForumMessages.Id == tForumMessages.Id)) continue;
                var nm = new tUserNewMessages {tForumMessages = tForumMessages, tUsers = item2};
                _db.tUserNewMessages.Add(nm);
                _db.SaveChanges();
            }
            var val = Url.RequestContext.HttpContext.Request.Url.Scheme;
            var href = Url.Action("Index", "ForumMessages", new { id = tForumMessages.tForumThemes.Id, id_list = tForumMessages.tForumThemes.tForumList.Id }, val);
            Code.Notify.NewMessage(tForumMessages.Id, href, userId);
            return RedirectToAction("Index", new { id = id, id_list = tForumMessages.tForumThemes.tForumList.Id });
        }