Exemple #1
0
        public ActionResult Create(AdSlide adSlide)
        {
            if (ModelState.IsValid)
            {
                if (adSlide.ImageFile == null)
                {
                    ModelState.AddModelError("ImageFile", "image is requred");
                    return(View(adSlide));
                }
                else
                {
                    string imageName = DateTime.Now.ToString("ddMMyyyyHHmmssfff") + adSlide.ImageFile.FileName;
                    string imagePath = Path.Combine(Server.MapPath("~/Uploads/"), imageName);

                    adSlide.ImageFile.SaveAs(imagePath);
                    adSlide.Image = imageName;
                }

                adSlide.AddedDate = DateTime.Now;

                adSlide.EndDate = adSlide.EndDateForm;


                int hours = adSlide.EndTime.Hour;
                adSlide.EndDate = adSlide.EndDate.AddHours(hours);
                int minutes = adSlide.EndTime.Minute;
                adSlide.EndDate = adSlide.EndDate.AddMinutes(minutes);

                db.AdSlides.Add(adSlide);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(adSlide));
        }
Exemple #2
0
        // GET: Admin/AdSlider/Delete/5
        public ActionResult Delete(int id)
        {
            AdSlide adSlide = db.AdSlides.Find(id);

            db.AdSlides.Remove(adSlide);
            db.SaveChanges();


            return(RedirectToAction("Index"));
        }