Esempio n. 1
0
        /* 2017年5月6日16:16:54 */
        public FaUserInfo UserInfoSave(DBEntities db, ref ErrorInfo err, ApiRequesSaveEntityBean <FaUserInfo> inEnt)
        {
            GlobalUser gu = Global.GetUser(inEnt.authToken);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "登录超时";
                return(null);
            }
            if (string.IsNullOrEmpty(inEnt.saveKeys))
            {
                inEnt.saveKeys = "";
            }
            var allPar = inEnt.saveKeys.Split(',');
            //调用用户保存
            var user = api.UserApi.UserSave(db, inEnt.authToken, ref err, inEnt.entity, allPar);

            if (err.IsError)
            {
                return(null);
            }
            var userInfo = db.fa_user_info.SingleOrDefault(x => x.ID == user.ID);

            if (userInfo == null)
            {
                userInfo                  = Mapper.Map <fa_user_info>(inEnt.entity);
                userInfo.ID               = user.ID;
                userInfo.STATUS           = "正常";
                userInfo.CREATE_TIME      = DateTime.Now;
                userInfo.CREATE_USER_ID   = gu.UserId;
                userInfo.CREATE_USER_NAME = gu.UserName;
                userInfo.UPDATE_TIME      = DateTime.Now;
                userInfo.UPDATE_USER_ID   = gu.UserId;
                userInfo.UPDATE_USER_NAME = gu.UserName;
                UpdataLog <FaUserInfo> updataLog = new UpdataLog <FaUserInfo>(db);
                updataLog.UpdataLogSaveCreate(gu, Mapper.Map <FaUserInfo>(userInfo));
                db.fa_user_info.Add(userInfo);
            }
            else
            {
                UpdataLog <FaUserInfo> updataLog = new UpdataLog <FaUserInfo>(db, Mapper.Map <FaUserInfo>(userInfo));
                userInfo = Fun.ClassToCopy <FA_USER_INFO, fa_user_info>(inEnt.entity, userInfo, allPar);
                //userInfo.UPDATE_TIME = DateTime.Now;
                userInfo.UPDATE_USER_ID   = gu.UserId;
                userInfo.UPDATE_USER_NAME = gu.UserName;
                updataLog.UpdataLogSaveUdate(gu, Mapper.Map <FaUserInfo>(userInfo));
            }
            return(Mapper.Map <FaUserInfo>(userInfo));
        }
Esempio n. 2
0
        public string UserInfoAddMultiSon(ref ErrorInfo err, ApiRequesSaveEntityBean <string> inEnt)
        {
            GlobalUser gu = Global.GetUser(inEnt.authToken);

            if (gu == null)
            {
                err.IsError = true;
                err.Message = "登录超时";
                return(null);
            }
            if (string.IsNullOrEmpty(inEnt.entity))
            {
                err.IsError = true;
                err.Message = "参数有误";
                return(null);
            }
            //调用用户保存
            using (DBEntities db = new DBEntities())
            {
                var allUserNameArr = inEnt.entity.Split(',').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();

                var parentUser = db.fa_user_info.SingleOrDefault(x => x.ID == inEnt.userId);
                if (parentUser == null)
                {
                    err.IsError = true;
                    err.Message = "当前用户不存在";
                    return(null);
                }
                if (string.IsNullOrEmpty(parentUser.fa_user.NAME))
                {
                    err.IsError = true;
                    err.Message = "当前用户不存在";
                    return(null);
                }
                var fristName = parentUser.fa_user.NAME.Substring(0, 1);

                foreach (var userName in allUserNameArr)
                {
                    TUser inUser = new TUser();
                    if (userName.Substring(0, 1).Equals(fristName))
                    {
                        inUser.NAME = userName;
                    }
                    else
                    {
                        inUser.NAME = string.Format("{0}{1}", fristName, userName);
                    }
                    inUser.DISTRICT_ID  = parentUser.fa_user.DISTRICT_ID;
                    inUser.RoleAllIDStr = string.Join(",", parentUser.fa_user.fa_role.Select(x => x.ID).ToList());
                    var user = api.UserApi.UserSave(db, inEnt.authToken, ref err, inUser, new List <string> {
                        "NAME", "DISTRICT_ID", "RoleAllIDStr"
                    });
                    if (err.IsError)
                    {
                        return(null);
                    }
                    var userInfo = db.fa_user_info.SingleOrDefault(x => x.ID == user.ID);
                    if (userInfo == null)
                    {
                        userInfo                  = new fa_user_info();
                        userInfo.ID               = user.ID;
                        userInfo.STATUS           = "正常";
                        userInfo.CREATE_TIME      = DateTime.Now;
                        userInfo.CREATE_USER_ID   = gu.UserId;
                        userInfo.CREATE_USER_NAME = gu.UserName;
                        userInfo.UPDATE_TIME      = DateTime.Now;
                        userInfo.UPDATE_USER_ID   = gu.UserId;
                        userInfo.UPDATE_USER_NAME = gu.UserName;

                        userInfo.FATHER_ID = parentUser.ID;
                        UpdataLog <FaUserInfo> updataLog = new UpdataLog <FaUserInfo>(db);
                        updataLog.UpdataLogSaveCreate(gu, Mapper.Map <FaUserInfo>(userInfo));
                        db.fa_user_info.Add(userInfo);
                    }
                }
                if (err.IsError)
                {
                    return(null);
                }
                Fun.DBEntitiesCommit(db, ref err);
                return(allUserNameArr.Count().ToString());
            }
        }