Esempio n. 1
0
        public ActionResult CreatePodcast([Bind(Include = "Title,Description,EpisodeNumber,SeasonNumber,AudioPath")] Podcast podcast)
        {
            if (ModelState.IsValid)
            {
                podcast.Date      = DateTime.Now;
                podcast.ImagePath = @"/Content/Images/podcast_cat.jpg";
                db.Podcasts.Add(podcast);
                db.SaveChanges();

                if (!String.IsNullOrEmpty(podcast.AudioPath))
                {
                    HttpPostedFileBase AudioPath = Request.Files["AudioPath"];

                    if (AudioPath != null && AudioPath.ContentLength > 0)
                    {
                        try
                        {
                            string extension = System.IO.Path.GetExtension(AudioPath.FileName);
                            string fileName  = podcast.AudioPathBuilder() + extension;
                            string path      = Path.Combine(Server.MapPath(@"/Content/Podcasts/"), fileName);

                            if (System.IO.File.Exists(path))
                            {
                                System.IO.File.Delete(path);
                            }

                            AudioPath.SaveAs(path);
                            podcast.AudioPath = @"/Content/Podcasts/" + fileName;
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            string ex = e.Message;
                        }
                    }
                }
                return(RedirectToAction("AllPodcasts"));
            }
            return(View(podcast));
        }
Esempio n. 2
0
        public ActionResult EditPodcast([Bind(Include = "PodcastId,Date,ImagePath,Title,EpisodeNumber,SeasonNumber,Description,AudioPath")] Podcast pod, string NewAudioPath)
        {
            if (ModelState.IsValid)
            {
                if (!String.IsNullOrEmpty(NewAudioPath))
                {
                    HttpPostedFileBase AudioPath = Request.Files["NewAudioPath"];

                    if (AudioPath != null && AudioPath.ContentLength > 0)
                    {
                        try
                        {
                            string extension = System.IO.Path.GetExtension(AudioPath.FileName);
                            string fileName  = pod.AudioPathBuilder() + extension;
                            string path      = Path.Combine(Server.MapPath(@"/Content/Podcasts/"), fileName);

                            if (System.IO.File.Exists(path))
                            {
                                System.IO.File.Delete(path);
                            }

                            AudioPath.SaveAs(path);
                            pod.AudioPath = @"/Content/Podcasts/" + fileName;
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            string ex = e.Message;
                        }
                    }
                }
                db.Entry(pod).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("AllPodcasts"));
            }
            return(View(pod));
        }