public TBulletin BulletinSingleByTitle(string loginKey, ref ErrorInfo err, string title) { if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod())) { return(null); } using (DBEntities db = new DBEntities()) { TBulletin reEnt = new TBulletin(); YL_BULLETIN ent = db.YL_BULLETIN.FirstOrDefault(x => x.TITLE == title); if (ent == null) { reEnt.TITLE = title; reEnt.ISSUE_DATE = DateTime.Now; reEnt.IS_SHOW = 0; reEnt.IS_URGENT = 0; } else { reEnt = Fun.ClassToCopy <YL_BULLETIN, TBulletin>(ent); reEnt.AllFiles = Fun.ClassListToCopy <YL_FILES, FILES>(ent.YL_FILES.ToArray()); reEnt.AllFilesStr = JSON.DecodeToStr(reEnt.AllFiles); } return(reEnt); } }
public ProInterface.Models.Api.ApiPagingDataBean BulletinList(ref ErrorInfo err, ProInterface.Models.Api.ApiRequesPageBean inEnt) { GlobalUser gu = Global.GetUser(inEnt.authToken); ApiPagingDataBean reEnt = new ApiPagingDataBean(); int skip = 0; if (inEnt.currentPage > 1) { skip = (inEnt.currentPage - 1) * inEnt.pageSize; } using (DBEntities db = new DBEntities()) { var tmpEnt = db.YL_BULLETIN.AsEnumerable(); var allData = tmpEnt.Where(x => x.IS_SHOW == 1 && x.ISSUE_DATE < DateTime.Now).OrderByDescending(x => x.IS_URGENT).ThenByDescending(x => x.ISSUE_DATE).AsEnumerable(); allData = allData.Where(x => x.YL_ROLE.Where(y => gu.RoleID.Contains(y.ID)).Count() > 0).AsEnumerable(); ErrorInfo error = new ErrorInfo(); #region 过虑条件 foreach (var filter in inEnt.searchKey) { if (filter.K == "CREATE_TIME" && filter.T == ">=" && !string.IsNullOrEmpty(filter.V)) { DateTime dt1 = DateTime.ParseExact(filter.V, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture); allData = allData.Where(x => x.CREATE_TIME >= dt1).AsEnumerable(); } else if (filter.K == "CREATE_TIME" && filter.T == "<=" && !string.IsNullOrEmpty(filter.V)) { DateTime dt2 = DateTime.ParseExact(filter.V, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture); allData = allData.Where(x => x.CREATE_TIME <= dt2).AsEnumerable(); } else if (filter.V == "全部") { allData = tmpEnt.Where(x => x.IS_SHOW == 1 && x.ISSUE_DATE < DateTime.Now).OrderByDescending(x => x.IS_URGENT).ThenByDescending(x => x.ISSUE_DATE).AsEnumerable(); } else { allData = Fun.GetListWhere <YL_BULLETIN>(allData, filter.K, filter.T, filter.V, ref error); } } #endregion var allList = allData.Skip(skip).Take(inEnt.pageSize).ToList(); reEnt.currentPage = inEnt.currentPage; reEnt.pageSize = inEnt.pageSize; reEnt.totalCount = allData.Count(); reEnt.totalPage = reEnt.totalCount / reEnt.pageSize; if (reEnt.totalCount % reEnt.pageSize != 0) { reEnt.totalPage++; } IList <TBulletin> reList = new List <TBulletin>(); foreach (var t in allList) { TBulletin tmp = Fun.ClassToCopy <YL_BULLETIN, TBulletin>(t); tmp.CONTENT = Fun.NoHTML(tmp.CONTENT); reList.Add(tmp); } reEnt.data = reList; } return(reEnt); }
public ProInterface.Models.TBulletin BulletinSingle(string loginKey, ref ErrorInfo err, int?bullID) { if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod())) { return(null); } using (DBEntities db = new DBEntities()) { TBulletin reEnt = new TBulletin(); YL_BULLETIN ent = db.YL_BULLETIN.SingleOrDefault(x => x.ID == bullID); GlobalUser gu = Global.GetUser(loginKey); if (ent != null) { db.YL_BULLETIN_LOG.Add(new YL_BULLETIN_LOG { BULLETIN_ID = ent.ID, LOOK_TIME = DateTime.Now, USER_ID = gu.UserId }); db.SaveChanges(); reEnt = Fun.ClassToCopy <YL_BULLETIN, TBulletin>(ent); reEnt.AllFiles = Fun.ClassListToCopy <YL_FILES, FILES>(ent.YL_FILES.ToArray()); reEnt.AllFilesStr = JSON.DecodeToStr(reEnt.AllFiles); reEnt.AllRoleId = string.Join(",", ent.YL_ROLE.Select(x => x.ID).ToList()); var user = db.YL_USER.SingleOrDefault(x => x.ID == ent.USER_ID); if (user != null) { reEnt.DistrictName = user.YL_DISTRICT.NAME; } foreach (var t in ent.YL_BULLETIN_REVIEW.OrderBy(x => x.ADD_TIME).ToList()) { var tmp = Fun.ClassToCopy <YL_BULLETIN_REVIEW, ProInterface.Models.BulletinReview>(t); var userTmp = db.YL_USER.SingleOrDefault(x => x.ID == t.USER_ID); if (userTmp != null) { tmp.UserName = userTmp.NAME; tmp.DistictName = userTmp.YL_DISTRICT.NAME; tmp.UserPhone = userTmp.LOGIN_NAME; tmp.UserRole = string.Join(",", userTmp.YL_ROLE.Select(x => x.NAME).ToList()); } reEnt.AllChildrenItem.Add(tmp); } } else { reEnt.IS_URGENT = 1; reEnt.IS_IMPORT = 1; reEnt.IS_SHOW = 1; reEnt.REGION = gu.DistrictId.ToString(); } return(reEnt); } }