public object DeleteById(int id) { try { EFHelper <NewsAndCases> eFHelper = new EFHelper <NewsAndCases>(); NewsAndCases newsAndCases = new NewsAndCases(); using (DDContext context = new DDContext()) { newsAndCases = context.NewsAndCases.Find(id); context.NewsAndCases.Remove(newsAndCases); context.SaveChanges(); } return(new NewErrorModel() { data = newsAndCases, error = new Error(0, "删除成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public object AddVisitingtime(int id) { try { EFHelper <NewsAndCases> eFHelper = new EFHelper <NewsAndCases>(); NewsAndCases newsAndCases = eFHelper.GetListById(id); newsAndCases.visitingtime = (newsAndCases.visitingtime == null?0: newsAndCases.visitingtime) + 1; eFHelper.Modify(newsAndCases); return(new NewErrorModel() { data = newsAndCases, error = new Error(0, "累加成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }
public object Save([FromBody] NewsAndCases newsAndCases) { try { EFHelper <NewsAndCases> eFHelper = new EFHelper <NewsAndCases>(); newsAndCases.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); eFHelper.Add(newsAndCases); return(new NewErrorModel() { error = new Error(0, "保存成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }
public object ReadById(int id) { try { EFHelper <NewsAndCases> eFHelper = new EFHelper <NewsAndCases>(); NewsAndCases newsAndCases = eFHelper.GetListById(id); return(new NewErrorModel() { data = newsAndCases, error = new Error(0, "读取成功!", "") { }, }); } catch (Exception ex) { throw ex; } }
public object Save([FromBody] NewsAndCases newsAndCases) { try { EFHelper <NewsAndCases> eFHelper = new EFHelper <NewsAndCases>(); eFHelper.Add(newsAndCases); return(new NewErrorModel() { error = new Error(0, "保存成功!", "") { }, }); } catch (Exception ex) { return(new NewErrorModel() { error = new Error(1, ex.Message, "") { }, }); } }