TAPS.MVC.Controllers.CourseController.Edit C# (CSharp) Method

Edit() public method

public Edit ( string id ) : System.Web.Mvc.ActionResult
id string
return System.Web.Mvc.ActionResult
        public ActionResult Edit(string id)
        {
            // default value if nothing found
            ActionResult result = View("Index"); // = RedirectToAction("Index");
            ViewData["Title"] = "Course Edit";
            ViewData["Message"] = "Edit Course Details!";
            int courseId;
            try
            {
                courseId = Convert.ToInt32(id);
            }
            catch (Exception) //not an integer
            {
                return RedirectToAction("Index", "Course");
            }

            try
            {
                Course course = (new CourseProvider()).GetCourseByID(courseId);
                if (course != null)
                {
                    PrepareProfessorList(course);
                    result = View(course);
                }
            }
            catch (Exception)
            {
                result = View("Index");
            }
            return result;
        }

Same methods

CourseController::Edit ( [ Prefix = "")]Coursecourse, string id, string ProfessorList ) : object

Usage Example

コード例 #1
0
        public void CourseController_should_Edit_And_Save()
        {
            CourseController controller = new CourseController();

            //FormCollection form = new FormCollection();

            //form["CourseName"] = "CSTesting";
            //form["Monday"] = "True";
            //form["StartHour"] = "14";

            var course = new Course
                             {
                                 CourseName = "CSTesting",
                                 Monday = true,
                                 StartHour = 14,
                                 EndHour = 17,
                                 AssignedProfessor = null
                             };
            var result = controller.Edit(course, "139", "3");

            Assert.IsNotNull(result, "Expected client side redirect");
            Assert.AreEqual("Course Updated",controller.ViewData["Message"], "Expected another message!!");
            //Assert.AreEqual(controller.);
        }
All Usage Examples Of TAPS.MVC.Controllers.CourseController::Edit