public ActionResult Create(FormCollection fc, CMS_TypeOfQuestion obj) { try { if (ModelState.IsValid) { CMS_TypeOfQuestion_DAO objDAO = new CMS_TypeOfQuestion_DAO(); int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { SetAlert("Thêm bản ghi thành công", AlertType.Success); return(RedirectToAction("index", "CMS_TypeOfQuestion")); } else { ModelState.AddModelError("", "Thêm mới không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult Edit(FormCollection fc, CMS_TypeOfQuestion obj) { try { if (ModelState.IsValid) { CMS_TypeOfQuestion_DAO objDAO = new CMS_TypeOfQuestion_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); if (objDAO.Update(obj)) { SetAlert("Cập nhật thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_TypeOfQuestion")); } else { SetAlert("Cập nhật không thành công", AlertType.Error); } } return(View(obj)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public bool Update(CMS_TypeOfQuestion entity) { try { MyContext.Entry(entity).State = EntityState.Modified; MyContext.SaveChanges(); return(true); } catch (Exception ex) { Logs.WriteLog(ex); return(false); } }
public int Insert(CMS_TypeOfQuestion entity) { try { MyContext.CMS_TypeOfQuestion.Add(entity); MyContext.SaveChanges(); return(entity.ID); } catch (Exception ex) { Logs.WriteLog(ex); throw; } }