Ejemplo n.º 1
0
        public ActionResult InserDepart()
        {
            var model = new DepartmentInput {
                TenantId = AbpSession.TenantId, IsUse = true
            };

            return(View("Easyman.FwWeb.Views.Admin.EditDepart", model));
        }
Ejemplo n.º 2
0
        public void SavePost(DepartmentInput input)
        {
            //var depart= Fun.ClassToCopy<DepartmentInput, Department>(input);
            //var depart = AutoMapper.Mapper.Map<Department>(input);
            var depart = _departmentManagerManager.GetDepartment(input.Id) ?? new Department();

            depart = Fun.ClassToCopy(input, depart, (new string[] { "Id" }).ToList());
            _departmentManagerManager.SaveOrUpdateDepartment(depart);
        }
        public bool AddDepartment(DepartmentInput departmentInput, out string message)
        {
            IQueryable <DepartmentInfo> departmentInfos = _dbContext.Set <DepartmentInfo>();
            DepartmentInfo department = departmentInfos.Where(d => d.DepartmentId == departmentInput.DepartmentId).FirstOrDefault();

            if (department == null)
            {
                DepartmentInfo department1 = departmentInfos.Where(d => d.DepartmentName == departmentInput.DepartmentName).FirstOrDefault(); //部门名是否已被使用
                if (department1 == null)
                {
                    DepartmentInfo info = departmentInfos.Where(d => d.LeaderId == departmentInput.LeaderId).FirstOrDefault(); //查询此人是否已是领导
                    if (info == null)
                    {
                        try
                        {
                            DepartmentInfo newDepartment = new DepartmentInfo
                            {
                                DepartmentId   = departmentInput.DepartmentId,
                                DepartmentName = departmentInput.DepartmentName,
                                LeaderId       = departmentInput.LeaderId,
                                ParentId       = departmentInput.ParentId,
                                Description    = departmentInput.Description,
                                AddTime        = DateTime.Now
                            };
                            _dbContext.Set <DepartmentInfo>().Add(newDepartment);
                            if (_dbContext.SaveChanges() > 0)
                            {
                                message = "添加成功!";
                                return(true);
                            }
                            else
                            {
                                message = "添加失败!内部出现异常!";
                                return(false);
                            }
                        }
                        catch (Exception ex)
                        {
                            message = ex.Message;
                            return(false);
                        }
                    }
                    message = "此人已是" + info.DepartmentName + "的领导!";
                    return(false);
                }
                message = "该部门名已被使用!";
                return(false);
            }
            message = "已存在该部门ID,请检查部门ID!";
            return(false);
        }
Ejemplo n.º 4
0
        // [AbpAuthorize(AppPermissions.Pages_Tenant_Geography_Department)]
        public ListResultDto <DepartmentListDto> GetDepartment(DepartmentInput input)
        {
            var dept = _departmentRepository
                       .GetAll();
            var query = dept
                        .WhereIf(
                !input.Filter.IsNullOrWhiteSpace(),
                u =>
                u.DepartmentCode.Contains(input.Filter) ||
                u.DepatmentName.Contains(input.Filter))
                        .ToList();

            return(new ListResultDto <DepartmentListDto>(query.MapTo <List <DepartmentListDto> >()));
        }
        public JsonResult AddDepartment(DepartmentInput departmentInput)
        {
            string message;
            //进行输入认证,是否输入的格式是对的。要求格式 D开头后接数字
            string str  = departmentInput.DepartmentId.Substring(0, 1); //获取第一个字符,验证是否为D开头
            string str1 = departmentInput.DepartmentId.Substring(1);

            if (str != "D")
            {
                message = "部门ID格式不正确!请以 D 开头,后续接数字!如:D1001 !!";
                return(Json(message));
            }
            _departmentManageService.AddDepartment(departmentInput, out message);
            return(Json(message));
        }
        /// <summary>
        /// 修改部门信息
        /// </summary>
        /// <param name="departmentInput">输入的信息</param>
        /// <param name="message">返回去的信息</param>
        /// <returns></returns>
        public bool UpdateDepartmentInfoById(DepartmentInput departmentInput, out string message)
        {
            IQueryable <DepartmentInfo> departmentInfos = _dbContext.Set <DepartmentInfo>();
            DepartmentInfo department = departmentInfos.Where(d => d.DepartmentId == departmentInput.DepartmentId).FirstOrDefault();//是否存在该部门

            if (department != null)
            {
                DepartmentInfo department1 = departmentInfos.Where(d => d.DepartmentName == departmentInput.DepartmentName).FirstOrDefault();
                if (department1 == null || department.DepartmentName == departmentInput.DepartmentName)
                {
                    DepartmentInfo info = departmentInfos.Where(l => l.LeaderId == departmentInput.LeaderId).FirstOrDefault(); //查询此人是否已是领导
                    if (info == null || info.LeaderId == department.LeaderId)
                    {
                        try
                        {
                            department.DepartmentName = departmentInput.DepartmentName;
                            department.Description    = departmentInput.Description;
                            department.LeaderId       = departmentInput.LeaderId;
                            department.ParentId       = departmentInput.ParentId;
                            _dbContext.Set <DepartmentInfo>().Update(department);
                            if (_dbContext.SaveChanges() > 0)
                            {
                                message = "修改成功!";
                                return(true);
                            }
                            message = "修改失败!内部出现异常!";
                            return(false);
                        }
                        catch (Exception ex)
                        {
                            message = ex.Message;
                            return(false);
                        }
                    }
                    message = "此人已是" + info.DepartmentName + "的领导!";
                    return(false);
                }
                message = "此部门名称已被使用!";
                return(false);
            }
            message = "内部错误!数据可能被篡改!";
            return(false);
        }
