public static string Save(string id, string title, string time, string author, string content, string userid) { using (XMWBEntities entity = new XMWBEntities()) { TB_LSARTICLE ad = entity.TB_LSARTICLE.SingleOrDefault(t => t.CM_USERID == userid); if (ad == null) { try { TB_LSARTICLE lsad = new TB_LSARTICLE(); lsad.CM_TITLE = title; lsad.CM_TIME = DateTime.Now; lsad.CM_AUTHOR = author; lsad.CM_CONTENT = content; lsad.CM_USERID = userid; lsad.CM_ID = id; entity.TB_LSARTICLE.Add(lsad); entity.SaveChanges(); return(handle.ObjToJson.ToJson(lsad)); } catch (Exception e) { return("5"); } } else { try { ad.CM_TITLE = title; ad.CM_TIME = DateTime.Now; ad.CM_AUTHOR = author; ad.CM_CONTENT = content; entity.SaveChanges(); return(handle.ObjToJson.ToJson(ad)); } catch (Exception e) { return("5"); } } } }
public ActionResult Preview(string id, string avid) { if (string.IsNullOrWhiteSpace(id)) { return(new EmptyResult()); } else { using (XMWBEntities entity = new XMWBEntities()) { TB_LSARTICLE at = entity.TB_LSARTICLE.SingleOrDefault(t => t.CM_ID == id); if (at != null) { TB_ARTICLE ad = new TB_ARTICLE(); ad.CM_USERID = at.CM_USERID; ad.CM_ADVMTID = string.IsNullOrWhiteSpace(avid) ? "" : avid; ad.CM_AUTHOR = at.CM_AUTHOR; ad.CM_CONTENT = at.CM_CONTENT; ad.CM_ID = at.CM_ID; ad.CM_TIME = DateTime.Now; ad.CM_TITLE = at.CM_TITLE; ad.CM_TYPE = 2; ad.CM_ISPASS = 0; entity.TB_ARTICLE.Add(ad); entity.Set <TB_LSARTICLE>().Remove(at); entity.SaveChanges(); return(View(ad)); } else { TB_ARTICLE ARTICLE = entity.TB_ARTICLE.SingleOrDefault(t => t.CM_ID == id); if (ARTICLE != null) { TB_USER user = entity.TB_USER.SingleOrDefault(t => t.CM_USERID == ARTICLE.CM_USERID); if (user != null) { if (user.CM_EXPIRINGTIME < DateTime.Now) { ARTICLE = null; } } else { ARTICLE = null; } } return(View(ARTICLE)); } } } }
public static string Revise(string id, string content, string advertid, string title, string date, string author) { using (XMWBEntities entity = new XMWBEntities()) { TB_LSARTICLE at = entity.TB_LSARTICLE.SingleOrDefault(t => t.CM_ID == id); try { if (at != null) { TB_ARTICLE ad = new TB_ARTICLE(); ad.CM_USERID = at.CM_USERID; ad.CM_ADVMTID = string.IsNullOrWhiteSpace(advertid) ? "" : advertid; ad.CM_AUTHOR = string.IsNullOrWhiteSpace(author) ? at.CM_AUTHOR : author; ad.CM_CONTENT = content; ad.CM_ID = at.CM_ID; ad.CM_TIME = DateTime.Now; ad.CM_TITLE = string.IsNullOrWhiteSpace(title) ? at.CM_TITLE : title; ad.CM_TYPE = 2; ad.CM_ISPASS = 0; entity.TB_ARTICLE.Add(ad); entity.Set <TB_LSARTICLE>().Remove(at); entity.SaveChanges(); return("0"); } else { return("3"); } } catch (Exception e) { return("2"); } } }