Beispiel #1
0
        public async Task <ArticleViewModel> Get(ArticlePrimaryKey primaryKey, string viewerUserId = null)
        {
            var article = await(await _client.Article().FindAsync(x => x.Id == primaryKey.Id).CAF())
                          .FirstOrDefaultAsync().CAF();

            if (article is null)
            {
                return(null);
            }
            if ((!article.EverPublished || article.ForceFullyUnlisted || article.Draft) && article.AuthorId != viewerUserId)
            {
                return(null);
            }

            var author = await(await _client.User().FindAsync(x => x.Id == article.AuthorId).CAF())
                         .FirstOrDefaultAsync().CAF();
            var tags = (await(await _client.Tag().FindAsync(x => article.TagsIds.Contains(x.Id)).CAF()).ToListAsync()
                        .CAF());

            // TODO enable article series to bring articles in same series

            return(new ArticleViewModel(article, tags, author.Name, new ArticleSeriesArticles()));
        }
Beispiel #2
0
        private static async Task MigrateUsers(Data originalDbContext, IMongoClient targetMongoClient,
                                               ILogger logger)
        {
            logger.LogCritical("Starting the user collection");
            var userCollection = targetMongoClient.User();

            await originalDbContext.User.AsNoTracking().ForEachAsync(async(user) =>
            {
                var targetUser = await(await userCollection.FindAsync(x => x.Id == user.Id).CAF()).FirstOrDefaultAsync()
                                 .CAF();

                if (targetUser is null)
                {
                    await userCollection.InsertOneAsync(user).CAF();
                    logger.LogCritical("User with id: {id} was added to MongoDB", user.Id);
                }
                else
                {
                    logger.LogCritical("User with id: {id} already exists in MongoDB", user.Id);
                }
            }).CAF();

            logger.LogCritical("Finished the user collection");
        }
Beispiel #3
0
        public async Task <string> Add(RegisterViewModel registerViewModel)
        {
            // Allow OAuth users with same email to register if exists or vice versa
            string lowerCaseEmail = registerViewModel.Email.ToLowerInvariant();
            var    existingUser   =
                await(await _client.User().FindAsync(x => x.Email == lowerCaseEmail && !x.OAuthUser).CAF())
                .FirstOrDefaultAsync().CAF();

            if (existingUser?.Email == lowerCaseEmail)
            {
                throw new UserWithThisEmailAlreadyExistsException();
            }

            var user = _userFactory.Create(registerViewModel);

            user.Id = await GetIdUntilVacancyExists(user.Id).ConfigureAwait(false);

            await AddUser(user).ConfigureAwait(false);

            return(user.Id);
        }