Пример #1
0
        // GET: AdminMusic/Edit/id
        public ActionResult Edit(int?id)
        {
            if ((Request.Cookies["userId"]["roleId"]) == "1")
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                Music music = db.Musics.Find(id);
                if (music == null)
                {
                    return(HttpNotFound());
                }

                MusicsResponseVM musicsResponseVM = new MusicsResponseVM()
                {
                    Albums          = db.Albums.ToList(),
                    AlbumTemplate   = new SelectList(db.Albums, "ID", "Name", 1),
                    Music1          = music,
                    selectedAlbumID = music.Album.ID
                };

                return(View(musicsResponseVM));
            }

            return(RedirectToAction("Index", "Home"));
        }
Пример #2
0
        // GET: Order
        public ActionResult Index()
        {
            if (Request.Cookies["userId"] == null)
            {
                return(RedirectToAction("Login", "User"));
            }

            int  userId = int.Parse(Request.Cookies["userId"]["id"]);
            User user   = db.Users.Find(userId);

            List <Order> orders = db.Orders.Where(i => i.UserID == userId).ToList();
            List <Music> musics = new List <Music>();
            Music        music;

            for (int i = 0; i < orders.Count; i++)
            {
                music = db.Musics.Find(orders[i].MusicID);
                if (music != null)
                {
                    musics.Add(music);
                }
            }
            MusicsResponseVM musicsResponseVM = new MusicsResponseVM
            {
                Musics = musics
            };

            return(View(musicsResponseVM));
        }
Пример #3
0
        public ActionResult Search(MusicsResponseVM musicResponseVM)
        {
            Music        m  = musicResponseVM.Music1;
            List <Music> lm = db.Musics.ToList();

            if (m.Name != null)
            {
                lm = lm.Where(c => c.Name.Equals(m.Name)).ToList();
            }
            if (m.Artist != null)
            {
                lm = lm.Where(c => c.Artist.Equals(m.Artist)).ToList();
            }
            if (m.ReleaseDate != new DateTime(01, 01, 0001))
            {
                lm = lm.Where(c => c.ReleaseDate.Equals(m.ReleaseDate)).ToList();
            }
            if (m.Genre != null)
            {
                lm = lm.Where(c => c.Genre.Equals(m.Genre)).ToList();
            }

            int userid = Int32.Parse(Request.Cookies["UserId"]["id"]);
            var orders = db.Orders.Where(u => u.UserID == userid).Select(u => u.MusicID).ToList();

            MusicsResponseVM vm = new MusicsResponseVM();

            vm.Musics          = lm;
            vm.MusicOrderedIds = orders;

            return(PartialView("_Musics", vm));
        }
Пример #4
0
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";
            List <Music> musics = db.Musics.OrderByDescending(a => a.Mark).ToList();

            MusicsResponseVM musicsResponseVM = new MusicsResponseVM()
            {
                Musics = musics
            };

            if (musics.Count == 1)
            {
                musicsResponseVM.Music1 = musics[0];
            }
            else if (musics.Count == 2)
            {
                musicsResponseVM.Music2 = musics[1];
                musicsResponseVM.Music1 = musics[0];
            }
            else if (musics.Count >= 3)
            {
                musicsResponseVM.Music3 = musics[2];
                musicsResponseVM.Music2 = musics[1];
                musicsResponseVM.Music1 = musics[0];
            }
            return(View(musicsResponseVM));
        }
Пример #5
0
        public ActionResult NotEnoughMoney(int id)
        {
            MusicsResponseVM vm = new MusicsResponseVM()
            {
                Music1 = db.Musics.Find(id)
            };

            return(View(vm));
        }
Пример #6
0
        public ActionResult AlreadyBought(int id)
        {
            Music music = db.Musics.Find(id);

            if (music == null)
            {
                return(HttpNotFound());
            }
            MusicsResponseVM musicsResponseVM = new MusicsResponseVM()
            {
                Music1 = music
            };

            return(View(musicsResponseVM));
        }
Пример #7
0
        // Get: AdminMusic/Create
        public ActionResult Create()
        {
            //int id2 = int.Parse(Response.Cookies["userId"]["id"]);
            //int id = int.Parse(Response.Cookies["userId"]["roleId"]);
            if (int.Parse(Request.Cookies["userId"]["roleId"]) == 1)
            {
                MusicsResponseVM musicsResponseVM = new MusicsResponseVM()
                {
                    Albums        = db.Albums.ToList(),
                    AlbumTemplate = new SelectList(db.Albums, "ID", "Name", 1)
                };
                return(View(musicsResponseVM));
            }

            return(RedirectToAction("Index", "Home"));
        }
