public IActionResult MyCourse(int id) { List <Course> courses = _courseRepository.GetMyCourse(id); MyCourseViewModel myCourseViewModel = new MyCourseViewModel { courses = courses, success = null }; return(View(myCourseViewModel)); }
/// <summary> /// 顯示我的課程 /// </summary> /// <returns></returns> public ActionResult MyCourse() { try { //驗證授權:一般會員 var pass = roleAuth.UserAuth(); if (pass == true) { ViewBag.UserName = roleAuth.UserName(); ViewBag.RoleName = "User"; } else { TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!"; return(RedirectToAction("Logout", "Home")); } //取得會員Id var UserEmail = User.Identity.Name; MemberOperation member = new MemberOperation(); var MemberId = member.Get(UserEmail).MemberNo; //取得會員課程 MemberCourseOperation mco = new MemberCourseOperation(); var LstCourse = mco.Get(MemberId); var courses = LstCourse.ToLookup(o => o.CourseType_no, o => o.Num); //將會員課程寫入我的課程ViewModel List <MyCourseViewModel> LstMcv = new List <MyCourseViewModel>(); foreach (var type in courses) { MyCourseViewModel mcv = new MyCourseViewModel(); CourseTypeOperation cto = new CourseTypeOperation(); var ClassName = cto.Get(type.Key).Name; //取得課程類型名稱 int addCnt = 0; //加總用變數 mcv.Name = ClassName; //將同課程類型的課堂數加總 foreach (int cnt in type) { addCnt += cnt; } mcv.count = addCnt; LstMcv.Add(mcv); } return(View(LstMcv)); } catch (Exception ex) { ViewBag.Msg = ex.ToString(); return(RedirectToAction("Logout", "Home")); } }
public ELearningPage() { InitializeComponent(); string studentId = string.Empty; if (App.Current.Properties.ContainsKey("StudentId")) { studentId = App.Current.Properties["StudentId"] as string; } model = new MyCourseViewModel(studentId); BindingContext = model; }
public IActionResult AddCourse(int courseId) { var accountId = Request.Cookies["id"]; _courseRepository.AddCourse(courseId, Int32.Parse(accountId)); HttpContext.Session.SetString("success", "Đăng ký khóa học thành công"); List <Course> courses = _courseRepository.GetMyCourse(Int32.Parse(accountId)); MyCourseViewModel myCourseViewModel = new MyCourseViewModel { courses = courses, success = HttpContext.Session.GetString("success") }; return(View("MyCourse", myCourseViewModel)); }
//我的课程 public ActionResult Mycourse(int userid) { MyCourseViewModel mcv = new MyCourseViewModel(); mcv.Uses1 = userManager.IEGetUsersById(userid); mcv.courses = dbContext.Add_Course.Where(e => e.UserId == userid); mcv.collect_courses = dbContext.Collect.Where(b => b.User_Id == userid && b.Collect_Type == "课程"); ViewBag.userid = userid; mcv.User = dbContext.User.Where(c => c.UserID == userid).FirstOrDefault(); Session["Guanzhu"] = 0; //关注的人数 mcv.UserA = userManager.CountGuanzhu(userid).Count(); //粉丝数 mcv.UserB = userManager.CountGuanzhu1(userid).Count(); //关注的人 mcv.UsesAa = userManager.CountGuanzhu(userid); //粉丝 mcv.UsesBb = userManager.CountGuanzhu1(userid); //判断是否为粉丝 foreach (var item in userManager.CountGuanzhu1(userid)) { if (Session["userid"] != null) { if (item.UserA == userid) { Session["Guanzhu"] = 1;//表示已经关注 break; } } else { break; } } return(View(mcv)); }
public MyCoursePage() { InitializeComponent(); BindingContext = viewModel = new MyCourseViewModel(); }