Esempio n. 1
0
        public ActionResult Create([Bind(Include = "Tag,Photo")] Gallery gallery)
        {
            if (!ModelState.IsValid)
            {
                return(View(gallery));
            }

            if (gallery.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo can not empty...");
                return(View(gallery));
            }

            if (!gallery.Photo.isImage())
            {
                ModelState.AddModelError("Photo", "Photo type is not valid...");
                return(View(gallery));
            }

            gallery.Image = gallery.Photo.Save("gallery");

            _db.Galleries.Add(gallery);
            _db.SaveChanges();

            return(RedirectToAction("Index", "Gallery"));
        }
        public ActionResult Create([Bind(Include = "Title, Content,Photo")]  About about)
        {
            if (!ModelState.IsValid)
            {
                return(View(about));
            }

            if (about.Photo == null)
            {
                ModelState.AddModelError("Photo", "Photo can not be null");
                return(View(about));
            }

            if (!about.Photo.isImage())
            {
                ModelState.AddModelError("Photo", "Photo type is not valid");
                return(View(about));
            }

            about.Image = about.Photo.Save("about");

            _db.Abouts.Add(about);
            _db.SaveChanges();

            return(RedirectToAction(nameof(Index), "About"));
        }
        public ActionResult Edit([Bind(Include = "Id,Title,Price,SubTitle,Hours,HowManyPhoto,Content")] Event events)
        {
            if (!ModelState.IsValid)
            {
                return(View(events));
            }

            Event eventBefore = _db.Events.Find(events.Id);

            eventBefore.Title        = events.Title;
            eventBefore.Price        = events.Price;
            eventBefore.SubTitle     = events.SubTitle;
            eventBefore.Hours        = events.Hours;
            eventBefore.HowManyPhoto = events.HowManyPhoto;
            eventBefore.Content      = events.Content;
            _db.SaveChanges();

            return(RedirectToAction("Index", "Event"));
        }