/// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Add(Esmart_Sys_Department_User model)
        {
            var engine = PermissionDb.CreateEngine();

            engine.Esmart_Sys_Department_User.Add(model);
            engine.SaveChanges();
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = model.CreateId, CreateTime = model.CreateTime, EventType = "add", OprTbName = "Esmart_Sys_Department_User", OprUserId = model.CreateId, OptDescription = string.Format("用户:{0}添加了部门关系用户,用户ID:{1},部门ID:{2}", model.CreateId, model.UserId, model.DeparentId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(model)
            });
            CommonAction.ClearCache();
            return(true);
        }
Beispiel #2
0
        public int CreateUserWithDepartmentId(Esmart_Sys_Users user, int departMentId)
        {
            if (user.UserID == 0)
            {
                user.CreateTime = DateTime.Now;
                UserManagerDb.Add(user);
            }

            Esmart_Sys_Department_User departUser = new Esmart_Sys_Department_User
            {
                DeparentId = departMentId,
                UserId     = user.UserID,
                CreateTime = DateTime.Now,
                CreateId   = user.CreateId
            };

            DepartmentUserDbAction.Add(departUser);

            CommonAction.ClearCache(user.UserID);

            return(user.UserID);
        }
        public static int ChangeDepartmentOfUser(List <int> userIds, int newDepartmentId, int createId)
        {
            var engine = PermissionDb.CreateEngine();

            if (!engine.Esmart_Sys_Departments.Any(n => n.DeparentId == newDepartmentId))
            {
                throw new TpoBaseException("调入部门已不存在,请刷新后重试");
            }
            List <Esmart_Sys_Department_User> delDepartUser = new List <Esmart_Sys_Department_User>(), addDepartUser = new List <Esmart_Sys_Department_User>();

            foreach (var userId in userIds)
            {
                if (!engine.Esmart_Sys_Users.Any(n => n.UserID == userId))
                {
                    throw new TpoBaseException("用户已不存在,请刷新后重试");
                }

                var depUsers = engine.Esmart_Sys_Department_User.Where(n => n.UserId == userId).ToArray();
                engine.Esmart_Sys_Department_User.RemoveRange(depUsers);
                delDepartUser.AddRange(depUsers);
                var newModel = new Esmart_Sys_Department_User
                {
                    UserId     = userId,
                    DeparentId = newDepartmentId,
                    CreateId   = createId,
                    CreateTime = DateTime.Now
                };
                engine.Esmart_Sys_Department_User.Add(newModel);
                addDepartUser.Add(newModel);
            }
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = createId, CreateTime = DateTime.Now, EventType = "add&delete", OprTbName = "Esmart_Sys_Department_User", OprUserId = createId, OptDescription = string.Format("用户:{0}更新了部门用户关系,更新的用户ID:{1},原部门ID{2},新部门ID:{3}", createId, string.Join(",", userIds), string.Join(",", delDepartUser.Select(s => s.DeparentId)), string.Join(",", addDepartUser.Select(s => s.DeparentId))), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(delDepartUser) + ";" + Newtonsoft.Json.JsonConvert.SerializeObject(addDepartUser)
            });
            var result = engine.SaveChanges();

            CommonAction.ClearCache();
            return(result);
        }