コード例 #1
0
 public ActionResult Edit(int? id)
 {
     if (id.HasValue)
     {
         using (var repository = new EducationPlanRepository())
         {
             EducationPlanModel model = repository.Find(id.Value);
             EducationPlanViewModel viewModel = Mapper.Map<EducationPlanViewModel>(model);
             return View(viewModel);
         }
     }
     else
     {
         throw new ArgumentException("Id must be provided");
     }
 }
コード例 #2
0
        /// <summary>
        /// Fetches an education plan with a user given id and returns a rendered view containing a form which 
        /// lets the user read and comment it.
        /// </summary>
        /// <param name="id">The id supplied by the user.</param>
        /// <returns>A rendered view containing info about the education plan and a form 
        /// for commenting the education plan.</returns>
        /// <exception cref="ArgumentException">Thrown when no id is supplied by the user.</exception>
        public ActionResult Details(int? id)
        {
            //If no id is supplied, an exception is thrown.
            if (!id.HasValue)
            {
                throw new ArgumentException("Id must be provided");
            }
            EducationPlanModel model;
            using (var repository = new EducationPlanRepository())
            {
                model = repository.Find(id.Value);
                if (model != null)
                {
                    model.EducationPlanComments = (IList<EducationPlanCommentModel>)repository.GetCommentsForEducationPlan(id.Value);
                    EducationPlanViewModel viewModel = Mapper.Map<EducationPlanViewModel>(model);
                    return View(viewModel);
                }
            }

            return HttpNotFound();
        }