public ActionResult CreateOrUpdate(SlideModel model, HttpPostedFileBase file)
 {
     var entity = model.Id > 0 ? _slideService.GetById(model.Id) : new Slide();
     Mapper.CreateMap<SlideModel, Slide>();
     Mapper.Map(model, entity);
     entity.LastUpdated = DateTime.Now;
     if (file != null && file.ContentLength > 0)
     {
         FileHelper _fileHelper = new FileHelper(DIR_NAME, entity.Id > 0 ? entity.CreatedDate : DateTime.Now);
         entity.ImageUrl = _fileHelper.SaveFile(file);
     }
     string msg = string.Empty;
     if (entity.Id == 0)
     {
         _slideService.Insert(entity);
         msg = "Thêm slide thành công !";
     }
     else
     {
         _slideService.Update(entity);
         msg = "Cập nhật slide thành công !";
     }
     TempData["Message"] = null;
     if (!String.IsNullOrEmpty(msg))
         TempData["Message"] = msg;
     return RedirectToAction("Edit", new { Id = entity.Id });
 }
 public ActionResult Create()
 {
     var model = new SlideModel();
     model.CreatedDate = DateTime.Now;
     model.Published = true;
     return View(model);
 }
 public ActionResult Edit(int Id)
 {
     var entity = _slideService.GetById(Id);
     var model = new SlideModel();
     if (entity != null)
     {
         Mapper.CreateMap<Slide, SlideModel>();
         Mapper.Map(entity, model);
     }
     if (!String.IsNullOrEmpty(model.ImageUrl))
     {
         model.FullPathImageUrl = FileHelper.GetImageUrlBackEnd(DIR_NAME, model.ImageUrl, model.CreatedDate);
     }
     return View(model);
 }
  public ActionResult List()
  {
      var entities = _slideService.Table.Where(x => !x.Deleted).OrderByDescending(x => x.CreatedDate).ToList();
      IList<SlideModel> models = new List<SlideModel>();
      Mapper.CreateMap<Slide, SlideModel>();
      foreach (var item in entities)
      {
          SlideModel sm = new SlideModel();
          Mapper.Map(item, sm);
          sm.FullPathImageUrl = FileHelper.GetImageUrlBackEnd(DIR_NAME, sm.ImageUrl, sm.CreatedDate);
          models.Add(sm);
      }
 
      return View(models);
  }