コード例 #1
0
ファイル: Module.cs プロジェクト: wengzhilai/OldWebApi
 /// <summary>
 /// 查询一条
 /// </summary>
 /// <param name="loginKey">登录凭证</param>
 /// <param name="err">错误信息</param>
 /// <param name="id">条件lambda表达表</param>
 /// <returns>查询一条</returns>
 public ProInterface.Models.TModule ModuleSingleId(string loginKey, ref ProInterface.ErrorInfo err, int id)
 {
     if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
     {
         return(null);
     }
     using (DBEntities db = new DBEntities())
     {
         var ent   = db.YL_MODULE.SingleOrDefault(x => x.ID == id);
         var reEnt = new ProInterface.Models.TModule();
         if (ent != null)
         {
             reEnt = Fun.ClassToCopy <YL_MODULE, ProInterface.Models.TModule>(ent);
             reEnt.AllRoleIdArrStr = string.Join(",", ent.YL_ROLE.Select(x => x.ID));
         }
         return(reEnt);
     }
 }
コード例 #2
0
ファイル: Module.cs プロジェクト: wengzhilai/OldWebApi
        /// <summary>
        /// 修改模块
        /// </summary>
        /// <param name="loginKey">登录凭证</param>
        /// <param name="err">错误信息</param>
        /// <param name="inEnt">实体类</param>
        /// <param name="allPar">更新的参数</param>
        /// <returns>修改模块</returns>
        public bool ModuleSave(string loginKey, ref ProInterface.ErrorInfo err, ProInterface.Models.TModule inEnt, IList <string> allPar)
        {
            if (!UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(false);
            }
            using (DBEntities db = new DBEntities())
            {
                try
                {
                    var  ent   = db.YL_MODULE.SingleOrDefault(a => a.ID == inEnt.ID);
                    bool isAdd = false;
                    if (ent == null)
                    {
                        isAdd  = true;
                        ent    = Fun.ClassToCopy <ProInterface.Models.MODULE, YL_MODULE>(inEnt);
                        ent.ID = Fun.GetSeqID <YL_MODULE>();
                    }
                    else
                    {
                        ent = Fun.ClassToCopy <ProInterface.Models.MODULE, YL_MODULE>(inEnt, ent, allPar);
                    }
                    var allRoleId = inEnt.AllRoleIdArrStr.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                    ent.YL_ROLE.Clear();
                    ent.YL_ROLE = db.YL_ROLE.Where(x => allRoleId.Contains(x.ID)).ToList();

                    if (isAdd)
                    {
                        db.YL_MODULE.Add(ent);
                    }
                    db.SaveChanges();
                    UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Edit);
                    return(true);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = e.Message;
                    return(false);
                }
            }
        }