public ActionResult CreateOrUpdate(BannerModel model, HttpPostedFileBase file)
 {
     var entity = model.Id > 0 ? _bannerService.GetById(model.Id) : new Banner();
     Mapper.CreateMap<BannerModel, Banner>();
     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)
     {
         _bannerService.Insert(entity);
         msg = "Thêm danh mục thành công !";
     }
     else
     {
         _bannerService.Update(entity);
         msg = "Cập nhật danh mục 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 BannerModel();
     model.CreatedDate = DateTime.Now;
     model.Published = true;
     return View(model);
 }
 public ActionResult Edit(int Id)
 {
     var entity = _bannerService.GetById(Id);
     var model = new BannerModel();
     if (entity != null)
     {
         Mapper.CreateMap<Banner, BannerModel>();
         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 = _bannerService.Table.Where( x => x.Published && !x.Deleted).OrderByDescending(x => x.CreatedDate).ToList();
      IList<BannerModel> models = new List<BannerModel>();
      Mapper.CreateMap<Banner, BannerModel>();
      foreach (var item in entities)
      {
          BannerModel sm = new BannerModel();
          Mapper.Map(item, sm);
          sm.FullPathImageUrl = FileHelper.GetImageUrlBackEnd(DIR_NAME, sm.ImageUrl, sm.CreatedDate);
          models.Add(sm);
      }
 
      return View(models);
  }