Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        public object BulletinSave(string loginKey, ref ErrorInfo err, ProInterface.Models.TBulletin inEnt, IList <string> allPar)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            using (DBEntities db = new DBEntities())
            {
                GlobalUser gu = Global.GetUser(loginKey);
                inEnt.AllFiles = JSON.EncodeToEntity <IList <FILES> >(inEnt.AllFilesStr == null ? "[]" : inEnt.AllFilesStr);
                IList <int> fileIdList = inEnt.AllFiles.Select(x => x.ID).ToList();
                if (string.IsNullOrEmpty(inEnt.AllRoleId))
                {
                    err.IsError = true;
                    err.Message = string.Format("保存失败,没有选择可查看的角色", inEnt.AllRoleId);
                    return(null);
                }
                IList <int> AllRoleId = inEnt.AllRoleId.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                YL_BULLETIN reEnt     = new YL_BULLETIN();
                if (inEnt.ID == 0)
                {
                    reEnt             = Fun.ClassToCopy <ProInterface.Models.BULLETIN, YL_BULLETIN>(inEnt);
                    reEnt.ID          = Fun.GetSeqID <YL_BULLETIN>();
                    reEnt.YL_FILES    = db.YL_FILES.Where(x => fileIdList.Contains(x.ID)).ToList();
                    reEnt.YL_ROLE     = db.YL_ROLE.Where(x => AllRoleId.Contains(x.ID)).ToList();
                    reEnt.PUBLISHER   = gu.UserName;
                    reEnt.CREATE_TIME = DateTime.Now;
                    reEnt.UPDATE_TIME = DateTime.Now;
                    reEnt.REGION      = gu.Region;
                    reEnt.USER_ID     = gu.UserId;
                    reEnt             = db.YL_BULLETIN.Add(reEnt);
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                }
                else
                {
                    reEnt = db.YL_BULLETIN.SingleOrDefault(x => x.ID == inEnt.ID);

                    if (reEnt.USER_ID != gu.UserId)
                    {
                        err.IsError = true;
                        err.Message = string.Format("该公告是【{0}】添加的,不能修改", reEnt.PUBLISHER);
                        return(null);
                    }



                    reEnt = Fun.ClassToCopy <ProInterface.Models.BULLETIN, YL_BULLETIN>(inEnt, reEnt, allPar);
                    var allNowFiles = db.YL_FILES.Where(x => fileIdList.Contains(x.ID)).ToList();
                    foreach (var t in reEnt.YL_FILES.ToList())
                    {
                        if (allNowFiles.SingleOrDefault(x => x.ID == t.ID) == null)
                        {
                            reEnt.YL_FILES.Remove(t);
                            db.YL_FILES.Remove(t);
                        }
                    }

                    reEnt.YL_FILES.Clear();
                    reEnt.YL_ROLE.Clear();
                    reEnt.YL_ROLE     = db.YL_ROLE.Where(x => AllRoleId.Contains(x.ID)).ToList();
                    reEnt.YL_FILES    = allNowFiles;
                    reEnt.PUBLISHER   = gu.UserName;
                    reEnt.UPDATE_TIME = DateTime.Now;
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                }
                try
                {
                    //FunTask.StartTask(db, ref err, 1, "阅读公告信息", gu);
                    db.SaveChanges();
                    return(reEnt.ID);
                }
                catch (DbEntityValidationException e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetDbEntityErrMess(e);
                    err.Excep   = e;
                    return(null);
                }
            }
        }