public async Task <ResponseMessage> PlusOranizatin([FromBody] OranizationRequest oranization)
        {
            var users = DataBaseUser.TokenModel;

            _Logger.LogInformation($"用户{users?.UserName ?? ""},其ID:({users?.Id ?? ""}) 获取权限列表:\r\n" + (oranization != null ? JsonHelpers.ToJSON(oranization) : ""));
            var response = new ResponseMessage();

            if (oranization == null)
            {
                _Logger.LogInformation($"用户:{users.UserName}获取权限列表,请求的参数为空。");
                response.Code    = ResponseCodeDefines.NotAllow;
                response.Message = "添加组织时,请求参数为空";
            }
            try
            {
                response = await _OranizationManager.PlusOranization(oranization);
            }
            catch (Exception el)
            {
                _Logger.LogError($"用户{users?.UserName ?? ""}({users?.Id ?? ""})添加组织报错:\r\n{el.ToString()}");
                response.Code    = ResponseCodeDefines.ArgumentNullError;
                response.Message = $"添加组织报错:{el.Message}";
            }
            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// 添加组织信息
        /// </summary>
        /// <param name="oranizationRequest"></param>
        /// <returns></returns>
        public async Task <ResponseMessage> PlusOranization(OranizationRequest oranizationRequest)
        {
            var response = new ResponseMessage();

            var newOranization = _Mapper.Map <Organizations>(oranizationRequest);

            try
            {
                //修改
                if (oranizationRequest.id != string.Empty)
                {
                    var oran = await _IOranizationStore.GettingOraniztions().AsNoTracking().Where(u => u.Id.Equals(oranizationRequest.id)).SingleOrDefaultAsync();

                    oran.OrganizationName = newOranization.OrganizationName;
                    oran.Phone            = newOranization.Phone;
                    await _IOranizationStore.EditOrganization(oran);

                    return(response);
                }

                //添加
                var oranizationid = Guid.NewGuid().ToString();
                newOranization.Id = oranizationid;
                newOranization.OrganizationName = newOranization.OrganizationName;
                newOranization.Phone            = newOranization.Phone;
                newOranization.ParentId         = newOranization.ParentId;
                newOranization.CreateTime       = DateTime.Now;
                await _IOranizationStore.AddOraniztions(newOranization);

                List <OrganizationExpansions> organizationExpansions = new List <OrganizationExpansions>()
                {
                };


                //递归找到所有的父级节点信息
                var parentList = await ListPrantOranization(new List <Organizations>(), oranizationRequest.ParentId, oranizationRequest.OrganizationName);

                foreach (var item in parentList)
                {
                    organizationExpansions.Add(new OrganizationExpansions
                    {
                        OrganizationId   = item.Id,       // 父节点ID
                        OrganizationName = item.OrganizationName,
                        SonId            = oranizationid, // 子节点ID
                        FullName         = item.FullName,
                        SonName          = oranizationRequest.OrganizationName,
                        //对比父级ID是否相同,相同则是直属关系
                        IsImmediate = item.Id == oranizationRequest.ParentId
                    });
                }
                await _IOranizationStore.AddOrganizationExpansions(organizationExpansions);
            }
            catch (Exception el)
            {
                throw new Exception(el.Message);
            }
            return(response);
        }