Example #1
0
        public ActionResult Create(CreateSlideFormModel model)
        {
            if (ModelState.IsValid)
            {
                var slide = new SLIDE();
                slide.IDSlide = model.IDSlide;
                slide.Sapxep  = model.Sapxep;
                slide.Link    = model.Link;
                slide.NgayTao = DateTime.Now;

                if (model.SlideImage != null)
                {
                    var fileName = model.SlideImage.FileName;
                    var link     = "/uploads/" + fileName;
                    var real     = Server.MapPath("~" + link);
                    model.SlideImage.SaveAs(real);
                    slide.Anh = link;
                }
                try
                {
                    db.SLIDEs.Add(slide);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("save_error", "Lỗi khi lưu" + ex.Message);
                    return(View(model));
                }
                return(RedirectToAction("Index", "Slide"));
            }
            return(View(model));
        }
Example #2
0
 public ActionResult Create(SLIDE model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var dao = new SlidesDao();
             int id  = dao.Insert(model);
             if (id > 0)
             {
                 SetAlert("Thêm thành công", "success");
                 return(RedirectToAction("Index", "Slide"));
             }
             else
             {
                 ModelState.AddModelError("", "Thêm thất bại");
             }
         }
         SetViewBag(model.ID);
         return(View(model));
     }
     catch
     {
         return(View());
     }
 }
Example #3
0
 public int Insert(SLIDE entity)
 {
     try
     {
         db.SLIDE.Add(entity);
         db.SaveChanges();
         return(entity.ID);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Example #4
0
        public ActionResult ThemSlide(SLIDE cs)
        {
            SLIDE ds = new SLIDE();

            ds.TenSlide  = cs.TenSlide;
            ds.Metatitle = RewriteURL.RewriteUrl(cs.TenSlide);
            ds.NgayTao   = DateTime.Now;
            ds.Anh       = cs.Anh;
            ds.Link      = cs.Link;
            ds.TrangThai = 1;
            ds.NgayTao   = DateTime.Now;
            dao.AddSlide(ds);
            return(RedirectToAction("SlideChoDuyet"));
        }
Example #5
0
 public bool Update(SLIDE entity)
 {
     try
     {
         var Slide = db.SLIDE.Find(entity.ID);
         Slide.Image        = entity.Image;
         Slide.DisplayOrder = entity.DisplayOrder;
         Slide.Link         = entity.Link;
         Slide.Created_Date = DateTime.Now;
         Slide.Status       = entity.Status;
         Slide.TypeID       = entity.TypeID;
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #6
0
 public ActionResult Edit(SLIDE model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var result = new SlidesDao().Update(model);
             if (result)
             {
                 SetAlert("Cập nhật thành công", "success");
                 return(RedirectToAction("Index", "Slide"));
             }
             else
             {
                 ModelState.AddModelError("", "Cập nhật thất bại");
             }
         }
         SetViewBag(model.ID);
         return(View(model));
     }
     catch
     { return(View()); }
 }
Example #7
0
 public long AddSlide(SLIDE sl)
 {
     db.SLIDEs.Add(sl);
     db.SaveChanges();
     return(sl.ID);
 }