//用于修改文章 public static BaseResultModel <Article> UpdateArticle(Article article) { BaseResultModel <Article> result = new BaseResultModel <Article>(); try{ using (CDBContext _cDBContext = new CDBContext()){ Article a = _cDBContext.Ar.FirstOrDefault(p => p.Id.Equals(article.Id)); a.UserName = article.UserName; a.type = article.type; a.ArticleContext = article.ArticleContext; a.ArticleSideName = article.ArticleSideName; a.ArticleUpdateDate = article.ArticleUpdateDate; a.ArticleName = article.ArticleName; _cDBContext.Ar.Update(a); _cDBContext.SaveChanges(); result.status = 1; result.Data = null; result.message = "更新文章成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
//用于添加富文章 public static BaseResultModel <SimpleArticle> SetRichArticle(SimpleArticle simpleArticle) { BaseResultModel <SimpleArticle> result = new BaseResultModel <SimpleArticle>(); try{ using (CDBContext _cDBContext = new CDBContext()){ SimpleArticle a = new SimpleArticle(); a.UserName = simpleArticle.UserName; a.type = simpleArticle.type; a.ArticleContext = simpleArticle.ArticleContext; a.ArticleCreateDate = simpleArticle.ArticleCreateDate; a.ArticleImgUrl = simpleArticle.ArticleImgUrl; a.ArticleUpdateDate = simpleArticle.ArticleUpdateDate; _cDBContext.Si.Add(a); _cDBContext.SaveChanges(); result.status = 1; result.Data = null; result.message = "添加文章成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
public void Guardar() { //var docente = new Docente(); try { using (CDBContext db = new CDBContext()) { if (this.Code_Docente == 0) { db.Entry(this).State = EntityState.Added; foreach (var m in this.Materias) { db.Entry(m).State = EntityState.Unchanged; } } db.SaveChanges(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
//一次添加多个轮播图 public static BaseResultModel <List <ScrollPicture> > AddScrollPicList(List <ScrollPicture> sp) { BaseResultModel <List <ScrollPicture> > result = new BaseResultModel <List <ScrollPicture> >(); try{ using (CDBContext _cDBContext = new CDBContext()){ for (int i = 0; i < sp.Count; i++) { ScrollPicture scrollpicture = new ScrollPicture(); scrollpicture.PicName = sp[i].PicName; scrollpicture.ImgUrl = sp[i].ImgUrl; scrollpicture.ImgSubmitDate = sp[i].ImgSubmitDate; scrollpicture.UserName = sp[i].UserName; _cDBContext.Sc.Add(scrollpicture); } _cDBContext.SaveChanges(); result.status = 1; result.Data = null; result.message = "多张轮播图添加成功"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
//添加邮件信息 public static BaseResultModel <Message> SetMail(Message message) { BaseResultModel <Message> result = new BaseResultModel <Message>(); try{ using (CDBContext _cDBContext = new CDBContext()){ Message ms = new Message(); ms.Name = message.Name; ms.Phone = message.Phone; ms.Email = message.Email; ms.Infos = message.Infos; ms.SubmitDate = DateTime.Now.ToString(); _cDBContext.Me.Add(ms); _cDBContext.SaveChanges(); result.status = 1; result.Data = ms; result.message = "邮件提交成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
static void Main(string[] args) { CMysqlDBContext K = new CMysqlDBContext(); var list = K.userInfos.ToList(); K.Dispose(); CDBContext dBContext = new CDBContext(); var listUser = dBContext.userInfos.ToList(); }
//用于获取不同页面中富文本介绍 public static BaseResultModel <List <SimpleArticle> > GetFrontRichList(string type) { BaseResultModel <List <SimpleArticle> > result = new BaseResultModel <List <SimpleArticle> >(); try{ using (CDBContext _cDBContext = new CDBContext()){ result.status = 1; result.Data = _cDBContext.Si.Where(p => p.type.Equals(type)).Take(3).ToList(); result.message = "获取数据成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
//前台根据页面获取文章列表 public static BaseResultModel <List <Article> > GetFrontArticleList(string type) { BaseResultModel <List <Article> > result = new BaseResultModel <List <Article> >(); try{ using (CDBContext _cDBContext = new CDBContext()){ List <Article> messages = _cDBContext.Ar.Where(p => p.type == type).Take(3).ToList(); result.status = 1; result.Data = messages; result.message = "获取数据成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
//前台根据页面获取页面左下角图文 public static BaseResultModel <Article> GetFrontArticle(string type) { BaseResultModel <Article> result = new BaseResultModel <Article>(); try{ using (CDBContext _cDBContext = new CDBContext()){ Article messages = _cDBContext.Ar.FirstOrDefault(p => p.type == type); result.status = 1; result.Data = messages; result.message = "获取数据成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
public List <Docente> allDocentes() { var docente = new List <Docente>(); try { using (CDBContext db = new CDBContext()) { docente = db.Docentes.ToList(); } } catch (Exception ex) { throw new Exception(ex.Message); } return(docente); }
public List <Materia> allMaterias() { var materias = new List <Materia>(); try { using (CDBContext db = new CDBContext()) { materias = db.Materias.ToList(); } } catch (Exception ex) { throw new Exception(ex.Message); } return(materias); }
//后台获取文章类型 public static PaginationResultModel <Article> GetArticleList(PaginationModel pageList) { PaginationResultModel <Article> result = new PaginationResultModel <Article>(); try{ using (CDBContext _cDBContext = new CDBContext()){ List <Article> messages = _cDBContext.Ar.Skip((pageList.Index - 1) * pageList.Size).Take(pageList.Size).ToList(); result.Total = _cDBContext.Ar.Count(); result.status = 1; result.Data = messages; result.message = "获取数据成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); result.Total = 0; } return(result); }
// private static CDBContext _cDBContext; // public MailService(CDBContext CDBContext){ // _cDBContext=CDBContext; // } //展示邮件列表 public static PaginationResultModel <Message> GetMailList(PaginationModel pageList) { PaginationResultModel <Message> result = new PaginationResultModel <Message>(); try{ using (CDBContext cb = new CDBContext()){ List <Message> mss = new List <Message>(); mss = cb.Me.Skip((pageList.Index - 1) * pageList.Size).Take(pageList.Size).ToList(); result.Total = cb.Me.Count(); result.status = 1; result.Data = mss; result.message = "获取数据成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); result.Total = 0; } return(result); }
public static PaginationResultModel <ScrollPicture> GetPicList(PaginationModel pageList) { PaginationResultModel <ScrollPicture> result = new PaginationResultModel <ScrollPicture>(); try{ using (CDBContext _cDBContext = new CDBContext()){ List <ScrollPicture> sps = new List <ScrollPicture>(); sps = _cDBContext.Sc.Skip((pageList.Index - 1) * pageList.Size).Take(pageList.Size).ToList(); result.Total = _cDBContext.Sc.Count(); result.status = 1; result.Data = sps; result.message = "获取轮播图添加成功"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); result.Total = 0; } return(result); }
public Docente getConsulta(int id) { var docente = new Docente(); try { using (CDBContext db = new CDBContext()) { docente = db.Docentes .Include("Materia") .Where(x => x.Code_Docente == id) .Single(); } } catch (Exception ex) { throw new Exception(ex.Message); } return(docente); }
public static BaseResultModel <ScrollPicture> DeleteScrollPic(string Id) { int id = Int32.Parse(Id); BaseResultModel <ScrollPicture> result = new BaseResultModel <ScrollPicture>(); try{ using (CDBContext _cDBContext = new CDBContext()){ ScrollPicture sps = new ScrollPicture(); sps = _cDBContext.Sc.FirstOrDefault(p => p.Id == id); _cDBContext.Remove(sps); _cDBContext.SaveChanges(); result.status = 1; result.Data = null; result.message = "删除轮播图添加成功"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
public static BaseResultModel <Message> DeleteMessages(string Id) { int id = Int32.Parse(Id); BaseResultModel <Message> result = new BaseResultModel <Message>(); try{ using (CDBContext _cDBContext = new CDBContext()){ Message ms = new Message(); ms = _cDBContext.Me.FirstOrDefault(p => p.Id == id); _cDBContext.Remove(ms); _cDBContext.SaveChanges(); result.status = 1; result.Data = null; result.message = "邮件删除成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
//用于修改富文章 public static BaseResultModel <SimpleArticle> UpdateRichArticle(SimpleArticle simpleArticle) { BaseResultModel <SimpleArticle> result = new BaseResultModel <SimpleArticle>(); try{ using (CDBContext _cDBContext = new CDBContext()){ SimpleArticle a = _cDBContext.Si.FirstOrDefault(p => p.Id == simpleArticle.Id); a.UserName = simpleArticle.UserName; a.type = simpleArticle.type; a.ArticleContext = simpleArticle.ArticleContext; a.ArticleUpdateDate = simpleArticle.ArticleUpdateDate; _cDBContext.Si.Update(a); _cDBContext.SaveChanges(); result.status = 1; result.Data = null; result.message = "更新文章成功!"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
//添加轮播图片 public static BaseResultModel <ScrollPicture> AddScrollPic(ScrollPicture sp) { BaseResultModel <ScrollPicture> result = new BaseResultModel <ScrollPicture>(); try{ using (CDBContext _cDBContext = new CDBContext()){ ScrollPicture scrollpicture = new ScrollPicture(); scrollpicture.PicName = sp.PicName; scrollpicture.ImgUrl = sp.ImgUrl; scrollpicture.ImgSubmitDate = sp.ImgSubmitDate; scrollpicture.UserName = sp.UserName; _cDBContext.Sc.Add(scrollpicture); _cDBContext.SaveChanges(); result.status = 1; result.Data = null; result.message = "轮播图添加成功"; } }catch (Exception ex) { result.status = 0; result.Data = null; result.message = ex.ToString(); } return(result); }
public CustomersController() { _db = new CDBContext(); GeneraToken(); }
public HomeController() { _context = new CDBContext(); }
public ScrollPicService(CDBContext CDBContext) { _cDBContext = CDBContext; }