Exemplo n.º 1
0
        public IActionResult AddPeople(AddPeopleDto addPeopleDto)
        {
            var adminUserBo = _boProvider.GetAdminUserBo();
            var result      = adminUserBo.AddPeople(addPeopleDto);

            if (addPeopleDto.PeopleIdNumber == "445121199510222688")
            {
                return(Ok(false));
            }
            return(Ok(result));
        }
        /// <summary>
        /// 校验peopledto合法性
        /// </summary>
        /// <param name="addPeopleDto"></param>
        internal object CheckPeopleDto(AddPeopleDto addPeopleDto)
        {
            if (_boProvider._context.Peoples.Any(m => m.NetName == addPeopleDto.NetName))
            {
                return(JsonConvert.SerializeObject(new ResultMsgDto()
                {
                    Code = 419, Msg = $"该用户名已存在"
                }));                                                                                    //throw ExceptionHelper.InvalidArgumentException("该用户名已存在");
            }
            var result = IDCardHelper.GetIsValid(addPeopleDto.PeopleIdNumber);

            if (result == false)
            {
                return(JsonConvert.SerializeObject(new ResultMsgDto()
                {
                    Code = 419, Msg = $"请输入合法的身份证"
                }));                                                                                      //throw ExceptionHelper.InvalidArgumentException($"请输入合法的身份证");
            }
            if (_boProvider._context.Peoples.Any(m => m.PeopleIdNumber == addPeopleDto.PeopleIdNumber))
            {
                return(JsonConvert.SerializeObject(new ResultMsgDto()
                {
                    Code = 419, Msg = $"该用户已经注册了"
                }));                                                                                     //throw ExceptionHelper.InvalidArgumentException($"该用户已经注册了");
            }
            try
            {
                var addr = new MailAddress(addPeopleDto.Email);
                //throw ExceptionHelper.InvalidArgumentException($"请输入正确的邮箱地址");
            }
            catch (Exception)
            {
                return(JsonConvert.SerializeObject(new ResultMsgDto()
                {
                    Code = 419, Msg = $"请输入正确的邮箱地址"
                }));
            }

            var sex = IDCardHelper.GetGenderStr(addPeopleDto.PeopleIdNumber);

            if (int.Parse(sex) % 2 == 0)
            {
                sex = "女";
            }
            else
            {
                sex = "男";
            }
            if (sex != addPeopleDto.Sex)
            {
                return(JsonConvert.SerializeObject(new ResultMsgDto()
                {
                    Code = 419, Msg = $"请输入正确的性别"
                }));                                                                                     //throw ExceptionHelper.InvalidArgumentException($"请输入正确的性别");
            }
            var people = _boProvider._mapper.Map <People>(addPeopleDto);

            _boProvider._peopleRepo.AddPeople(people);
            return(JsonConvert.SerializeObject(new ResultMsgDto()
            {
                Code = 200, Msg = $"正确"
            }));
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="addPeopleDto"></param>
        internal object AddPeople(AddPeopleDto addPeopleDto)
        {
            var result = CheckPeopleDto(addPeopleDto);

            return(result);
        }