Exemplo n.º 1
0
 public ActionResult Create(int taksId, string returnUrl)
 {
     try
     {
         ViewBag.returnUrl = returnUrl;
         var task = new NewSolutionModel()
         {
             TaskId = taksId
         };
         return(View(task));
     }
     catch (Exception e)
     {
         return(RedirectToAction("Index", "Error", new { error = e.Message }));
     }
 }
Exemplo n.º 2
0
        public ActionResult Create(NewSolutionModel model, string returnUrl)
        {
            try
            {
                var solutionCreator = db.Users.Find(User.Identity.GetUserId());
                var parentTask      = db.Tasks.Include(x => x.Solutions).FirstOrDefault(x => x.Id == model.TaskId);
                if (solutionCreator != null)
                {
                    if (parentTask != null)
                    {
                        var solution = new Solution()
                        {
                            Content = model.Content, SolutionCreator = solutionCreator
                        };
                        parentTask.Solutions.Add(solution);
                        db.SaveChanges();

                        if (string.IsNullOrEmpty(returnUrl))
                        {
                            return(RedirectToAction("Index"));
                        }
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Задачи не существует!");
                        return(View());
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Пользователя не существует!");
                    return(View());
                }
            }
            catch (Exception e)
            {
                return(RedirectToAction("Index", "Error", new { error = e.Message }));
            }
        }