Ejemplo n.º 7
0
        public bool AddDepartment(DepartmentInput departmentInput, out string message)
        {
            IQueryable <RoleInfo>       roleInfos       = _dbContext.Set <RoleInfo>();
            IQueryable <RUserRoleInfo>  rUserRoleInfos  = _dbContext.Set <RUserRoleInfo>();
            IQueryable <DepartmentInfo> departmentInfos = _dbContext.Set <DepartmentInfo>();
            DepartmentInfo department = departmentInfos.Where(d => d.DepartmentId == departmentInput.DepartmentId).FirstOrDefault();

            if (department == null)
            {
                DepartmentInfo department1 = departmentInfos.Where(d => d.DepartmentName == departmentInput.DepartmentName).FirstOrDefault(); //部门名是否已被使用
                if (department1 == null)
                {
                    DepartmentInfo info = departmentInfos.Where(d => d.LeaderId == departmentInput.LeaderId).FirstOrDefault(); //查询此人是否已是领导
                    if (info == null)
                    {
                        try
                        {
                            DepartmentInfo newDepartment = new DepartmentInfo
                            {
                                DepartmentId   = departmentInput.DepartmentId,
                                DepartmentName = departmentInput.DepartmentName,
                                LeaderId       = departmentInput.LeaderId,
                                ParentId       = departmentInput.ParentId,
                                Description    = departmentInput.Description,
                                AddTime        = DateTime.Now
                            };

                            //将该用户的角色添加多一条为部门领导
                            RUserRoleInfo rUserRole = new RUserRoleInfo
                            {
                                UserId = departmentInput.LeaderId,
                                RoleId = roleInfos.Where(r => r.RoleName.Contains("部门领导")).FirstOrDefault().RoleId
                            };
                            _dbContext.Set <RUserRoleInfo>().Add(rUserRole);
                            _dbContext.Set <DepartmentInfo>().Add(newDepartment);
                            if (_dbContext.SaveChanges() > 0)
                            {
                                message = "添加成功!";
                                return(true);
                            }
                            else
                            {
                                message = "添加失败!内部出现异常!";
                                return(false);
                            }
                        }
                        catch (Exception ex)
                        {
                            message = "错误信息为:" + ex.Message;
                            if (ex.InnerException != null)
                            {
                                message += "详细错误信息:" + ex.InnerException.Message;
                            }
                            return(false);
                        }
                    }
                    message = "此人已是" + info.DepartmentName + "的领导!";
                    return(false);
                }
                message = "该部门名已被使用!";
                return(false);
            }
            message = "已存在该部门ID,请检查部门ID!";
            return(false);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 修改部门信息
        /// </summary>
        /// <param name="departmentInput">输入的信息</param>
        /// <param name="message">返回去的信息</param>
        /// <returns></returns>
        public bool UpdateDepartmentInfoById(DepartmentInput departmentInput, out string message)
        {
            IQueryable <RoleInfo>       roleInfos       = _dbContext.Set <RoleInfo>();
            IQueryable <RUserRoleInfo>  rUserRoleInfos  = _dbContext.Set <RUserRoleInfo>();
            IQueryable <DepartmentInfo> departmentInfos = _dbContext.Set <DepartmentInfo>();
            DepartmentInfo department = departmentInfos.Where(d => d.DepartmentId == departmentInput.DepartmentId).FirstOrDefault();//是否存在该部门

            if (department != null)
            {
                DepartmentInfo department1 = departmentInfos.Where(d => d.DepartmentName == departmentInput.DepartmentName).FirstOrDefault();
                if (department1 == null || department.DepartmentName == departmentInput.DepartmentName)
                {
                    DepartmentInfo info = departmentInfos.Where(l => l.LeaderId == departmentInput.LeaderId).FirstOrDefault(); //查询此人是否已是领导
                    if (info == null || info.LeaderId == department.LeaderId)
                    {
                        try
                        {
                            //获取部门领导这个角色的ID
                            string roleId = roleInfos.Where(r => r.RoleName.Contains("部门领导")).FirstOrDefault().RoleId;
                            //先移除原用户在该部门的领导角色
                            //找到这个人的部门领导角色的数据
                            RUserRoleInfo rUserRoleInfo = rUserRoleInfos.Where(r => r.UserId == department.LeaderId && r.RoleId == roleId).FirstOrDefault();
                            //如果该部门的原部门领导在角色信息表有部门领导角色,则删除,没有就证明是数据库手动添加的。直接跳过删除,直接赋值
                            if (rUserRoleInfo != null)
                            {
                                //挂起删除该条数据
                                _dbContext.Set <RUserRoleInfo>().Remove(rUserRoleInfo);
                            }


                            department.DepartmentName = departmentInput.DepartmentName;
                            department.Description    = departmentInput.Description;
                            department.LeaderId       = departmentInput.LeaderId;
                            department.ParentId       = departmentInput.ParentId;
                            _dbContext.Set <DepartmentInfo>().Update(department);

                            //为新的领导人配置角色权限
                            RUserRoleInfo newUserRoleInfo = new RUserRoleInfo
                            {
                                UserId = departmentInput.LeaderId,
                                RoleId = roleId
                            };

                            _dbContext.Set <RUserRoleInfo>().Add(newUserRoleInfo);

                            if (_dbContext.SaveChanges() > 0)
                            {
                                message = "修改成功!";
                                return(true);
                            }
                            message = "修改失败!内部出现异常!";
                            return(false);
                        }
                        catch (Exception ex)
                        {
                            message = ex.Message;
                            return(false);
                        }
                    }
                    message = "此人已是" + info.DepartmentName + "的领导!";
                    return(false);
                }
                message = "此部门名称已被使用!";
                return(false);
            }
            message = "内部错误!数据可能被篡改!";
            return(false);
        }