public ActionResult AddSingerToMusic(SingerMusicDTO singerMusic) { ApiService.AddSingerToMusic(singerMusic); return(RedirectToAction("SingerOfMusic", "Music", new { id = singerMusic.MusicID })); }
public ActionResult CreateMusicUser(MusicDTO m, HttpPostedFileBase fileMusic, HttpPostedFileBase imgMusic) { //Session["singer"] = ApiService.GetAllSinger(); var user = (UserDTO)Session[CommonConstants.USER_SESSION]; if (Session["singer"] != null) { List <int> arrSinger = new List <int>(); var list = Session["singer"] as List <int>; arrSinger = list; m.MusicNameUnsigned = RemoveUnicode.RemoveSign4VietnameseString(m.MusicName); m.MusicDownloadAllowed = true; m.MusicView = 0; m.UserID = user.ID; //img music if (imgMusic == null) { m.MusicImage = "default.png"; } else { try { string FileNameMusic = DateTime.Now.Ticks + ".png"; imgMusic.SaveAs(Server.MapPath("~/File/ImageMusic/" + FileNameMusic)); m.MusicImage = FileNameMusic; } catch (Exception e) { Console.WriteLine(e); throw; } } //quality music QualityMusicDTO quality = new QualityMusicDTO() { NewFile = true, QMusicApproved = false }; string FileName = DateTime.Now.Ticks + Path.GetFileName(fileMusic.FileName); string path; if (FileName.EndsWith("mp3")) { quality.QualityID = 1; //file normal of song m.SongOrMV = true; path = Path.Combine(Server.MapPath("~/File/mp3-mp4/"), FileName); } else { quality.QualityID = 3; //file mormal of mv m.SongOrMV = false; path = Path.Combine(Server.MapPath("~/File/mp3-mp4/"), FileName); } fileMusic.SaveAs(path); quality.MusicFile = FileName; // music int idMusic = ApiService.CreateMusicUpload(m); if (idMusic > 0) { quality.MusicID = idMusic; var dataQM = ApiService.CreateQualityMusic(quality); if (dataQM != null) { //singer foreach (var number in arrSinger) { ApiService.AddSingerToMusic(new SingerMusicDTO() { MusicID = idMusic, SingerID = number }); } SetAlert("Update success!", "success"); TempData["success"] = "Upload file thành công"; } } } else { SetAlert("Update fail!", "warning"); TempData["error"] = "Upload file xảy ra lỗi"; } Session.Remove("singer"); return(RedirectToAction("UploadFile")); }