Beispiel #1
0
        public static UserVm GetUserVm(User user, long?userId = null)
        {
            if (user == null)
            {
                return(null);
            }
            var resultUser = new UserVm()
            {
                About            = user.About,
                Birthday         = user.Birthday,
                City             = user.City,
                NameFirst        = user.NameFirst,
                NameSecond       = user.NameSecond,
                Online           = user.Online.GetValueOrDefault(),
                Language         = user.Language,
                Country          = user.Country,
                Photo            = user.Photo,
                Id               = user.Id,
                RegistrationDate = user.RegistrationDate.GetValueOrDefault(),
                NodeId           = user.NodeId,
                Emails           = user.Emails?.Select(opt => opt.EmailAddress).ToList(),
                Phones           = user.Phones?.Select(opt => new UserPhoneVm
                {
                    FullNumber = opt.PhoneNumber,
                    UserId     = user.Id,
                    IsMain     = opt.Main
                }).ToList(),
                Tag       = user.Tag,
                Security  = user.Security,
                BlackList = user.BlackList?.Select(opt => opt.BadUid).ToList(),
                Visible   = new List <BitArray> {
                    new BitArray(BitConverter.GetBytes(user.Privacy))
                },
                Keys            = KeyConverter.GetKeysVm(user.UserPublicKeys),
                ContactsPrivacy = user.ContactsPrivacy != null
                    ? new BitArray(BitConverter.GetBytes(user.ContactsPrivacy.Value))
                    : null,
                Privacy      = new BitArray(BitConverter.GetBytes(user.Privacy)),
                Confirmed    = user.Confirmed.GetValueOrDefault(),
                Banned       = user.Banned,
                SyncContacts = user.SyncContacts
            };

            if (user.UserContacts != null && userId != null && user.UserContacts.Any())
            {
                var contactDto = ContactConverter.GetContactDto(user.UserContacts.FirstOrDefault());
                resultUser.Contact = ContactConverter.GetContactVm(contactDto);
            }
            if (userId != null && user.UserContacts != null && user.UserContacts.Any())
            {
                var groups = GroupConverter.GetGroupsDto(user.UserContacts.FirstOrDefault()?.ContactGroups?.Select(opt => opt.Group)?.ToList());
                resultUser.Groups = GroupConverter.GetGroupsVm(groups);
            }
            return(resultUser);
        }
        public static UserFavoritesVm GetUserFavoriteVm(UserFavoritesDto userFavorites, long userId)
        {
            if (userFavorites == null)
            {
                return(null);
            }

            return(new UserFavoritesVm
            {
                Channel = ChannelConverter.GetChannelVm(userFavorites.Channel, userId),
                ChannelId = userFavorites.ChannelId,
                Chat = ChatConverter.GetChatVm(userFavorites.Chat),
                ChatId = userFavorites.ChatId,
                Contact = ContactConverter.GetContactVm(userFavorites.Contact),
                ContactId = userFavorites.ContactId,
                SerialNumber = userFavorites.SerialNumber
            });
        }
        public static UserFavoritesDto GetUserFavoriteDto(UserFavorite userFavorites)
        {
            if (userFavorites == null)
            {
                return(null);
            }

            return(new UserFavoritesDto
            {
                Channel = ChannelConverter.GetChannelDto(userFavorites.Channel),
                ChannelId = userFavorites.ChannelId,
                Chat = ChatConverter.GetChatDto(userFavorites.Chat),
                ChatId = userFavorites.ChatId,
                Contact = ContactConverter.GetContactDto(userFavorites.Contact),
                ContactId = userFavorites.ContactId,
                SerialNumber = userFavorites.SerialNumber,
                UserId = userFavorites.UserId
            });
        }