public int AddNew(NgheSi obj) { var result = context.NgheSis.Add(obj); if (result != null) { context.SaveChanges(); return(result.IdNgheSi); } return(-1); }
//Xem chi tiết public ViewResult XemChiTiet(int MaNS) { NgheSi nghesi = db.NgheSis.SingleOrDefault(n => n.MaNS == MaNS); if (nghesi == null) { Response.StatusCode = 404; return(null); } return(View(nghesi)); }
public ViewResult XemChiTietNS(int MaNgheSi) { NgheSi ngheSi = db.NgheSis.SingleOrDefault(n => n.MaNS == MaNgheSi); if (ngheSi == null) { //Trả về trang nào đó báo lỗi Response.StatusCode = 404; return(null); } return(View(ngheSi)); }
public ActionResult AddNew(NgheSi obj, HttpPostedFileBase file) { try { NgheSiDAO dao = new NgheSiDAO(); if (file != null && file.ContentLength > 0) { string fileName = Path.GetFileNameWithoutExtension(file.FileName); fileName += "_" + obj.IdNgheSi; fileName += Path.GetExtension(file.FileName); string folderPath = Server.MapPath("~") + @"\Areas\Admin\Asset\ImagesOutSource\imgsinger"; string folderPath2 = Server.MapPath("~") + @"\Assets\images\ImagesOutSource\ImagesSing"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } string path = Path.Combine(folderPath, fileName); string path2 = Path.Combine(folderPath2, fileName); file.SaveAs(path); file.SaveAs(path2); obj.AnhNgheSi = fileName; int id = dao.AddNew(obj); if (id != -1) { return(RedirectToAction("Index", "NgheSi")); } else { ViewBag.Message("Them moi khong thanh cong"); return(RedirectToAction("AddNew", "NgheSi")); } } else { ModelState.AddModelError("", "Bạn phải nhập vào trường này"); } } catch { } KhuVucDAO kvDAO = new KhuVucDAO(); var kv = kvDAO.ListOf(); ViewBag.kv = kv; return(View()); }
public bool Update(NgheSi obj) { var ns = context.NgheSis.SingleOrDefault(x => x.IdNgheSi == obj.IdNgheSi); if (ns != null) { ns.TenNgheSi = obj.TenNgheSi; ns.AnhNgheSi = obj.AnhNgheSi; ns.IdKhuVuc = obj.IdKhuVuc; ns.LuotQuanTam = obj.LuotQuanTam; ns.Hot = obj.Hot; context.SaveChanges(); return(true); } return(false); }
public ActionResult Add(BaiHat obj, NgheSi obj2, HttpPostedFileBase file, HttpPostedFileBase fileMusic, FormCollection f) { NgheSiDAO dao2 = new NgheSiDAO(); BaiHatDAO dao = new BaiHatDAO(); try { if (file != null && file.ContentLength > 0) { //anh bai hat string fileName = Path.GetFileNameWithoutExtension(file.FileName); fileName += "_" + obj.IdBaiHat; fileName += Path.GetExtension(file.FileName); string folderPath = Server.MapPath("~") + @"\Assets\images\ImagesOutSource\ImagesSong"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } string path = Path.Combine(folderPath, fileName); file.SaveAs(path); //anh nghe si string fileName2 = Path.GetFileNameWithoutExtension(fileMusic.FileName); //fileName2 += "_" + obj.LinkBaiHat; fileName2 += Path.GetExtension(fileMusic.FileName); string folderPath2 = Server.MapPath("~") + @"\MusicDowload"; if (!Directory.Exists(folderPath2)) { Directory.CreateDirectory(folderPath2); } string path2 = Path.Combine(folderPath2, fileName2); fileMusic.SaveAs(path2); obj.AnhBaiHat = fileName; obj.LinkBaiHat = fileName2; obj.IdNgheSi = Convert.ToInt32(f["getNgheSi"]); int id = dao.AddNew(obj); if (id != -1) { return(RedirectToAction("Add", "AdBaiHat")); } else { ViewBag.Message("Thêm mới không thành công!"); return(View()); } } else { ModelState.AddModelError("", "Bạn phải nhập vào trường này"); } } catch { } TheLoaiDAO tldao = new TheLoaiDAO(); var category = tldao.ListOf(); NgheSiDAO nsdao = new NgheSiDAO(); var nghesi = nsdao.Listof(); AlbumDAO abdao = new AlbumDAO(); var album = abdao.Listof(); ViewBag.category = category; ViewBag.nghesi = nghesi; ViewBag.album = album; return(View()); }