Exemplo n.º 1
0
        public ActionResult Answer(UserPostViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    model.AddNew();
                    // what TODO
                    // should we check successful creation?
                    // should we redirect somewhere?
                }
                catch (Exception)
                {
                    return RedirectToAction("Error", "Home", new { msg = "Exception answering a post..." });
                }

            }
            return View("Details", model);
        }
Exemplo n.º 2
0
 //
 // GET: /UserPost/Answer/2
 public ActionResult Answer(int id)
 {
     if (Request.IsAuthenticated)
     {
         var question = userPostRepository.Get(id);
         if (question == null)
         {
             return View("NotFound");
         }
         else
         {
             var answer = new UserPostViewModel();
             answer.parent_post_id = question.id;
             answer.title = "RE: " + question.title;
             return View(answer);
         }
     }
     else
     {
         //return RedirectToAction("Error", "Home", new { msg = "Please log on for adding post..." });
         return RedirectToAction("LogOn", "User", new { msg = "Please log on for adding post..." });
     }
 }
Exemplo n.º 3
0
        public ActionResult Edit(int id, UserPostViewModel model)
        {
            user_post toEdit = userPostRepository.Get(id);

            if (ModelState.IsValid)
            {
                try
                {
                    model.ApplyChanges(toEdit);
                    userPostRepository.Save();
                }
                catch (Exception)
                {
                    return RedirectToAction("Error", "Home", new { msg = "Exception editing a post..." });
                }

            }
            return View("Details", model);
        }
Exemplo n.º 4
0
        public ActionResult Create(UserPostViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    user userLoggedOn = userRepository.GetByUsername(User.Identity.Name);
                    model.user_id = userLoggedOn.id;
                    model.parent_post_id = 0;
                    model.ranking_points = 0;
                    model.num_views = 0;
                    model.is_accepted_answer = false;
                    model.AddNew();
                    // what TODO
                    // should we check successful creation?
                    // should we redirect somewhere?
                }
                catch (Exception)
                {
                    return RedirectToAction("Error", "Home", new { msg = "Exception adding post..." });
                }

            }
            return View("Details", model);
        }