Ejemplo n.º 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));
            }
        }
Ejemplo n.º 2
0
 public ActionResult UpdateCourses(COURSE course, HttpPostedFileBase postedFile)
 {
     if (ModelState.IsValid)
     {
         if (SaveImage(postedFile))
         {
             if (postedFile != null)
             {
                 course.Images = "images/" + postedFile.FileName;
             }
             var cou    = new CourseDao();
             var result = cou.Update(course);
             if (result)
             {
                 return(Content("Update Success"));
             }
             else
             {
                 return(Content("Update course unsuccessful"));
             }
         }
         else
         {
             return(Content("Update course unsuccessful"));
         }
     }
     return(Content("Update course unsuccessful"));
 }
        public Course SaveCourse()
        {
            if (_adding)
            {
                CourseDao.Add(Course);
            }
            else
            {
                CourseDao.Update(Course);
            }

            return(Course);
        }