/// <summary> /// Insert contact. /// </summary> /// <param name="contact">Contact to be inserted</param> public int InsertContact(ContactBO contact) { ValideContactData(contact); var contactDO = ContactConverter.FromBOToDO(contact); var contactId = ContactInformationDataManager.InsertContact(contactDO); return(contactId); }
public async Task GetGroupContacts() { var user = fillTestDbHelper.Users.FirstOrDefault(opt => opt.Groups.Any()); var group = fillTestDbHelper.Groups.FirstOrDefault(opt => opt.UserId == user.Id); var expectedContacts = ContactConverter.GetContactsDto(group.ContactGroups.Select(opt => opt.Contact).ToList()); var actualContacts = await groupsService.GetGroupContactsAsync(group.GroupId, user.Id); Assert.Equal(expectedContacts.Select(opt => opt.ContactId), actualContacts.Select(opt => opt.ContactId)); }
/// <summary> /// Update contact /// </summary> /// <param name="contact">Contact to be updated</param> public void UpdateContact(ContactBO contact) { if (!ContactExists(contact.Id)) { throw new ContactNotFoundException(); } ValideContactData(contact); var contactDO = ContactConverter.FromBOToDO(contact); ContactInformationDataManager.UpdateContact(contactDO); }
public void ConvertJsonItem_SetupJsonWithNullValues_VerifyContact() { // Arrange var json = SfContactJsonWithNullValues; var converter = new ContactConverter(); var expected = SfContactListWithNullValues.First(); // Act var result = converter.Convert <SF_Contact>(json).FirstOrDefault(); // Assert result.ShouldSatisfyAllConditions( () => result.ShouldNotBeNull(), () => result.IsContentMatched(expected)); }
public async Task <Response> CreateResponseAsync() { try { ContactDto resultContact = await contactsService.CreateOrEditContactAsync( ContactConverter.GetContactDto(request.Contact, clientConnection.UserId.GetValueOrDefault())).ConfigureAwait(false); return(new ContactsResponse(request.RequestId, ContactConverter.GetContactVm(resultContact))); } catch (ObjectDoesNotExistsException ex) { Logger.WriteLog(ex); return(new ResultResponse(request.RequestId, "User not found.", ObjectsLibrary.Enums.ErrorCode.ObjectDoesNotExists)); } }
public async Task <List <ContactDto> > GetUsersContactsAsync(long userId, List <long> usersId) { using (MessengerDbContext context = contextFactory.Create()) { var contactsCondition = PredicateBuilder.New <Contact>(); contactsCondition = usersId.Aggregate(contactsCondition, (current, value) => current.Or(opt => opt.UserId == value).Expand()); var contacts = await context.Contacts .Include(opt => opt.ContactGroups) .Where(opt => opt.ContactUserId == userId) .Where(contactsCondition) .ToListAsync().ConfigureAwait(false); return(ContactConverter.GetContactsDto(contacts)); } }
public async Task <ContactDto> CreateOrEditContactAsync(ContactDto contactDto) { try { using (MessengerDbContext context = contextFactory.Create()) { Contact result; var contact = await context.Contacts .Include(opt => opt.ContactGroups) .FirstOrDefaultAsync(opt => opt.UserId == contactDto.UserId && opt.ContactUserId == contactDto.ContactUserId) .ConfigureAwait(false); if (contact == null) { Contact newContact = new Contact { Name = contactDto.Name, UserId = contactDto.UserId, ContactUserId = contactDto.ContactUserId, ContactId = contactDto.ContactId }; await context.Contacts.AddAsync(newContact).ConfigureAwait(false); result = newContact; } else { contact.Name = contactDto.Name; context.Update(contact); result = contact; } await context.SaveChangesAsync().ConfigureAwait(false); return(ContactConverter.GetContactDto(result)); } } catch (PostgresException ex) { if (ex.SqlState == "23503") { throw new ObjectDoesNotExistsException("User not found.", ex); } throw new InternalErrorException("Database error.", ex); } }
public async Task <List <ContactDto> > GetGroupContactsAsync(Guid groupId, long userId, long?navigationUserId = 0) { using (MessengerDbContext context = contextFactory.Create()) { var contacts = await context.ContactsGroups .Include(opt => opt.Contact) .OrderBy(opt => opt.Contact.ContactUserId) .Where(opt => opt.GroupId == groupId && opt.Contact.ContactUserId > navigationUserId && opt.Contact.UserId == userId) .Select(opt => opt.Contact) .Include(opt => opt.ContactUser) .Include(opt => opt.ContactGroups) .ThenInclude(opt => opt.Group) .ToListAsync() .ConfigureAwait(false); return(ContactConverter.GetContactsDto(contacts)); } }
public async Task <List <ContactDto> > GetUserContactsAsync(long userId, long navigationUserId = 0, byte?limit = null) { using (MessengerDbContext context = contextFactory.Create()) { var query = context.Contacts .OrderBy(opt => opt.ContactUserId) .Include(opt => opt.ContactUser) .Include(opt => opt.ContactGroups) .Where(opt => opt.UserId == userId && opt.ContactUserId > navigationUserId); if (limit != null) { query = query.Take(limit.Value); } var contacts = await query.ToListAsync().ConfigureAwait(false); return(ContactConverter.GetContactsDto(contacts)); } }
public async Task <Response> CreateResponseAsync() { List <ContactDto> contactsDto = await groupsService.GetGroupContactsAsync( request.GroupId, clientConnection.UserId.GetValueOrDefault(), request.NavigationUserId.GetValueOrDefault()).ConfigureAwait(false); List <ContactVm> contactsVm = ContactConverter.GetContactsVm(contactsDto); IEnumerable <IGrouping <long, UserDto> > groupedUsers = contactsDto.Select(opt => opt.ContactUser).GroupBy(opt => opt.NodeId.GetValueOrDefault()); ConcurrentBag <UserVm> resultUsers = new ConcurrentBag <UserVm>(); List <Task> getUsersTasks = new List <Task>(); foreach (var group in groupedUsers) { getUsersTasks.Add(Task.Run(async() => { var nodeConnection = connectionsService.GetNodeConnection(group.Key); if (group.Key != NodeSettings.Configs.Node.Id && nodeConnection != null) { await MetricsHelper.Instance.SetCrossNodeApiInvolvedAsync(request.RequestId).ConfigureAwait(false); var users = await nodeRequestSender.GetUsersInfoAsync( group.Select(opt => opt.Id).ToList(), clientConnection.UserId, nodeConnection).ConfigureAwait(false); resultUsers.AddRange(users); resultUsers.AddRange(users); } else { resultUsers.AddRange(UserConverter.GetUsersVm(group.ToList(), clientConnection.UserId)); } })); } await Task.WhenAll(getUsersTasks).ConfigureAwait(false); foreach (var contact in contactsVm) { contact.ContactUser = resultUsers.FirstOrDefault(opt => opt.Id == contact.ContactUserId); } return(new ContactsResponse(request.RequestId, contactsVm)); }
public async Task <TeamSignUpFormViewModel> AddTeamSignUpFormAsync(TeamSignUpFormViewModel newTeamViewModel, CancellationToken ct = default(CancellationToken)) { TeamSignUpForm newTeamForm = new TeamSignUpForm() { Name = newTeamViewModel.Name }; newTeamForm = await this._teamSignUpRepository.AddSignUpFormAsync(newTeamForm); newTeamViewModel.Id = newTeamForm.Id; Contact teamContact = new Contact() { FirstName = newTeamViewModel.Contact.FirstName, LastName = newTeamViewModel.Contact.LastName, Email = newTeamViewModel.Contact.Email, PhoneNumber = newTeamViewModel.Contact.PhoneNumber, TeamSignUpFormId = newTeamViewModel.Id }; newTeamViewModel.Contact = ContactConverter.Convert(await this._teamSignUpRepository.AddTeamContactAsync(teamContact, ct)); return(newTeamViewModel); }
/// <summary> /// Get Contact information for a single contact /// </summary> /// <param name="Id">Id of the contact to be retrived</param> /// <returns></returns> public ContactBO GetContactById(int Id) { var contact = ContactInformationDataManager.GetContactById(Id); return(ContactConverter.FromDOToBO(contact)); }
/// <summary> /// Get all contacts in the system /// </summary> /// <returns></returns> public List <ContactBO> GetAllContacts() { var contacts = ContactInformationDataManager.GetAllContacts(); return(ContactConverter.FromDOToBOList(contacts)); }