コード例 #1
0
        public ActionResult AddCourse(string name, string description, List <int> modules, List <int> packages)
        {
            string            message  = string.Empty;
            bool              errored  = false;
            CourseRepository  repo     = new CourseRepository();
            PackageRepository pckgRepo = new PackageRepository();

            if (string.IsNullOrEmpty(name))
            {
                errored = true;
                message = "Missing value";
            }
            else
            {
                try
                {
                    int newCourseID = repo.AddCourse(name);
                    if (modules != null && modules.Count > 0)
                    {
                        repo.AddModulesToCourse(newCourseID, modules);
                    }
                    pckgRepo.AddDefaultPackage(newCourseID);
                    if (packages != null && packages.Count > 0)
                    {
                        pckgRepo.AddPackagesToCourse(newCourseID, packages);
                    }
                }
                catch (Exception exc)
                {
                    errored = true;
                    message = exc.ToString();
                }
            }

            if (!errored)
            {
                message = "Changes Saved";
            }

            return(Json(new { Errored = errored, Message = message }, JsonRequestBehavior.AllowGet));
        }