public ActionResult CreateOffer(int id_mess, int id_theme)
 {
     var returnUrl = Url.Action("CreateOffer", new { id_mess = id_mess, id_theme = id_theme });
     //попробуем для начала подсоедениться к БТ
     if (!TryConnect(User.Identity.Name)) return RedirectToAction("Settings", new {returnUrl = returnUrl});
     var t = _db.tForumMessages.Find(id_mess);
     tOffer toffer;
     if (t != null)
     {
         //создаем замечание на основании сообщения
         toffer = new tOffer {tforummessages = t};
         //теперь нам нужны данные для комбиков
         ViewData["tBranch"] = _db.tBranch.ToList();
         ViewData["tProject"] = _db.tProject.ToList();
         ViewData["tReleaseProject"] = _db.tReleaseProject.ToList();
         ViewData["tReleaseProject_exec"] = _db.tReleaseProject.ToList();
         ViewData["tSubsystem"] = _db.tSubsystem.ToList();
         ViewData["id_mess"] = id_mess;
         ViewData["id_theme"] = id_theme;
         return View(toffer);
     }
     var tm = _db.tForumThemes.Find(id_theme);
     if (tm == null) return HttpNotFound();
     //создаем замечание на основании сообщения
     toffer = new tOffer {tforumthemes = tm};
     //теперь нам нужны данные для комбиков
     ViewData["tBranch"] = _db.tBranch.ToList();
     ViewData["tProject"] = _db.tProject.ToList();
     ViewData["tReleaseProject"] = _db.tReleaseProject.ToList();
     ViewData["tReleaseProject_exec"] = _db.tReleaseProject.ToList();
     ViewData["tSubsystem"] = _db.tSubsystem.ToList();
     ViewData["id_mess"] = id_mess;
     ViewData["id_theme"] = id_theme;
     return View(toffer);
 }
        public ActionResult CreateOffer([Bind(Include = "tOffer_error,tOffer_place,tOffer_tBranch_id,tOffer_tProject_id,tOffer_tReleaseProject_id,tOffer_tReleaseProject_exec_id,tOffer_tSubsystem_id")] 
                                        int id_mess, 
                                        int id_theme, tOffer toffer)
        {
            var val = Url.RequestContext.HttpContext.Request.Url.Scheme;
            var returnUrl = "";
            var href = "";
            if (toffer.tOffer_tReleaseProject_exec_id == 0)
            {
                ModelState.AddModelError("tOffer_tReleaseProject_exec_id", "Укажите версию реализации");
            }
            if (toffer.tOffer_tReleaseProject_id == 0)
            {
                ModelState.AddModelError("tOffer_tReleaseProject_id", "Укажите версию обнаружения");
            }
            if (id_mess != 0)
            {
                var t = _db.tForumMessages.Find(id_mess);
                toffer.tforummessages = t;
                if (!ModelState.IsValid)
                {
                    ViewData["tBranch"] = _db.tBranch.ToList();
                    ViewData["tProject"] = _db.tProject.ToList();
                    ViewData["tReleaseProject"] = _db.tReleaseProject.ToList();
                    ViewData["tReleaseProject_exec"] = _db.tReleaseProject.ToList();
                    ViewData["tSubsystem"] = _db.tSubsystem.ToList();
                    ViewData["id_mess"] = id_mess;
                    ViewData["id_theme"] = id_theme;
                    return View(toffer);
                }
                _db.tOffer.Add(toffer);
                _db.SaveChanges();
                returnUrl = Url.Action("Index", "ForumMessages", new { id = t.tForumThemes.Id, id_list = t.tForumThemes.tForumList.Id });
                href = Url.Action("Index", "ForumMessages", new { id = t.tForumThemes.Id, id_list = t.tForumThemes.tForumList.Id }, val);
            }
            else
            {
                var t = _db.tForumThemes.Find(id_theme);
                toffer.tforumthemes = t;
                if (!ModelState.IsValid)
                {
                    ViewData["tBranch"] = _db.tBranch.ToList();
                    ViewData["tProject"] = _db.tProject.ToList();
                    ViewData["tReleaseProject"] = _db.tReleaseProject.ToList();
                    ViewData["tReleaseProject_exec"] = _db.tReleaseProject.ToList();
                    ViewData["tSubsystem"] = _db.tSubsystem.ToList();
                    ViewData["id_mess"] = id_mess;
                    ViewData["id_theme"] = id_theme;
                    return View(toffer);
                }
                _db.tOffer.Add(toffer);
                _db.SaveChanges();
                returnUrl = Url.Action("Index", "ForumMessages", new { id = t.Id, id_list = t.tForumList.Id });
                href = Url.Action("Index", "ForumMessages", new { id = t.Id, id_list = t.tForumList.Id }, val);
            }
            //и теперь мы создаем замечание - выделим отдельно, так как там много кода
            toffer.tOffer_docnumber =  Create(toffer.Id,User.Identity.Name,href);
            _db.Entry(toffer).State = EntityState.Modified;
            _db.SaveChanges();
            //а теперь допишем сообщение в форум
            var m = new tForumMessages
            {
                tUsers = _db.Users.First(a => a.UserName == User.Identity.Name),
                tForumMessages_datetime = System.DateTime.Now,
                tForumMessages_hide = false,
                tForumMessages_messages =
                    "<p>Создано замечание №" + toffer.tOffer_docnumber + "</p>",
                tForumThemes = id_mess != 0 ? toffer.tforummessages.tForumThemes : toffer.tforumthemes
            };

            _db.tForumMessages.Add(m);
            _db.SaveChanges();

            return RedirectToLocal(returnUrl);
        }