public ActionResult Upload(HttpPostedFileBase anh, HttpPostedFileBase nhac, FormCollection f) { NhacCaNhan nc = new NhacCaNhan(); nc.IdNguoiDung = (Session["taikhoan"] as NguoiDung).IdNguoiDung; nc.TenBaiHat = f["ten"]; nc.NgheSiThucHien = f["nghesi"]; //Ảnh string fileName = Path.GetFileNameWithoutExtension(anh.FileName); fileName += Path.GetExtension(anh.FileName); string folderPath = Server.MapPath("~") + @"/Assets/images/ImagesOutSource/ImagesSong"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } string path = Path.Combine(folderPath, fileName); anh.SaveAs(path); nc.AnhBaiHat = fileName; //Nhạc string fileName2 = Path.GetFileNameWithoutExtension(nhac.FileName); fileName2 += Path.GetExtension(nhac.FileName); string folderPath2 = Server.MapPath("~") + @"/MusicDowload"; if (!Directory.Exists(folderPath2)) { Directory.CreateDirectory(folderPath2); } string path2 = Path.Combine(folderPath2, fileName2); nhac.SaveAs(path2); nc.LinkNhac = fileName2; NhacCaNhanDAO newSong = new NhacCaNhanDAO(); newSong.Add(nc); var listNhacCaNhan = newSong.ListOf(); return(View(listNhacCaNhan)); }
public void Add(NhacCaNhan obj) { context.NhacCaNhans.Add(obj); context.SaveChanges(); }