public async Task <Response> CreateResponseAsync() { try { var groupDto = await groupsService.CreateOrEditGroupAsync(GroupConverter.GetGroupDto(request.Group, clientConnection.UserId.GetValueOrDefault())).ConfigureAwait(false); return(new GroupsResponse(request.RequestId, GroupConverter.GetGroupVm(groupDto))); } catch (ObjectDoesNotExistsException ex) { Logger.WriteLog(ex); return(new ResultResponse(request.RequestId, "User not found.", ObjectsLibrary.Enums.ErrorCode.ObjectDoesNotExists)); } }
public async Task CreateOrEditGroup() { var user = fillTestDbHelper.Users.FirstOrDefault(); var exptectedGroup = new GroupDto { Title = "Group", PrivacySettings = int.MaxValue, UserId = user.Id, UsersId = user.Contacts.Select(opt => opt.UserId).Distinct().ToList() }; var actualGroup = await groupsService.CreateOrEditGroupAsync(exptectedGroup); Assert.True(exptectedGroup.PrivacySettings == actualGroup.PrivacySettings && exptectedGroup.Title == actualGroup.Title && exptectedGroup.UserId == actualGroup.UserId && exptectedGroup.UsersId.SequenceEqual(actualGroup.UsersId)); }
public async Task <bool> SaveUserDataAsync(UserDto userData) { try { UserDto user = await updateUsersService.CreateOrUpdateUserAsync(userData).ConfigureAwait(false); IEnumerable <ChatDto> chats = await createChatsService.CreateOrUpdateUserChatsAsync(userData.Chats).ConfigureAwait(false); IEnumerable <ChannelDto> channels = await createChannelsService.CreateOrUpdateUserChannelsAsync(userData.Channels).ConfigureAwait(false); foreach (var chat in userData.Chats) { await createMessagesService.SaveMessagesAsync(chat.Messages, user.Id).ConfigureAwait(false); } foreach (var channel in userData.Channels) { await createMessagesService.SaveMessagesAsync(channel.Messages, user.Id).ConfigureAwait(false); } foreach (var dialog in userData.Dialogs) { await createMessagesService.SaveMessagesAsync(dialog.Messages, user.Id).ConfigureAwait(false); } foreach (var contact in userData.Contacts) { await contactsService.CreateOrEditContactAsync(contact).ConfigureAwait(false); } foreach (var group in userData.ContactGroups) { await groupsService.CreateOrEditGroupAsync(group).ConfigureAwait(false); } await favoritesService.ChangeUserFavoritesAsync(userData.Favorites, userData.Id).ConfigureAwait(false); return(true); } catch (Exception ex) { Logger.WriteLog(ex); return(false); } }
public async Task ApplyPrivacySettingsGroupsAndContacts() { var user = fillTestDbHelper.Users.FirstOrDefault(); var firstUser = UserConverter.GetUserVm(fillTestDbHelper.Users.FirstOrDefault()); var secondUser = UserConverter.GetUserVm(fillTestDbHelper.Users.Skip(1).FirstOrDefault()); var thirdUser = UserConverter.GetUserVm(fillTestDbHelper.Users.Skip(2).FirstOrDefault()); var fourthUser = UserConverter.GetUserVm(fillTestDbHelper.Users.Skip(3).FirstOrDefault()); await contactsService.RemoveContactsAsync(user.Contacts.Select(opt => opt.ContactId).ToList(), user.Id); var secondContact = await contactsService.CreateOrEditContactAsync(new ContactDto { ContactUserId = secondUser.Id.Value, UserId = firstUser.Id.Value }); var thirdContact = await contactsService.CreateOrEditContactAsync(new ContactDto { ContactUserId = thirdUser.Id.Value, UserId = firstUser.Id.Value }); var group = await gropsService.CreateOrEditGroupAsync(new GroupDto { UserId = firstUser.Id.Value, UsersId = new List <long> { thirdContact.ContactUserId }, PrivacySettings = int.MaxValue }); firstUser.ContactsPrivacy[1] = true; var filteredBySecondUser = (await privacyService.ApplyPrivacySettingsAsync(new List <UserVm> { firstUser }, secondUser.Id)).FirstOrDefault(); Assert.True(filteredBySecondUser.NameFirst != null && filteredBySecondUser.NameSecond != null && filteredBySecondUser.Tag != null && filteredBySecondUser.About == null && filteredBySecondUser.Photo == null && filteredBySecondUser.Phones == null && filteredBySecondUser.Emails == null); var filteredByThirdUser = (await privacyService.ApplyPrivacySettingsAsync(new List <UserVm> { firstUser }, thirdUser.Id)).FirstOrDefault(); Assert.True(filteredByThirdUser.NameFirst != null && filteredByThirdUser.NameSecond != null && filteredByThirdUser.Tag != null && filteredByThirdUser.About != null && filteredByThirdUser.Photo != null && filteredByThirdUser.Phones != null && filteredByThirdUser.Emails != null); var filteredByFourthUser = (await privacyService.ApplyPrivacySettingsAsync(new List <UserVm> { firstUser }, fourthUser.Id)).FirstOrDefault(); Assert.True(filteredByFourthUser.NameFirst == null && filteredByFourthUser.NameSecond == null && filteredByFourthUser.Tag == null && filteredByFourthUser.About == null && filteredByFourthUser.Photo == null && filteredByFourthUser.Phones == null && filteredByFourthUser.Emails == null); }