Пример #1
0
        public async Task <ReporterOutput> AddReporter(ReporterAddInput input)
        {
            // 判断用户是否被占用
            var existUser = _userTbRepo.FirstOrDefault(u => u.Id == input.UserId);

            if (existUser == null || existUser.Enable == true)
            {
                throw new UserFriendlyException("用户不存在、或被占用");
            }

            var addReoirterObj = new ReporterInfoTb()
            {
                Address  = input.Address,
                AreaCode = input.AreaCode,
                Name     = input.Name,
                Phone    = input.Phone,
                User     = existUser,
                Age      = input.Age,
                Remark   = input.Remark,
                Type     = input.Type
            };

            var id = await _reporterInfoTbRepo.InsertAndGetIdAsync(addReoirterObj);

            addReoirterObj.Id = id;

            existUser.Enable = true;

            _userTbRepo.Update(existUser);

            return(addReoirterObj.MapTo <ReporterOutput>());
        }