// 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")); }
// 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)); }
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)); }
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)); }
public ActionResult NotEnoughMoney(int id) { MusicsResponseVM vm = new MusicsResponseVM() { Music1 = db.Musics.Find(id) }; return(View(vm)); }
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)); }
// 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")); }
// 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")); }
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)); }
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)); }
// 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")); }
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")); }
[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")); }