Esempio n. 1
0
        /// <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"));
            }
        }
Esempio n. 2
0
        //取得我的帳戶會員資料
        private MemberInfoViewModel GetAccount()
        {
            if (User.Identity.IsAuthenticated == true) //若會員為登入狀態
            {
                string Account = User.Identity.Name;   //取得會員Email

                //找出該會員資料
                MemberOperation mo     = new MemberOperation();
                var             member = mo.Get(Account);

                MemberInfoViewModel memInVM = new MemberInfoViewModel();
                string date = member.Birthday.ToString("yyyy-MM-dd").Substring(0, 10);
                memInVM.Email      = member.Email;
                memInVM.Birthday   = date;
                memInVM.CreateTime = member.CreateTime;
                memInVM.Name       = member.Name;
                memInVM.Passway    = member.PassWay;
                memInVM.Sex        = member.Sex;

                if (member.Status == true)
                {
                    memInVM.Status = "有效會員";
                }
                else
                {
                    memInVM.Status = "無效會員";
                }
                memInVM.Tel = member.Tel;

                return(memInVM);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 顯示我的預約課程紀錄
        /// </summary>
        /// <returns></returns>
        public ActionResult MyBooking()
        {
            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             id        = member.Get(UserEmail).MemberNo;

                CourseOperation co       = new CourseOperation();
                var             nowdata  = co.GetBooking(id);     //尚未結束之預約課程
                var             pastdata = co.GetPastBooking(id); //已結束之預約課程

                CourseTypeOperation cto       = new CourseTypeOperation();
                ClassroomOperation  classroom = new ClassroomOperation();
                StoreOperation      so        = new StoreOperation();
                TeacherOperation    to        = new TeacherOperation();

                BookingGroupViewModel booking = new BookingGroupViewModel();
                booking.FutureBooking = new List <FutureBookingViewModel>();
                booking.PastBooking   = new List <PastBookingViewModel>();

                foreach (var item in nowdata)
                {
                    FutureBookingViewModel fbv = new FutureBookingViewModel()
                    {
                        CourseNo   = item.CourseNo,                                                                 //課程代號
                        CourseName = cto.Get(item.CourseType_No).Name,                                              //課程名稱
                        Date       = item.ClassDate.ToShortDateString(),                                            //日期
                        Classroom  = classroom.Get(item.Classroom_No).Name,                                         //教室
                        Store      = so.GetName(classroom.Get(item.Classroom_No).Store_No),                         //場館
                        Time       = item.StartTime.ToShortTimeString() + " ~ " + item.EndTime.ToShortTimeString(), //上課時間
                        Teacher    = to.GetName(item.Teacher_No)                                                    //教練名字
                    };
                    booking.FutureBooking.Add(fbv);
                }

                foreach (var item in pastdata)
                {
                    PastBookingViewModel pbv = new PastBookingViewModel()
                    {
                        CourseNo   = item.CourseNo,                                                                 //課程代號
                        CourseName = cto.Get(item.CourseType_No).Name,                                              //課程名稱
                        Date       = item.ClassDate.ToShortDateString(),                                            //日期
                        Classroom  = classroom.Get(item.Classroom_No).Name,                                         //教室
                        Store      = so.GetName(classroom.Get(item.Classroom_No).Store_No),                         //場館
                        Time       = item.StartTime.ToShortTimeString() + " ~ " + item.EndTime.ToShortTimeString(), //上課時間
                        Teacher    = to.GetName(item.Teacher_No)                                                    //教練名字
                    };
                    booking.PastBooking.Add(pbv);
                }

                return(View(booking));
            }

            catch (Exception ex)
            {
                TempData["Msg"] = ex.ToString();
                return(RedirectToAction("Logout", "Home"));
            }
        }
Esempio n. 4
0
        public ActionResult SeriesDetail(SeriesDetailViewModel model)
        {
            try
            {
                //驗證授權:一般會員
                var pass = roleAuth.UserAuth();
                if (pass == true)
                {
                    ViewBag.UserName = roleAuth.UserName();
                    ViewBag.RoleName = "User";
                }
                else
                {
                    TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!";
                    return(RedirectToAction("Logout", "Home"));
                }

                var             UserEmail = User.Identity.Name;
                MemberOperation member    = new MemberOperation();
                //取得會員Id
                var MemberId = member.GetNo(UserEmail);
                //取得會員資料
                var memberData = member.Get(UserEmail);
                //購買方案數量
                var BuyCnt = Convert.ToInt16(model.Count);


                //新增方案購買紀錄
                PurchaseRecord purchaseRecord = new PurchaseRecord();
                purchaseRecord.Date            = DateTime.Now;   //購買日期
                purchaseRecord.Count           = BuyCnt;         //購買數量
                purchaseRecord.PayStatus       = true;           //付款狀態
                purchaseRecord.CourseSeries_No = model.SeriesId; //方案代號
                purchaseRecord.Member_No       = MemberId;       //會員id

                PurchaseRecordOperation pr = new PurchaseRecordOperation();
                pr.Add(purchaseRecord);

                //找出課程方案內容
                CourseSeriesDetailOperation csd = new CourseSeriesDetailOperation();
                var seriesDetails = csd.Get(model.SeriesId);
                //找出會員課程table筆數
                MemberCourseOperation mco = new MemberCourseOperation();
                int dataCnt = mco.GetCount();

                //將課程方案內容新增至會員課程
                List <MemberCourse> LstCourses = new List <MemberCourse>();
                foreach (var item in seriesDetails)
                {
                    MemberCourse        memberCourse = new MemberCourse();
                    CourseTypeOperation cto          = new CourseTypeOperation();
                    memberCourse.MemberCourseNo = dataCnt + 1;
                    memberCourse.CourseType_no  = item.CourseType_No; //課程類型代號
                    memberCourse.Member_No      = MemberId;           //會員id
                    memberCourse.Num            = item.Num * BuyCnt;  //課程堂數=原方案內容課程數*購買數量

                    LstCourses.Add(memberCourse);
                }


                mco.Add(LstCourses);

                return(RedirectToAction("MyPurchaseSeries", new { MemberId }));
            }
            catch (Exception ex)
            {
                TempData["Msg"] = ex.ToString();
                return(RedirectToAction("Logout", "Home"));
            }
        }
Esempio n. 5
0
        public ActionResult Login(LoginViewModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                MemberOperation memberDataOperation = new MemberOperation();
                RoleOperation   roleDataOperation   = new RoleOperation();

                if (memberDataOperation.CheckUserData(model))
                {
                    LoginUser user = new LoginUser();
                    //登入會員的角色編號
                    var tmpRole = from c in memberDataOperation.Get()
                                  where model.Email == c.Email
                                  select c.Role_No;

                    foreach (var item in tmpRole)
                    {
                        if (item.Equals(1))
                        {
                            user.Identity = Identity.User;
                        }
                        else if (item.Equals(2))
                        {
                            user.Identity = Identity.Admin;
                        }
                    }
                    //登入會員的名稱
                    user.UserName = memberDataOperation.user.Name;
                    //登入會員的帳號
                    user.UserEmail = memberDataOperation.user.Email.ToString();

                    FormsAuthManager authManager = new FormsAuthManager();
                    authManager.SignIn(user);
                    switch (user.Identity)
                    {
                    case Identity.User:
                        return(RedirectToAction("Index", "Home"));

                    case Identity.Admin:
                        return(RedirectToAction("Index", "Admin"));

                    default:
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "無效的帳號或密碼。");
                    return(View());
                }
            }
            catch (Exception ex)
            {
                TempData["Msg"] = ex.ToString();
                return(View());
            }
        }