public void Init(long[] entitiesIds)
        {
            var socialUserInfos = _userService.GetUsers(entitiesIds);

            if (socialUserInfos.IsNullOrEmpty())
            {
                return;
            }

            var entities = _entitiesRepository.GetEntitiesByIds(socialUserInfos.Select(x => x.id).ToArray())
                           .ToArray();

            var initilizers = socialUserInfos.Except(socialUserInfos.Join(entities, z => z.id, e => e.OriginalId, (z, e) => z));

            // TODO: we need to find a way to do this in one batch
            foreach (var entity in initilizers)
            {
                _entitiesRepository.Update(new Entity {
                    Id            = ObjectId.GenerateNewId(),
                    OriginalId    = entity.id,
                    Name          = entity.name,
                    ImageUrl      = entity.imageUrl,
                    OriginalEmail = entity.email
                });
            }
        }
        public void Resolve(IList <Entity> unresolvedEntities)
        {
            var ids = unresolvedEntities.Select(e => e.Id).ToArray();

            var resolvedEntities = _entitiesRepository.GetEntitiesByIds(ids)
                                   .Where(e => e != null);

            unresolvedEntities.JoinDo(resolvedEntities, u => u.Id, r => r.Id, (u, r) =>
            {
                u.OriginalId    = r.OriginalId;
                u.ImageUrl      = r.ImageUrl;
                u.Name          = r.Name;
                u.OriginalEmail = r.OriginalEmail;
                u.Email         = r.Email;
            });
        }
Example #3
0
        public Entity GetEntityFromPlatform()
        {
            var originalEntity = _userService.CurrentUser();

            if (originalEntity == null)
            {
                return(null);
            }

            var entity = _entitiesRepository.GetEntitiesByIds(new[] { originalEntity.id }).FirstOrDefault();

            if (entity != null)
            {
                entity.ImageUrl      = originalEntity.imageUrl;
                entity.Name          = originalEntity.name;
                entity.OriginalEmail = entity.OriginalEmail;
                entity.LastActivity  = SystemTime.Now();

                _entitiesRepository.Update(entity);

                return(entity);
            }

            entity = new Entity
            {
                Id            = ObjectId.GenerateNewId(),
                OriginalId    = originalEntity.id,
                Name          = originalEntity.name,
                ImageUrl      = originalEntity.imageUrl,
                OriginalEmail = originalEntity.email,
                LastActivity  = SystemTime.Now(),
                MemberSince   = SystemTime.Now()
            };

            _entitiesRepository.Add(entity);

            return(entity);
        }
 public static Entity Get(this IEntitiesRepository entitiesRepository, ObjectId id)
 {
     return(entitiesRepository.GetEntitiesByIds(new[] { id }).EmptyIfNull().FirstOrDefault());
 }
 public static Entity Get(this IEntitiesRepository entitiesRepository, long originalId)
 {
     return(entitiesRepository.GetEntitiesByIds(new[] { originalId }).EmptyIfNull().FirstOrDefault());
 }