public ActionResult Update(int?id) { if (id.HasValue) { var obj = tgService.Get((int)id); ViewBag.IsEdit = true; return(View(obj)); } return(View()); }
public ActionResult Create(OSanPham model) { if (ModelState.IsValid) { // var pro = ServiceFactory.NewsgoryManager.Get(new Newsgories { NewsgoryId = model.NewsgoryId }); try { model.TenVanTat = Help.Helper.convertToUnSign3(model.TenSanPham); model.TuKhoa += Help.Helper.convertLower(model.TenSanPham + ", "); var category = chuDeService.Get(new OChuDe { MaChuDe = (int)model.MaChuDe }); model.TuKhoa += Help.Helper.convertLower(category.Ten + ","); var account = (OAccount)Session["Account"]; model.NguoiTao = (Guid)account.MaTK; if (model.IsSach != null && model.IsSach == true) { foreach (var item in model.MaTacGia) { var tacgia = tacGiaService.Get(item); model.TuKhoa += Help.Helper.convertLower(tacgia.Ten + ","); } } //if (model.IsSach == true) //{ // System.IO.FileStream fs = new System.IO.FileStream("/sach/" + model.TenVanTat, System.IO.FileMode.Create); //} //else //{ // System.IO.FileStream fs = new System.IO.FileStream("/do-dung-hoc-tap/" + model.TenVanTat, System.IO.FileMode.Create); //} sanphamService.Add(model); if (model.IsSach != null && model.IsSach == true) { var idSach = sanphamService.GetLastId(); if (model.MaTacGia.ToList() != null && model.MaTacGia.ToList().Count > 0) { foreach (int item in model.MaTacGia) { sach_TacGiaService.Add(new OSach_TacGia { MaTacGia = item, MaSanPham = idSach, }); } } } return(RedirectToAction("Search", "QuanLySanPham", new { isSach = model.IsSach })); } catch (Exception e) { } } List <OChuDe> listCate = chuDeService.GetAll(); ViewBag.ListCate = new SelectList(listCate, "MaChuDe", "Ten"); List <ONhaXuatBan> listNXB = nxbService.GetAll(); ViewBag.ListNXB = new SelectList(listNXB, "MaNXB", "TenNXB"); ViewBag.ListTacGia = new SelectList(tacGiaService.GetAll(), "MaTacGia", "Ten"); ViewBag.ListNCC = new SelectList(nccService.GetAllActive(), "MaNCC", "TenNCC"); ViewBag.IsEdit = true; return(View("Update", model)); }