Exemplo n.º 1
0
        public ActionResult AddNewMovie()
        {
            if (Session["UserId"] == null)
            {
                RedirectToAction("Login", new { Controller = "Home" });
            }
            // get types from database and add to X.types

            MovieTypesViewModel x  = new MovieTypesViewModel();
            var           Actors   = db.Actors.ToList();
            List <string> actnames = new List <string>();
            string        lowername;

            foreach (Actor actor in Actors)
            {
                lowername = actor.full_name.ToLower();
                actnames.Add(lowername);
            }
            x.ActorsNames = actnames;

            x.TypesList = db.TYPESS.ToList();
            return(View(x));
        }
Exemplo n.º 2
0
        public ActionResult AddNewMovie(MovieTypesViewModel s, HttpPostedFileBase file, HttpPostedFileBase file2, HttpPostedFileBase file3, HttpPostedFileBase file4)

        {
            if (file != null && file2 != null && file3 != null /*&&file4 != null*/)
            {
                string extension  = Path.GetExtension(file.FileName).ToLower();
                string extension2 = Path.GetExtension(file2.FileName).ToLower();
                if (extension != ".png" && extension != ".jpg")
                {
                    return(Content("please upload jpg or png..."));
                }
                if (extension2 != ".mp4" && extension2 != ".flv" && extension2 != ".mkv" && extension2 != ".wmv")
                {
                    return(Content("please upload Mp4 or FLV..."));
                }

                //image upload

                ////
                string path     = Server.MapPath("~/Images/");
                string fileName = Path.GetFileName(file.FileName);
                string fullpath = Path.Combine(path, fileName);
                file.SaveAs(fullpath);
                s.ImagePath = fileName;


                ///
                ///video upload
                string path2     = Server.MapPath("~/Videos/");
                string fileName2 = Path.GetFileName(file2.FileName);
                string fullpath2 = Path.Combine(path2, fileName2);
                file2.SaveAs(fullpath2);
                s.MovieDirectroy = fileName2;
                /// // / ////////////////////////////////////////////////////
                /// /// ///////////



                if (file4 != null)
                {
                    string path4     = Server.MapPath("~/Trailers/");
                    string fileName4 = Path.GetFileName(file4.FileName);
                    string fullpath4 = Path.Combine(path4, fileName4);
                    file4.SaveAs(fullpath4);
                    s.Trailer = fileName4;
                }



                ///
                ///
                ///


                string path3     = Server.MapPath("~/Images/Covers/");
                string fileName3 = Path.GetFileName(file3.FileName);
                string fullpath3 = Path.Combine(path3, fileName3);

                file3.SaveAs(fullpath3);


                s.CoverPath = fileName3;



                /// /////////////////////////////////////
                s.Upload_Date = DateTime.Now.Date;
                int x = (int)Session["UserId"];
                s.pulisher_id = x;
            }



            s.TypesList = db.TYPESS.ToList();
            var viewmodel = s;

            foreach (var type in db.TYPESS.ToList())
            {
                if (s.type_id == type.Id)
                {
                    s.Type_Name = type.type_name;
                }
            }

            foreach (var admin in db.ADMINSS.ToList())
            {
                if (s.pulisher_id == admin.Id)
                {
                    s.publisher_Name = admin.Name;
                }
            }



            Movie movie = new Movie();

            movie.Name            = s.Name;
            movie.Country         = s.Country;
            movie.description     = s.description;
            movie.Duration        = s.Duration;
            movie.Id              = s.Id;
            movie.ImagePath       = s.ImagePath;
            movie.Language        = s.Language;
            movie.MovieDirectroy  = s.MovieDirectroy;
            movie.publisher_Name  = s.publisher_Name;
            movie.pulisher_id     = s.pulisher_id;
            movie.type_id         = s.type_id;
            movie.Type_Name       = s.Type_Name;
            movie.Upload_Date     = s.Upload_Date;
            movie.year_production = s.year_production;
            movie.CoverPath       = s.CoverPath;
            movie.Trailer         = s.Trailer;
            movie.Cast            = s.Cast;


            //var listofActor = s.Cast.Split(',');

            // foreach(String actr in listofActor) {

            //   var actorDB = db.Actors.Where(r => r.full_name == actr).FirstOrDefault();

            // }


            /// //// /////////////////////////////////////////

            // //// //////////////////////////////////////////////////////////


            if (ModelState.IsValid)
            {
                db.MOVIESS.Add(movie);
                db.SaveChanges();
                Session["MovieId"] = s.Id;
                //var   listofFollowers =    db.Follow.Where(y => y.PublisherId == s.pulisher_id).ToList();
                // foreach (var follower in listofFollowers )
                //           {
                //               var userEmail = db.USERSS.Find(follower.UserId);
                //               EmailManager.SendEmail("<b>Movies land</b>A New Movie has been uploaded ",s.Name+s.year_production.Year+" Was uploaded recently By: "+s.publisher_Name,userEmail.Email,s.ImagePath);

                //           }



                return(RedirectToAction("AddNewMovie", "Admin"));
            }
            else
            {
                //List<ModelError> c = new List<ModelError>();
                s.TypesList = db.TYPESS.ToList();
                return(View(s));
                //foreach (ModelState modelState in ModelState.Values)
                //{
                //    foreach (ModelError error in modelState.Errors)
                //    {
                //        c.Add(error);
                //    }
                //}
                //return Content(c.ToString());
            }
        }