示例#1
0
        public ActionResult Edit(course cou, HttpPostedFileBase photo)
        {
            TeacherDao teDao  = new TeacherDao();
            CourseDao  couDao = new CourseDao();

            if (ModelState.IsValid)
            {
                try
                {
                    if (photo != null && photo.ContentLength > 0)
                    {
                        course exists_cou = couDao.GetById(cou.co_id);
                        string image      = String.Concat(cou.co_name, photo.FileName);
                        if (!image.Equals(exists_cou.co_image))
                        {
                            var image_old = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/course/"),
                                                         System.IO.Path.GetFileName(exists_cou.co_image));
                            if (System.IO.File.Exists(image_old))
                            {
                                System.IO.File.Delete(image_old);
                            }
                            var image_new = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/course/"),
                                                         System.IO.Path.GetFileName(image));


                            photo.SaveAs(image_new);
                        }
                        cou.co_image      = image;
                        cou.co_updated_at = DateTime.Now;
                        couDao.Update(cou);
                    }
                    else
                    {
                        course exists_cou = couDao.GetById(cou.co_id);
                        cou.co_image = exists_cou.co_image;
                        couDao.Update(cou);
                    }
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(View("Error"));
                }
            }
            else
            {
                ViewBag.lst_te = teDao.GetAll();
                var        teacher = teDao.GetAll();
                SelectList list_te = new SelectList(teacher, "te_id", "te_name");
                ViewBag.list_te = list_te;
                return(View(cou));
            }
        }
        public void OnGet(string courseId)
        {
            var id        = int.Parse(courseId);
            var courseDao = new CourseDao();

            Course = courseDao.GetById(id);
            var commentDao = new CommentDao();

            Comments = commentDao.GetByCourseId(id);
            var usersId = HttpContext.Session.GetInt32("users_id");

            if (usersId == null && HttpContext.Request.Cookies.ContainsKey("users_id"))
            {
                usersId = int.Parse(HttpContext.Request.Cookies["users_id"]);
                var usersName = HttpContext.Request.Cookies["users_name"];
                HttpContext.Session.SetInt32("users_id", (int)usersId);
                HttpContext.Session.SetString("users_name", usersName);
            }
            UserIsAuthorized = usersId != null;
            if (UserIsAuthorized)
            {
                var usersCourses = new UsersDao().GetCourses((int)usersId);
                UserHasThisCourse = usersCourses.Select(c => c.Id).Contains(id);
            }
        }
示例#3
0
        public JsonResult ExsitsCourseName(string cou_Coursename, int?cou_id)
        {
            CourseDao     dao     = new CourseDao();
            List <course> lts_cou = dao.GetAll();

            if (cou_id != null)
            {
                lts_cou.Remove(dao.GetById(cou_id)); //////////////??????????????????????
            }
            return(Json(!lts_cou.Any(x => x.co_name.Trim().ToLower() == cou_Coursename.Trim().ToLower()), JsonRequestBehavior.AllowGet));
        }
示例#4
0
        public ActionResult Delete(int id)
        {
            CourseDao dao        = new CourseDao();
            course    exists_cou = dao.GetById(id);

            var image_old = Path.Combine(Server.MapPath("~/Areas/Admins/Content/Photo/course/"),
                                         System.IO.Path.GetFileName(exists_cou.co_image));

            if (System.IO.File.Exists(image_old))
            {
                System.IO.File.Delete(image_old);
            }
            dao.Delete(id);
            return(RedirectToAction("Index"));
        }
示例#5
0
        public ActionResult Edit(int?id)
        {
            CourseDao couDao = new CourseDao();

            if (id == null)
            {
                return(View("Error"));
            }
            course course = couDao.GetById(id);

            if (course == null)
            {
                return(HttpNotFound());
            }
            TeacherDao teDao   = new TeacherDao();
            var        teacher = teDao.GetAll();
            SelectList list_te = new SelectList(teacher, "te_id", "te_name");

            ViewBag.list_te = list_te;
            return(View(course));
        }