Exemple #1
0
        public ActionResult OnCreate(BannerModels banner)
        {
            if (ModelState.IsValid)
            {
                banner.ImageUrl = banner.Image != null?
                                  banner.Image.Upload() :
                                      banner.ImageUrl;

                var newBanner = banner.CloneTo <Banner>(new[] {
                    nameof(banner.Image),
                    nameof(banner.StartDate),
                    nameof(banner.EndDate)
                });
                newBanner.StartDate = banner.StartDate;
                newBanner.EndDate   = banner.EndDate;
                var result = BannerService.Insert(newBanner);
                if (result == Result.Exists)
                {
                    ModelState.AddModelError("", $"Banner '{banner.Name}' đã tồn tại trên hệ thống.");
                    ViewBag.ListPosition = DataHelper.ListEnumType <PositionEnum>();
                    return(View("Create", banner));
                }
                SetFlashMessage($"Thêm banner '{banner.Name}' thành công.");
                if (banner.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ModelState.Clear();
                ViewBag.ListPosition = DataHelper.ListEnumType <PositionEnum>();
                return(View("Create", banner.ResetValue()));
            }
            ViewBag.ListPosition = DataHelper.ListEnumType <PositionEnum>();
            return(View("Create", banner));
        }
Exemple #2
0
        public ActionResult OnEdit(BannerModels banner)
        {
            if (ModelState.IsValid)
            {
                banner.ImageUrl = banner.Image != null?
                                  banner.Image.Upload() :
                                      banner.ImageUrl.ToImageOriginalPath();

                var bannerUpdate = banner.CloneTo <Banner>(new[] {
                    nameof(banner.Image),
                    nameof(banner.StartDate),
                    nameof(banner.EndDate)
                });
                bannerUpdate.StartDate = banner.StartDate;
                bannerUpdate.EndDate   = banner.EndDate;
                var result = BannerService.Update(bannerUpdate);
                if (result == Result.NotExists)
                {
                    ModelState.AddModelError("", "Banner không tồn tại trên hệ thống.");
                    ViewBag.ListPosition = DataHelper.ListEnumType <PositionEnum>();
                    return(View("Edit", banner));
                }
                SetFlashMessage($"Cập nhật Banner '{banner.Name}' thành công.");
                if (banner.SaveList)
                {
                    return(RedirectToAction("Index"));
                }
                ViewBag.ListPosition = DataHelper.ListEnumType <PositionEnum>();
                return(View("Edit", banner));
            }
            ViewBag.ListPosition = DataHelper.ListEnumType <PositionEnum>();
            return(View("Edit", banner));
        }
Exemple #3
0
        public ActionResult Index(int?page, BannerType type = BannerType.Top)
        {
            BannerModels    model            = new BannerModels();
            int             total            = 0;
            int             PageSize         = 10;
            int             CurrentPageIndex = page.HasValue ? page.Value - 1 : 0;
            IList <Banners> lst = bannerSrv.GetbyList(type, CurrentPageIndex, PageSize, out total);

            model.PageListBanners = new PagedList <Banners>(lst, CurrentPageIndex, PageSize, total);
            model.Type            = type;
            return(View(model));
        }