Exemplo n.º 1
0
        public IActionResult Index(MergeCourseClasses c)
        {
            string             s         = HttpContext.Session.GetString("SavedList");
            MergeCourseClasses mergedObj = new MergeCourseClasses();

            if ((s != null) || (s == ""))
            {
                mergedObj.CourseDetailList = JsonConvert.DeserializeObject <List <CourseModel> >(s);
            }
            else
            {
                return(RedirectToAction("Index"));
            }

            // Validate input fields before posting.
            if (ModelState.IsValid)
            {
                mergedObj.CourseDetails.Id          = c.CourseDetails.Id;
                mergedObj.CourseDetails.Code        = c.CourseDetails.Code;
                mergedObj.CourseDetails.Name        = c.CourseDetails.Name;
                mergedObj.CourseDetails.Url         = c.CourseDetails.Url;
                mergedObj.CourseDetails.Progression = c.CourseDetails.Progression;
                mergedObj.CourseDetailList.Add(mergedObj.CourseDetails);

                s = JsonConvert.SerializeObject(mergedObj.CourseDetailList);
                HttpContext.Session.SetString("SavedList", s);

                return(RedirectToAction("Index"));
            }
            return(View(mergedObj));
        }
Exemplo n.º 2
0
        public IActionResult Index()
        {
            string             s         = HttpContext.Session.GetString("SavedList");
            MergeCourseClasses mergedObj = new MergeCourseClasses();

            // Get session variable and deserialize if string is not/empty.
            if ((s != null) || (s == ""))
            {
                mergedObj.CourseDetailList = JsonConvert.DeserializeObject <List <CourseModel> >(s);
            }
            else
            {
                List <CourseModel> courseList = new List <CourseModel>
                {
                    new CourseModel(0, "DT102G", "ASP.NET Core med C#", "https://www.miun.se/utbildning/kursplaner-och-utbildningsplaner/Sok-kursplan/kursplan/?kursplanid=22325", "B")
                };
                mergedObj.CourseDetailList = courseList;
            }

            string s2 = JsonConvert.SerializeObject(mergedObj.CourseDetailList);

            // Session variable saving.
            HttpContext.Session.SetString("SavedList", s2);
            return(View(mergedObj));
        }
Exemplo n.º 3
0
        public IActionResult Delete(int id)
        {
            string             s         = HttpContext.Session.GetString("SavedList");
            MergeCourseClasses mergedObj = new MergeCourseClasses();

            if ((s != null) || (s == ""))
            {
                mergedObj.CourseDetailList = JsonConvert.DeserializeObject <List <CourseModel> >(s);
            }
            else
            {
                return(RedirectToAction("Index"));
            }
            mergedObj.CourseDetailList.RemoveAll(x => x.Id == id);
            s = JsonConvert.SerializeObject(mergedObj.CourseDetailList);
            HttpContext.Session.SetString("SavedList", s);

            return(RedirectToAction("Index"));
        }