public List <ShortInfo> GetShortList(int AdminID) { List <ShortInfo> lc = new List <ShortInfo>(); string sql = "select * from tbl_service_short where AdminID = " + AdminID + " and enable > -1 order by id asc"; try { using (DataTable dt = helper.GetDataTable(sql)) { if (dt != null && dt.Rows.Count > 0) { foreach (DataRow r in dt.Rows) { ShortInfo c = new ShortInfo() { ID = Convert.ToInt32(r["id"]), Title = r["Title"].ToString(), Content = r["Content"].ToString(), AddOn = Convert.ToDateTime(r["AddOn"]) }; lc.Add(c); } } } } catch { } return(lc); }
public async Task <IActionResult> Create(ShortInfo shortInfo) { if (!ModelState.IsValid) { return(View()); } await _db.ShortInfos.AddAsync(shortInfo); await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Update(int?id) { if (id == null) { return(NotFound()); } ShortInfo shortInfo = await _db.ShortInfos.FirstOrDefaultAsync(c => c.IsDeleted == false && c.Id == id); if (shortInfo == null) { return(NotFound()); } return(View(shortInfo)); }
public async Task <IActionResult> DeleteShortInfo(int?id) { if (id == null) { return(NotFound()); } ShortInfo dbShortInfo = await _db.ShortInfos.FirstOrDefaultAsync(c => c.IsDeleted == false && c.Id == id); if (dbShortInfo == null) { return(NotFound()); } dbShortInfo.IsDeleted = true; await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <IActionResult> Update(int?id, ShortInfo shortInfo) { if (id == null) { return(NotFound()); } ShortInfo dbShortInfo = await _db.ShortInfos.FirstOrDefaultAsync(c => c.IsDeleted == false && c.Id == id); if (dbShortInfo == null) { return(NotFound()); } dbShortInfo.Title = shortInfo.Title; dbShortInfo.Description = shortInfo.Description; await _db.SaveChangesAsync(); return(RedirectToAction("Index")); }