/// <summary> /// Author: Phạm Huy Hùng /// Todo: tìm kiếm đối tượng theo khóa chính /// </summary> /// <param name="obj"></param> /// <returns></returns> public TblLog FindById(TblLog obj) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { return db.TblLogs.SingleOrDefault(x => x.LogId == obj.LogId); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblLogDao::FindById::" + ex.Message); } else { throw new Exception("TblLogDao::FindByID::" + ex.InnerException.Message); } } }
public void Create(TblGallery o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { db.TblGalleries.Add(o); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGallery::Create::" + ex.Message); } else { throw new Exception("TblGallery::Create::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: xóa đối tượng /// </summary> /// <param name="o"></param> /// <returns></returns> public void Delete(TblRole o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { db.TblRoles.Add(o); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblRoleDao::Delete::" + ex.Message); } else { throw new Exception("TblRoleDao::Delete::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: tìm kiếm tin /// </summary> /// <returns></returns> public IEnumerable <TblNewsDraff> FindBy(decimal codeNews, decimal status) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { return(db.Database.SqlQuery <TblNewsDraff>("select * from TblNewDraff where TblNewDraff.CodeNew =@codeNews and TblNewDraff.ReleaseStatus = @status", new SqlParameter("@codeNews", codeNews), new SqlParameter("@status", status)).ToList()); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblNewsDraffDao::FindBy" + ex.Message); } else { throw new Exception("TblNewsDraffDao::FindBy" + ex.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: xóa đối tượng /// </summary> /// <param name="o"></param> /// <returns></returns> public void Delete(TblUserGroup o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblUserGroups.Where(x => x.Id == o.Id).SingleOrDefault(); db.TblUserGroups.Remove(res); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblUserGroup::Delete::" + ex.Message); } else { throw new Exception("TblUserGroup::Delete::" + ex.InnerException.Message); } } }
public void Create(TblLog o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblLogs.Where(x => x.LogId == o.LogId).SingleOrDefault(); db.TblLogs.Add(res); db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblLogDao::FindByAll::" + ex.Message); } else { throw new Exception("TblLogDao::FindByAll::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: tìm kiếm đối tượng theo khóa chính /// </summary> /// <param name="obj"></param> /// <returns></returns> public LoginModel FindById(string Username) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var query = from dat in db.TblUsers where dat.Username == Username select new LoginModel { username = dat.Username, password = dat.Password }; return(query.FirstOrDefault()); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblUserDao::FindById::" + ex.Message); } else { throw new Exception("TblUserDao::FindById::" + ex.InnerException.Message); } } }
public void Update(TblGallery o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblGalleries.Where(x => x.Id == o.Id).SingleOrDefault(); res.Name = o.Name; res.ImageUrl = o.ImageUrl; db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGallery::Update::" + ex.Message); } else { throw new Exception("TblGallery::Update::" + ex.InnerException.Message); } } }
public void Update(TblComment o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblComments.Where(x => x.Id == o.Id).SingleOrDefault(); res.Name = o.Name; res.Content = o.Content; db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblCommentDao::Delete::" + ex.Message); } else { throw new Exception("TblCommentDao::Delete::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: cập nhật đối tượng /// </summary> /// <param name=""></param> /// <returns></returns> public void Update(TblFileNewsDraff obj) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblFileNewsDraffs.Where(x => x.Id == obj.Id).SingleOrDefault(); res.NewsId = obj.NewsId; res.FileId = obj.FileId; db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblFileNewsDraff::Update::" + ex.Message); } else { throw new Exception("TblFileNewsDraff::Update::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: tạo list gồm các đối tượng /// </summary> /// <param name=""></param> /// <returns></returns> public IEnumerable <TblNewsDraffModel> FindByAll() { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var query = from groupnews in db.TblGroupNews.AsEnumerable() join news in db.TblNewsDraffs.AsEnumerable() on groupnews.GroupNewsId equals news.GroupNewsId select new TblNewsDraffModel { id = news.NewsId, title = news.Title, groupname = groupnews.Name, ishome = news.IsHome, isevent = news.IsEvent, isweek = news.IsWeek }; return(query.ToList()); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblNewsDraffDao::FindByAll::" + ex.Message); } else { throw new Exception("TblNewsDraffDao::FIndByAll::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: tìm kiếm đối tượng theo khóa chính /// </summary> /// <param name="obj"></param> /// <returns></returns> public TblNewsDraffModel FindById(long id) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var query = (from groupnews in db.TblGroupNews.AsEnumerable() join news in db.TblNewsDraffs.AsEnumerable() on groupnews.GroupNewsId equals news.GroupNewsId where news.NewsId == id select new TblNewsDraffModel { id = news.NewsId, title = news.Title, groupname = groupnews.Name, image = news.BigImage, shortcontent = news.ShortContent, content = news.Content, ishome = news.IsHome, isevent = news.IsEvent, isweek = news.IsWeek, createdate = news.CreateDate }).SingleOrDefault(); return(query); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblNewsDraff::FindById::" + ex.Message); } else { throw new Exception("TblNewsDraff::FindById::" + ex.InnerException.Message); } } }
/// <summary> /// Author: Phạm Huy Hùng /// Todo: cập nhật đối tượng /// </summary> /// <param name=""></param> /// <returns></returns>\ public void Update(TblGroupRole o) { try { using (TkSchoolDbContext db = new TkSchoolDbContext()) { var res = db.TblGroupRoles.Where(x => x.Id == o.Id).SingleOrDefault(); res.GroupId = o.GroupId; res.RoleId = o.RoleId; db.SaveChanges(); } } catch (Exception ex) { if (ex.InnerException == null) { throw new Exception("TblGroupRoleDao::Update::" + ex.Message); } else { throw new Exception("TblGroupRoleDao::Update::" + ex.InnerException.Message); } } }