Пример #8
0
        // GET: AdminMusic
        public ActionResult Index()
        {
            if ((Request.Cookies["userId"]["roleId"]) == "1")
            {
                var musics = db.Musics.Include(m => m.Album).ToList();

                MusicsResponseVM musicsResponseVM = new MusicsResponseVM()
                {
                    Musics = musics
                };

                return(View(musicsResponseVM));
            }

            return(RedirectToAction("Index", "Home"));
        }
Пример #9
0
        public ActionResult BuyConfirmation(int id)
        {
            Music music = db.Musics.Find(id);

            if (music == null)
            {
                return(HttpNotFound());
            }
            MusicsResponseVM musicsResponseVM = new MusicsResponseVM()
            {
                Music1 = music
            };

            //db.Users.Remove(user);
            //db.SaveChanges();
            return(View(musicsResponseVM));
        }
Пример #10
0
        public ActionResult Index(string name)
        {
            Music music = db.Musics.Find(1);

            if (music == null)
            {
                return(HttpNotFound());
            }
            MusicsResponseVM musicsResponseVM = new MusicsResponseVM()
            {
                Music1 = music
            };

            //db.Users.Remove(user);
            //db.SaveChanges();
            return(View(musicsResponseVM));
        }
Пример #11
0
        // GET: Music
        public ActionResult Index()
        {
            if (Request.Cookies["UserId"] != null)
            {
                var musics = db.Musics.Include(m => m.Album).ToList();
                int userid = Int32.Parse(Request.Cookies["UserId"]["id"]);
                var orders = db.Orders.Where(u => u.UserID == userid).Select(u => u.MusicID).ToList();

                MusicsResponseVM musicsResponseVM = new MusicsResponseVM()
                {
                    Musics          = musics,
                    MusicOrderedIds = orders
                };

                return(View(musicsResponseVM));
            }

            return(RedirectToAction("Login", "User"));
        }
Пример #12
0
        public ActionResult Edit(MusicsResponseVM MusicVM)
        {
            if ((Request.Cookies["userId"]["roleId"]) == "1")
            {
                if (ModelState.IsValid)
                {
                    Music Music = MusicVM.Music1;
                    Music.Album     = db.Albums.Find(MusicVM.selectedAlbumID);
                    Music.Thumbnail = Music.Album.Thumbnail;

                    db.Entry(Music).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }

                return(View(MusicVM));
            }

            return(RedirectToAction("Index", "Home"));
        }
Пример #13
0
        [ValidateAntiForgeryToken] //Eviter l'injection de script par onglet
        public ActionResult Create(MusicsResponseVM MusicVM, HttpPostedFileBase MusicFile)
        {
            if ((Request.Cookies["userId"]["roleId"]) == "1")
            {
                if (ModelState.IsValid && MusicFile != null)
                {
                    Music Music = MusicVM.Music1;

                    var path       = Server.MapPath("~/Content/Ressources/Musics/");
                    var path2      = Server.MapPath("~/Content/Ressources/CutMusics/");
                    int fileNumber = Directory.GetFiles(path).Length + 1;

                    Music.Album            = db.Albums.Find(MusicVM.selectedAlbumID);
                    Music.Thumbnail        = Music.Album.Thumbnail;
                    Music.Number           = fileNumber;
                    Music.Mark             = 0;
                    Music.NumberOfComments = 0;

                    db.Musics.Add(Music);
                    db.SaveChanges();

                    string filename = Path.GetFileName(fileNumber.ToString() + ".mp3");
                    MusicFile.SaveAs(Path.Combine(path, filename));

                    string ffPath        = Server.MapPath("~/Content/Ressources/ffmpeg-20170411-f1d80bc-win64-static/bin/ffmpeg.exe");
                    string processString = "-t 20 -i " + Path.Combine(path, filename) + " " + Path.Combine(path2, filename);

                    System.Diagnostics.Process p = new System.Diagnostics.Process();
                    p.StartInfo = new System.Diagnostics.ProcessStartInfo(ffPath, processString);
                    p.Start();
                    p.WaitForExit();

                    return(RedirectToAction("Index"));
                }

                return(View(MusicVM));
            }

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