public ActionResult DeleteConfirmed(string id) { NhanHieu nhanHieu = db.NhanHieus.Find(id); db.NhanHieus.Remove(nhanHieu); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <IActionResult> EditConfirmed( int id, [Bind("Id,TenNhanHieu")] NhanHieu nhanHieu, bool?modal, bool?redirect) { AddInfoToViewData(); bool isModal = modal ?? false; bool isRedirect = redirect ?? true; Message message = new Message(); if (id != nhanHieu.Id) { message.Type = MessageType.Error; message.Header = _sharedLocalizer["DefaultErrorHeader"]; message.Content = _sharedLocalizer["Invalid"]; } else if (ModelState.IsValid) { try { await _bookStoreData.UpdateNhanHieu(nhanHieu); message.Type = MessageType.Success; message.Header = _sharedLocalizer["Success"]; message.Content = string.Format( "{0} {1}", _sharedLocalizer[action], _sharedLocalizer[controller].Value.ToLower()); if (isModal) { message.Results["Reload"] = true; } if (isRedirect) { message.Results["RedirectUrl"] = Url.Action( "Details", new { id = nhanHieu.Id }); } } catch (Exception ex) { message.Type = MessageType.Error; message.Header = _sharedLocalizer["DefaultErrorHeader"]; message.Content = _sharedLocalizer[ex.GetType().FullName]; } } return(Json(message)); }
public ActionResult Edit([Bind(Include = "MaNhanHieu,TenNhanHieu,MaLoai")] NhanHieu nhanHieu) { if (ModelState.IsValid) { db.Entry(nhanHieu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaLoai = new SelectList(db.Loais, "MaLoai", "TenLoai", nhanHieu.MaLoai); return(View(nhanHieu)); }
public ActionResult Create([Bind(Include = "MaNhanHieu,TenNhanHieu,MaLoai")] NhanHieu nhanHieu) { if (ModelState.IsValid) { db.NhanHieus.Add(nhanHieu); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaLoai = new SelectList(db.Loais, "MaLoai", "TenLoai", nhanHieu.MaLoai); return(View(nhanHieu)); }
// GET: Admin/NhanHieux/Details/5 public ActionResult Details(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NhanHieu nhanHieu = db.NhanHieus.Find(id); if (nhanHieu == null) { return(HttpNotFound()); } return(View(nhanHieu)); }
// GET: Admin/NhanHieux/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NhanHieu nhanHieu = db.NhanHieus.Find(id); if (nhanHieu == null) { return(HttpNotFound()); } ViewBag.MaLoai = new SelectList(db.Loais, "MaLoai", "TenLoai", nhanHieu.MaLoai); return(View(nhanHieu)); }
public bool CapNhat(NhanHieu nh) { try { var _nh = _context.NhanHieux.SingleOrDefault(x => x.MaNhanHien == nh.MaNhanHien); _nh.TenNhanHien = nh.TenNhanHien; _nh.MaNhanHien = nh.MaNhanHien; _nh.GhiChu = nh.GhiChu; _context.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public ActionResult Create(NhanHieu nh) { if (ModelState.IsValid) { var nhDao = new NhanHieuDAO(); string maNH = nhDao.ThemMoiNhanHieu(nh); if (!string.IsNullOrEmpty(maNH)) { return(RedirectToAction("Index", "NhanHieu")); } else { ModelState.AddModelError("", "Thêm nhãn hiệu thất bai"); } } return(View(nh)); }
// Phương thức thêm mới nhân viên vào database public string ThemMoiNhanHieu(NhanHieu nh) { _context.NhanHieux.Add(nh); _context.SaveChanges(); return(nh.MaNhanHien); }
private async Task <IActionResult> RUD(int?id, bool?modal, bool?redirect) { AddInfoToViewData(); bool isModal = modal ?? false; bool isRedirect = redirect ?? true; Message message = new Message(); if (id == null) { if (isModal) { message.Type = MessageType.Error; message.Header = _sharedLocalizer["DefaultErrorHeader"]; message.Content = _sharedLocalizer["NotFound"]; } } try { NhanHieu nhanHieu = await _bookStoreData.GetNhanHieuById(id); if (nhanHieu == null) { if (isModal) { message.Type = MessageType.Error; message.Header = _sharedLocalizer["DefaultErrorHeader"]; message.Content = _sharedLocalizer["NotFound"]; } } else { ViewData["Modal"] = isModal; ViewData["Redirect"] = isRedirect; if (isModal) { return(PartialView(GetUrlPartialPartial(), nhanHieu)); } else { return(View(nhanHieu)); } } } catch (Exception ex) { message.Type = MessageType.Error; message.Header = _sharedLocalizer["DefaultErrorHeader"]; message.Content = _sharedLocalizer[ex.GetType().FullName]; } if (isModal) { return(Json(message)); } else { return(RedirectToAction("Index")); } }
public async Task <int> UpdateNhanHieu(NhanHieu nhanHieu) { _context.Entry(nhanHieu).State = EntityState.Modified; return(await _context.SaveChangesAsync()); }
public async Task <int> AddNhanHieu(NhanHieu nhanHieu) { await _context.NhanHieu.AddAsync(nhanHieu); return(await _context.SaveChangesAsync()); }