Ejemplo n.º 1
0
        public ActionResult AddBanner(FormCollection fdata)
        {
            MainBanner b = new MainBanner();

            try
            {
                long numb  = DateTime.Now.Ticks;
                int  count = 0;
                foreach (string fname in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fname];
                    if (!string.IsNullOrEmpty(file.FileName))
                    {
                        b.Caption    = Convert.ToString(fdata["caption"]);
                        b.Banner_Url = "/ImagesData/MainPageBanners/" + file.FileName + numb + "_" + ++count + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                        string path = Request.MapPath(b.Banner_Url);
                        if (file != null)
                        {
                            file.SaveAs(path);
                        }
                        new BannersHandler().AddBanner(b);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToAction("BannerManagment"));
        }
Ejemplo n.º 2
0
        public ActionResult BannerEdit(MainBanner Banner)
        {
            User u = (User)Session[WebUtil.CURRENT_USER];

            if (!(u != null && u.IsInRole(WebUtil.ADMIN_ROLE)))
            {
                return(RedirectToAction("Login", "User"));
            }

            if (ModelState.IsValid)
            {
                //long numb = DateTime.Now.Ticks;
                //int count = 0;
                //foreach (string fname in Request.Files)
                //{
                //    HttpPostedFileBase file = Request.Files[fname];
                //    if (!string.IsNullOrEmpty(file.FileName))
                //    {
                //        Banner.Banner_Url = "/ImagesData/MainPageBanners/" + file.FileName + numb + "_" + ++count + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                //        string path = Request.MapPath(Banner.Banner_Url);
                //        file.SaveAs(path);
                //    }

                //}
                new BannersHandler().UpdateBanner(Banner);
                return(RedirectToAction("BannerManagment"));
            }
            ViewBag.bannercount = new BannersHandler().GetBannerCount();
            return(View());
        }
 public void UpdateBanner(MainBanner banner)
 {
     using (_db)
     {
         _db.Entry(banner).State = EntityState.Modified;
         _db.SaveChanges();
     }
 }
 public void AddBanner(MainBanner banner)
 {
     using (_db)
     {
         _db.MainBanners.Add(banner);
         _db.SaveChanges();
     }
 }
        public ActionResult AddBanner(FormCollection fdata)
        {
            User u = (User)Session[WebUtil.CURRENT_USER];

            if (!(u != null && u.IsInRole(WebUtil.ADMIN_ROLE)))
            {
                return(RedirectToAction("Login", "User", new { ctl = "Admin", act = "AdminPanel" }));
            }
            MainBanner b = new MainBanner();

            try
            {
                long numb  = DateTime.Now.Ticks;
                int  count = 0;
                foreach (string fname in Request.Files)
                {
                    HttpPostedFileBase file = Request.Files[fname];
                    if (!string.IsNullOrEmpty(file.FileName))
                    {
                        b.Caption   = Convert.ToString(fdata["Caption"]);
                        b.BannerUrl = "/ImagesData/SliderImages/" + file.FileName + numb + "_" + ++count + file.FileName.Substring(file.FileName.LastIndexOf('.'));
                        string path = Request.MapPath(b.BannerUrl);
                        if (file != null)
                        {
                            file.SaveAs(path);
                        }
                        new BannerHandler().AddBanner(b);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToAction("BannerManagment"));
        }