public ActionResult Create(Music.Model.EF.Music music, int[] singers, int[] category, int[] album, HttpPostedFileBase img, HttpPostedFileBase mp3, HttpPostedFileBase mp4) { if (function.CookieID() == null) { return(Redirect("/User/Login")); } var user = function.CookieID(); music.music_img = imagesfunction.AddImages(img, "Music", Guid.NewGuid().ToString()); if (mp3 != null) { music.music_linkdow = imagesfunction.AddMuscis(mp3, "MP3", Guid.NewGuid().ToString()); } else if (mp4 != null) { music.music_video = imagesfunction.AddMuscis(mp4, "MP4", Guid.NewGuid().ToString()); } music.music_avgrate = 0; music.music_vote = 0; music.music_vip = true; music.user_id = user.user_id; musicsDAO.Add(music, category, singers, album); return(RedirectToAction("MyMusisc")); }
public ActionResult Create([Bind(Include = "music_id,music_name,music_img,music_lyric,music_time,music_view,music_dowload,user_id,music_linkdow,music_datecreate,music_dateedit,music_active,music_bin,music_option,nation_id,music_video,genres_id,author_id,album_id,nation_id")] Music.Model.EF.Music music, HttpPostedFileBase img, HttpPostedFileBase link_mp3, HttpPostedFileBase link_video, int[] category, int[] singers, int[] album) { music.music_bin = false; music.music_datecreate = DateTime.Now; if (ModelState.IsValid) { music.music_img = filesController.AddImages(img, "Music", Guid.NewGuid().ToString()); if (link_mp3 != null) { music.music_linkdow = filesController.AddMuscis(link_mp3, "MP3", Guid.NewGuid().ToString()); } else if (link_video != null) { music.music_video = filesController.AddMuscis(link_video, "MP4", Guid.NewGuid().ToString()); } musicsDAO.Add(music, category, singers, album); return(RedirectToAction("Index")); } ViewBag.album_id = new SelectList(db.Albums, "album_id", "album_name", music.album_id); ViewBag.author_id = new SelectList(db.Authors, "author_id", "author_name", music.author_id); ViewBag.genres_id = new SelectList(db.Genres, "genres_id", "genres_name", music.genres_id); ViewBag.nation_id = new SelectList(db.Nationals, "nation_id", "nation_name", music.nation_id); return(View(music)); }
public ActionResult DeleteConfirmed(int id) { Music.Model.EF.Music music = db.Musics.Find(id); db.Musics.Remove(music); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(Music.Model.EF.Music music, int[] singers, int[] category, HttpPostedFileBase img, HttpPostedFileBase mp3, HttpPostedFileBase mp4) { if (function.CookieID() == null) { return(Redirect("/User/Login")); } if (ModelState.IsValid) { var user = function.CookieID(); music.music_img = imagesfunction.AddImages(img, "Music", Guid.NewGuid().ToString()); if (mp3 != null) { music.music_linkdow = imagesfunction.AddMuscis(mp3, "MP3", Guid.NewGuid().ToString()); } else if (mp4 != null) { music.music_video = imagesfunction.AddMuscis(mp4, "MP4", Guid.NewGuid().ToString()); } music.user_id = user.user_id; musicsDAO.Edit(music, category, singers, null); return(RedirectToAction("MyMusisc")); } return(View(music)); }
//Hàm sửa public bool Edit(Music.Model.EF.Music musics, int[] category, int[] singer, int[] album) { try { db.Entry(musics).State = EntityState.Modified; db.SaveChanges(); //remove old category foreach (var item in db.Groups.Where(x => x.category_id != null && x.music_id == musics.music_id)) { db.Groups.Remove(item); } //remove old singer foreach (var item in db.Groups.Where(x => x.singer_id != null && x.music_id == musics.music_id)) { db.Groups.Remove(item); } // remove old album foreach (var item in db.PlayLists.Where(x => x.music_id == musics.music_id)) { db.PlayLists.Remove(item); } db.SaveChanges(); // add category foreach (var item in category) { groupDAO.Add(new Group() { category_id = item, music_id = musics.music_id }); } // add singer foreach (var item in singer) { groupDAO.Add(new Group() { singer_id = item, music_id = musics.music_id }); } // add singer foreach (var item in album) { playListDAO.Add(new PlayList() { albums_id = item, music_id = musics.music_id }); } return(true); } catch (Exception) { return(false); } }
public JsonResult Rate(int?rate, int?id) { Music.Model.EF.Music music = db.Musics.Find(id); double avg = music.music_avgrate == null ? 0 : (double)music.music_avgrate; int vote = music.music_vote == null ? 0 : (int)music.music_vote; music.music_avgrate = ((avg * vote) + rate) / (vote + 1); music.music_vote++; db.Entry(music).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(Json(music.music_avgrate.Value.ToString("0.0"), JsonRequestBehavior.AllowGet)); }
//Hàm thêm public bool Add(Music.Model.EF.Music musics, int[] category, int[] singer, int[] album) { try { musics.music_datecreate = DateTime.Now; musics.music_view = 1; musics.music_dowload = 0; musics.music_active = false; musics.music_option = true; musics.music_bin = false; db.Musics.Add(musics); db.SaveChanges(); // get music id var music_id = db.Musics.FirstOrDefault(t => t.music_name == musics.music_name && t.user_id == musics.user_id && t.music_bin == false && t.music_active == false).music_id; // add category foreach (var item in category) { groupDAO.Add(new Group() { category_id = item, music_id = music_id }); } // add singer foreach (var item in singer) { groupDAO.Add(new Group() { singer_id = item, music_id = music_id }); } // add music to album foreach (var item in album) { playListDAO.Add(new PlayList() { albums_id = item, music_id = music_id }); } return(true); } catch { return(false); } }
// GET: AdminMain/MusicsA/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Music.Model.EF.Music music = db.Musics.Find(id); if (music == null) { return(HttpNotFound()); } return(View(music)); }
//Option public bool Option(int?id) { try { Music.Model.EF.Music musics = db.Musics.Find(id); musics.music_option = !musics.music_option; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public ActionResult ChangeOption(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Music.Model.EF.Music music = db.Musics.Find(id); if (music == null) { return(HttpNotFound()); } db.Musics.Find(id).music_option = !db.Musics.Find(id).music_option; db.SaveChanges(); return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteVip(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Music.Model.EF.Music music = db.Musics.Find(id); if (music == null) { return(HttpNotFound()); } db.Musics.Find(id).music_bin = true; db.SaveChanges(); return(RedirectToAction("IndexVip")); }
//Hàm xoá public bool Delete(int?id) { try { Music.Model.EF.Music musics = db.Musics.Find(id); db.Musics.Remove(musics); db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
//Khôi Phục public bool Restore(int?id) { try { Music.Model.EF.Music musics = db.Musics.Find(id); musics.music_bin = false; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
// GET: AdminMain/MusicsA/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Music.Model.EF.Music music = db.Musics.Find(id); if (music == null) { return(HttpNotFound()); } ViewBag.album_id = new SelectList(db.Albums, "album_id", "album_name", music.album_id); ViewBag.author_id = new SelectList(db.Authors, "author_id", "author_name", music.author_id); ViewBag.genres_id = new SelectList(db.Genres, "genres_id", "genres_name", music.genres_id); ViewBag.nation_id = new SelectList(db.Nationals, "nation_id", "nation_name", music.nation_id); return(View(music)); }
public ActionResult Create(Music.Model.EF.Music music, int[] singers, int[] category, int[] album, int[] authour, HttpPostedFileBase IMG, HttpPostedFileBase MP3, HttpPostedFileBase MP4) { //if (function.CookieID() == null) //{ // return Redirect("/User/Login"); //} //var user = function.CookieID(); music.music_img = imagesfunction.AddImages(IMG, "Music", Guid.NewGuid().ToString()); if (MP3 != null) { music.music_linkdow = imagesfunction.AddMuscis(MP3, "MP3", Guid.NewGuid().ToString()); } else if (MP4 != null) { music.music_video = imagesfunction.AddMuscis(MP4, "MP4", Guid.NewGuid().ToString()); } //music.user_id = user.user_id; musicsDAO.Add(music, category, singers, album); return(RedirectToAction("Index")); }
public ActionResult RemoveToBin(int?id) { Music.Model.EF.Music music = db.Musics.Find(id); musicsDAO.Del(id); return(RedirectToAction("Index")); }
public ActionResult Restore(int?id) { Music.Model.EF.Music music = db.Musics.Find(id); musicsDAO.Restore(id); return(Redirect(Request.UrlReferrer.ToString())); }