public async Task <ActionResult> DeleteRightSolution(int?id)
        {
            MathTaskSolution mathTaskSolution = await db.RequestSolutions.FindAsync(id);

            // Нельзя удалить уже проверенное решение
            if (mathTaskSolution.IsChecked)
            {
                return(RedirectToAction("MyRightSolutions"));
            }
            // Удалим информацию, что данный пользователь уже решал данную задачу.
            var req   = db.Requests.Find(mathTaskSolution.MathTaskId);
            var curId = this.User.Identity.GetUserId();
            var user  = db.Users.Find(curId);

            req.Executors.Remove(user);
            req.RequestSolutions.Remove(mathTaskSolution);

            req.RightMathTaskSolution = null;

            db.Entry(req).State = EntityState.Modified;;
            db.RequestSolutions.Remove(mathTaskSolution);
            await db.SaveChangesAsync();

            return(RedirectToAction("MyRightSolutions"));
        }
        public ActionResult CreateRightSolution([Bind(Include = "Id,Name,Comment,MathTaskId")] MathTaskSolution mathTaskSolution, HttpPostedFileBase error)
        {
            var curId = this.User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                // если получен файл
                var current = DateTime.Now;
                var user    = db.Users.Find(curId);

                if (error != null)
                {
                    Document doc = new Document();
                    doc.Size = error.ContentLength;
                    // Получаем расширение
                    string ext = error.FileName.Substring(error.FileName.LastIndexOf('.'));
                    doc.Type = ext;
                    // сохраняем файл по определенному пути на сервере
                    string path = current.ToString(user.Id.GetHashCode() + "dd/MM/yyyy H:mm:ss").Replace(":", "_").Replace("/", ".") + ext;
                    error.SaveAs(Server.MapPath("~/Files/RequestSolutionFiles/" + path));
                    doc.Url = path;

                    mathTaskSolution.Document = doc;
                    db.Documents.Add(doc);
                }
                else
                {
                    mathTaskSolution.Document = null;
                }

                var req = db.Requests.Find(mathTaskSolution.MathTaskId);
                mathTaskSolution.MathTask = req;
                mathTaskSolution.Author   = user;
                mathTaskSolution.AuthorId = user.Id;
                mathTaskSolution.IsRight  = false;
                mathTaskSolution.Date     = DateTime.Now;
                mathTaskSolution.IsRight  = true;

                // Отметим, что решение относится к этой задаче
                req.RequestSolutions.Add(mathTaskSolution);
                req.Executors.Add(user);

                // Поставим как правильное решение
                req.RightMathTaskSolution  = mathTaskSolution;
                req.RightRequestSolutionId = mathTaskSolution.Id;

                db.Entry(req).State = EntityState.Modified;

                db.RequestSolutions.Add(mathTaskSolution);

                db.SaveChanges();
                return(RedirectToAction("MyRightSolutions"));
            }


            return(RedirectToAction("MyRightSolutions"));
        }
        //[Authorize]
        public ActionResult DistributeChangeStatus(int requestSolutionId, int status)
        {
            var             curId = HttpContext.User.Identity.GetUserId();
            ApplicationUser user  = db.Users.First(m => m.Id == curId);

            if (user == null)
            {
                return(RedirectToAction("LogOff", "Account"));
            }

            MathTaskSolution req = db.RequestSolutions.Find(requestSolutionId);

            switch (status)
            {
            case 0:
            {
                req.IsChecked = false;
                req.IsRight   = false;
                break;
            }

            case 1:
            {
                req.IsChecked = true;
                req.IsRight   = true;
                break;
            }

            case 2:
            {
                req.IsChecked = true;
                req.IsRight   = false;
                break;
            }
            }


            if (req != null)
            {
                db.Entry(req).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }