示例#1
0
        public async Task <IActionResult> ApprovalApplyRequests([FromForm] int applierId)
        {
            var result = await _contactApplyRequestRepository.ApprovalAsync(UserIdentity.Id, applierId);

            if (!result)
            {
                //日志记录
                return(BadRequest());
            }

            //申请人的信息
            var applierMsg = await _userService.GetBaseUserinfo(applierId);

            //当前用户的信息
            var userMsg = await _userService.GetBaseUserinfo(UserIdentity.Id);

            //因为添加好友是双向的,各自的通讯录都有对方
            //往当前用户的MongoDB通讯录添加好友
            await _contactRepository.AddContactAsync(UserIdentity.Id, applierMsg);

            //往申请人的MongoDB通讯录添加好友
            await _contactRepository.AddContactAsync(applierMsg.Id, userMsg);

            return(Ok());
        }
示例#2
0
        public async Task <IActionResult> ApprovalApplyRequest(int applierId, CancellationToken cancellationToken)
        {
            //获取 当前上下文的用户  和申请人的  信息
            var user = await _userService.GetBaseUserInfoAsync(UserIdentity.UserId, cancellationToken);

            var applier = await _userService.GetBaseUserInfoAsync(applierId, cancellationToken);

            //当前上下文的用户id 添加好友
            await _contactRepository.AddContactAsync(user.UserId, new Dto.BaseUserInfo
            {
                Avatar  = applier.Avatar,
                Company = applier.Company,
                Name    = applier.Name,
                Title   = applier.Title,
                UserId  = applier.UserId
            }, cancellationToken);

            //对方好友也要添加当前用户作为好友
            await _contactRepository.AddContactAsync(applierId, new Dto.BaseUserInfo
            {
                Avatar  = user.Avatar,
                Company = user.Company,
                Name    = user.Name,
                Title   = user.Title,
                UserId  = user.UserId
            }, cancellationToken);

            var result = await _contactApplyRequestRepository.ApprovalAsync(UserIdentity.UserId, applierId, new CancellationToken());

            if (!result)
            {
                return(BadRequest());
            }
            return(Ok());
        }
示例#3
0
        public async Task <IActionResult> AddContactyAsync(ContactInputModel model)
        {
            if (string.IsNullOrEmpty(model.CompanyId))
            {
                return(BadRequest(ResponseResult.Failed(ErrorCode.ValidationError, "Company id can't be empty.")));
            }

            if (string.IsNullOrEmpty(model.Name))
            {
                return(BadRequest(ResponseResult.Failed(ErrorCode.ValidationError, "Contact name can't be empty.")));
            }

            var company = await _companyRepository.GetCompanyByIdAsync(model.CompanyId);

            if (company is null)
            {
                return(NotFound(ResponseResult.Failed(ErrorCode.Error, "Company not found")));
            }

            var contact = Contact.New(model.Name, company.Id);
            await _contactRepository.AddContactAsync(contact);

            company.AddContact(contact.Id);
            await _companyRepository.UpdateCompanyAsync(company);

            var result = Mapper.Map <ContactOutputModel>(contact);

            return(Ok(ResponseResult.SucceededWithData(result)));
        }
        async void Add_ReturnRightContact_WithExceptedParamerters()
        {
            var result = await contactRepository.AddContactAsync(1, new Contact.API.Dtos.BaseUserInfo {
                UserId = 3
            }, new System.Threading.CancellationToken());

            Assert.True(result);
        }
示例#5
0
        public async Task <IActionResult> ApplyUpdate(int applierId, CancellationToken cancellationToken)
        {
            var result = await _contactApplyRequestRepository.ApprovalAsync(UserIdentity.UserId, applierId, cancellationToken);

            if (!result)
            {
                return(BadRequest());
            }
            var applier = await _userService.GetBaseUserInfoAsync(applierId);

            var userinfo = await _userService.GetBaseUserInfoAsync(UserIdentity.UserId);

            await _contactRepository.AddContactAsync(UserIdentity.UserId, applier, cancellationToken);

            await _contactRepository.AddContactAsync(applierId, applier, cancellationToken);

            return(Ok());
        }
        public async Task <IActionResult> ApproalRequest(int applierId, CancellationToken cancellationToken)
        {
            var result = await _contactApplyRequestRepository.ApprovalAsync(UserIdentity.UserId, applierId, cancellationToken);

            if (!result)
            {
                _logger.LogWarning($"用户{UserIdentity.UserId} 通过好友-{applierId}-请求 失败");
                return(BadRequest());
            }

            var applierInfo = await _userService.GetUserInfoAsync(applierId);

            var userInfo = await _userService.GetUserInfoAsync(UserIdentity.UserId);

            await _contactRepository.AddContactAsync(applierId, userInfo, cancellationToken);

            await _contactRepository.AddContactAsync(UserIdentity.UserId, applierInfo, cancellationToken);

            return(Ok());
        }
示例#7
0
 public async Task <bool> AddContactAsync(Contact contact)
 {
     try
     {
         return(await _contactRepository.AddContactAsync(contact).ConfigureAwait(false));
     }
     catch (Exception ex)
     {
         Log.Information($"{nameof(ContactEngine)} - {nameof(AddContactAsync)}- Unable to save cantact- {ex.Message}");
         throw new Exception(ex.Message, ex);
     }
 }
        public async Task <IActionResult> ApprovalApplyRequest(int applierId, CancellationToken cancellationToken)
        {
            var result = await _contactApplyRequestRepository.ApprovalAsync(UserIdentity.UserId, applierId, cancellationToken);

            if (!result)
            {
                return(BadRequest());
            }
            //申请人用户信息
            var applierInfo = await _userService.GetBaseUserInfoAsync(applierId);

            //当前用户信息
            var userInfo = await _userService.GetBaseUserInfoAsync(UserIdentity.UserId);

            //添加好友为双向添加
            await _contactRepository.AddContactAsync(UserIdentity.UserId, applierInfo, cancellationToken);

            await _contactRepository.AddContactAsync(applierId, userInfo, cancellationToken);

            return(Ok());
        }
示例#9
0
        private async void AddContact()
        {
            var newContact = new Contact
            {
                Name         = "name",
                NxtAddressRs = "NXT-"
            };

            newContact = await _contactRepository.AddContactAsync(newContact);

            Contacts.Add(newContact);
            SelectedContact = newContact;
        }
示例#10
0
        public async Task <ResultHandler> AddContactAsync(ContactInfo contact)
        {
            try
            {
                await _contactRepository.AddContactAsync(contact);

                await _serviceStatus.CompleteAsync();

                return(new ResultHandler(contact));
            }
            catch (Exception ex)
            {
                return(new ResultHandler($"An error occurred when adding the contact: {ex.Message}"));
            }
        }
示例#11
0
 public async Task <ContactEntity> AddContactAsync(ContactEntity contact)
 {
     return(await _contactRepository.AddContactAsync(contact));
 }
示例#12
0
 public async Task <Contact> AddContactAsync(ContactDto contactDto)
 {
     return(await _contactRepository.AddContactAsync(contactDto));
 }