Ejemplo n.º 1
0
        public ActionResult TeacherAdd(TeacherViewModel vm)
        {
            try
            {
                //驗證授權:管理員
                var pass = roleAuth.AdminAuth();
                if (pass == true)
                {
                    ViewBag.UserName = roleAuth.UserName();
                    ViewBag.RoleName = "Admin";
                }
                else
                {
                    TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!";
                    return(RedirectToAction("Login", "Home"));
                }

                //vm.CreateTime = DateTime.Now.ToString();

                TeacherOperation op = new TeacherOperation();
                var result          = op.Add(vm);
                TempData["result"] = result;
                return(RedirectToAction(nameof(Teacher)));
            }
            catch (Exception ex)
            {
                TempData["Msg"] = ex.ToString();
                return(RedirectToAction("Logout", "Home"));
            }
        }
Ejemplo n.º 2
0
        public ActionResult TeacherEdit(TeacherViewModel model)
        {
            try
            {
                //驗證授權:管理員
                var pass = roleAuth.AdminAuth();
                if (pass == true)
                {
                    ViewBag.UserName = roleAuth.UserName();
                    ViewBag.RoleName = "Admin";
                }
                else
                {
                    TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!";
                    return(RedirectToAction("Login", "Home"));
                }

                TeacherOperation operation = new TeacherOperation();
                operation.Update(model);
                return(RedirectToAction(nameof(Teacher)));
            }
            catch (Exception ex)
            {
                TempData["Msg"] = ex.ToString();
                return(RedirectToAction("Logout", "Home"));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 管理教練首頁 顯示所有教練資料
        /// </summary>
        /// <returns></returns>
        public ActionResult Teacher()
        {
            try
            {
                //驗證授權:管理員
                var pass = roleAuth.AdminAuth();
                if (pass == true)
                {
                    ViewBag.UserName = roleAuth.UserName();
                    ViewBag.RoleName = "Admin";
                }
                else
                {
                    TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!";
                    return(RedirectToAction("Login", "Home"));
                }

                //取得所有教練資料
                TeacherOperation operation = new TeacherOperation();
                var teacher = operation.Get();

                //放入顯示網頁的viewModel
                List <TeacherViewModel> models = new List <TeacherViewModel>();
                foreach (var item in teacher)
                {
                    var status = "";
                    if (item.Status.Equals(true))
                    {
                        status = "現役教練";
                    }
                    else
                    {
                        status = "目前無教學服務";
                    }

                    TeacherViewModel vm = new TeacherViewModel()
                    {
                        Name       = item.Name,
                        CreateTime = item.CreateTime.ToString("yyyy-MM-dd").Substring(0, 10),
                        EMail      = item.Email,
                        BirDate    = item.Birthday.ToString("yyyy-MM-dd").Substring(0, 10),
                        TeacherNo  = item.TeacherNo,
                        Status     = status
                    };
                    models.Add(vm);
                }

                return(View(models));
            }
            catch (Exception ex)
            {
                TempData["Msg"] = ex.ToString();
                return(RedirectToAction("Logout", "Home"));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 顯示編輯教練的資料
        /// </summary>
        /// <param name="id">教練id</param>
        /// <returns></returns>
        public ActionResult TeacherEdit(string id)
        {
            try
            {
                //驗證授權:管理員
                var pass = roleAuth.AdminAuth();
                if (pass == true)
                {
                    ViewBag.UserName = roleAuth.UserName();
                    ViewBag.RoleName = "Admin";
                }
                else
                {
                    TempData["Msg"] = "無權限瀏覽該網頁,請登入會員瀏覽,謝謝!";
                    return(RedirectToAction("Login", "Home"));
                }

                TeacherOperation operation = new TeacherOperation();
                var teacher = operation.Get(id);

                var status = "";
                if (teacher.Status.Equals(true))
                {
                    status = "現役教練";
                }
                else
                {
                    status = "目前無教學服務";
                }

                TeacherViewModel vm = new TeacherViewModel()
                {
                    Name       = teacher.Name,
                    CreateTime = teacher.CreateTime.ToString("yyyy-MM-dd").Substring(0, 10),
                    EMail      = teacher.Email,
                    BirDate    = teacher.Birthday.ToString("yyyy-MM-dd").Substring(0, 10),
                    TeacherNo  = teacher.TeacherNo,
                    Status     = status
                };

                return(View(vm));
            }
            catch (Exception ex)
            {
                TempData["Msg"] = ex.ToString();
                return(RedirectToAction("Logout", "Home"));
            }
        }
Ejemplo n.º 5
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"));
            }
        }