Пример #1
0
        public async Task <Response> CreateResponseAsync()
        {
            var userFavorites = await favoritesService.ChangeUserFavoritesAsync(
                UserFavoritesConverter.GetUserFavoritesDtos(request.Favorites, clientConnection.UserId.Value), clientConnection.UserId.Value).ConfigureAwait(false);

            return(new FavoritesResponse(request.RequestId, UserFavoritesConverter.GetUserFavoritesVms(userFavorites, clientConnection.UserId.Value)));
        }
Пример #2
0
        public async Task ChangeUserFavorites()
        {
            var user          = fillTestDbHelper.Users.FirstOrDefault();
            var chat          = fillTestDbHelper.Chats.FirstOrDefault(opt => opt.ChatUsers.Any(p => p.UserId == user.Id));
            var channel       = fillTestDbHelper.Channels.FirstOrDefault(opt => opt.ChannelUsers.Any(p => p.UserId == user.Id));
            var userFavorites = new List <UserFavoritesDto>
            {
                new UserFavoritesDto
                {
                    ChannelId = channel.ChannelId
                },
                new UserFavoritesDto
                {
                    ChatId = chat.Id
                },
                new UserFavoritesDto
                {
                    ContactId = user.Contacts.FirstOrDefault().ContactId
                }
            };
            var actualFavorites = await favoritesService.ChangeUserFavoritesAsync(userFavorites, user.Id);

            Assert.True(userFavorites.All(opt => actualFavorites.Any(p => p.ContactId == opt.ContactId) ||
                                          actualFavorites.Any(p => p.ChatId == opt.ChatId) ||
                                          actualFavorites.Any(p => p.ChannelId == opt.ChannelId)));
        }
        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);
            }
        }