Exemplo n.º 1
0
        public async Task <Card> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var assigmnemt = context.GetArgument <CardAssignment>();

            assigmnemt.CreatedAt = DateTime.UtcNow;

            var card = await databaseContext.Cards
                       .Include(x => x.Assignments)
                       .FirstOrDefaultAsync(x => x.Id == assigmnemt.CardId);

            var account = await databaseContext.Accounts
                          .FirstAsync(x => x.Id == assigmnemt.AccountId);

            await databaseContext.CardEvents.AddRangeAsync(card.Assignments
                                                           .Select(x => new CardEvent
            {
                Card      = card,
                AccountId = x.AccountId,
                CreatedAt = DateTime.UtcNow,
                Content   = $"'{account.FirstName} {account.LastName}' присоединился к карточке '{card.Name}'"
            }));

            await databaseContext.CardAssignments.AddAsync(assigmnemt);

            await databaseContext.SaveChangesAsync();

            return(await databaseContext.Cards.SingleAsync(x => x.Id == assigmnemt.CardId));
        }
Exemplo n.º 2
0
        public async Task <Card> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var cardLabel = context.GetArgument <CardLabel>();

            var card = await databaseContext.Cards
                       .Include(x => x.Assignments)
                       .FirstOrDefaultAsync(x => x.Id == cardLabel.CardId);

            var label = await databaseContext.Labels
                        .FirstAsync(x => x.Id == cardLabel.LabelId);

            await databaseContext.CardEvents.AddRangeAsync(card.Assignments
                                                           .Select(x => new CardEvent
            {
                Card      = card,
                AccountId = x.AccountId,
                CreatedAt = DateTime.UtcNow,
                Content   = $"К карточке '{card.Name}'' добавлена метка '{label.Name}'"
            }));

            await databaseContext.CardLabels.AddAsync(cardLabel);

            await databaseContext.SaveChangesAsync();

            return(await databaseContext.Cards.SingleAsync(x => x.Id == cardLabel.CardId));
        }
Exemplo n.º 3
0
        public async Task Validate(DocumentIOResolveFieldContext <object> context, IValidationContext validationContext)
        {
            var accountId = context.GetAccountId();
            var model     = context.GetArgument <Column>();

            var boardExists = await databaseContext
                              .Boards
                              .Where(x => x.Organization.Accounts.Any(account => account.Id == accountId))
                              .AnyAsync(x => x.Id == model.BoardId);

            validationContext.When(model, m => m.BoardId)
            .IsNot(() => boardExists)
            .AddValidationDetail("Доска не найдена");

            validationContext.When(model, m => m.Name)
            .IsNullOrWhitespace()
            .AddValidationDetail("Имя колонки не указано");

            if (validationContext.IsValid(model, m => m.Name))
            {
                var columnExists = await databaseContext
                                   .Columns
                                   .Where(x => x.Board.Organization.Accounts.Any(account => account.Id == accountId))
                                   .AnyAsync(x => x.Name == model.Name);

                validationContext.When(model, m => m.Name)
                .Is(() => columnExists)
                .AddValidationDetail("Колонка с таким именем уже сущетсвует");
            }
        }
Exemplo n.º 4
0
        public async Task Validate(DocumentIOResolveFieldContext <object> context, IValidationContext validationContext)
        {
            var model = context.GetArgument <Organization>();

            validationContext.When(model, m => m.Name)
            .IsNullOrWhitespace()
            .AddValidationDetail("Задайте имя организации");

            if (validationContext.IsValid(model, m => m.Name))
            {
                var organizationNameExists = await databaseContext
                                             .Organizations
                                             .AnyAsync(organization => organization.Name == model.Name);

                validationContext.When(model, m => m.Name)
                .Is(() => organizationNameExists)
                .AddValidationDetail("Имя организации уже используется");
            }

            validationContext.When(model, m => m.Accounts)
            .IsEmpty()
            .AddValidationDetail("Создайте хотя-бы один аккаунт");

            for (var index = 0; index < model.Accounts.Count; index++)
            {
                var account = model.Accounts[index];

                using (var scope = validationContext.CreateScope(model, m => m.Accounts[index]))
                {
                    await accountValidation.ValidateAccount(scope, account);
                }
            }
        }
Exemplo n.º 5
0
        public async Task <Card> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var card = context.GetArgument <Card>();

            var column = await databaseContext.Columns
                         .Include(x => x.Cards)
                         .SingleAsync(x => x.Id == card.ColumnId);

            card.Column    = column;
            card.Order     = column.Cards.Count + 1;
            card.CreatedAt = DateTime.UtcNow;

            await databaseContext.Cards.AddAsync(card);

            await databaseContext.CardAssignments
            .AddAsync(new CardAssignment
            {
                Card      = card,
                AccountId = context.GetAccountId()
            });

            await databaseContext.SaveChangesAsync();

            return(card);
        }
Exemplo n.º 6
0
        public async Task <IEnumerable <Search> > Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var accountId = context.GetAccountId();
            var filter    = context.GetFilter <SearchFilter>();

            var boards = await filter.Filtered(
                databaseContext.Boards.Where(x => x.Organization.Accounts.Any(account => account.Id == accountId)),
                x => x,
                search => search.CreatedAt)
                         .ToListAsync();

            var columns = await filter.Filtered(
                databaseContext.Columns.Where(x => x.Board.Organization.Accounts.Any(account => account.Id == accountId)),
                x => x,
                search => search.CreatedAt)
                          .ToListAsync();

            var cards = await filter.Filtered(
                databaseContext.Cards.Where(x =>
                                            x.Column.Board.Organization.Accounts.Any(account => account.Id == accountId)),
                x => x,
                search => search.CreatedAt)
                        .ToListAsync();

            return(boards.Concat(columns).Concat(cards));
        }
Exemplo n.º 7
0
        public async Task Validate(DocumentIOResolveFieldContext <object> context, IValidationContext validationContext)
        {
            var model = context.GetArgument <Account>();

            validationContext.When(model, m => m.Email)
            .IsNotEmail()
            .AddValidationDetail("Это не email =/");

            validationContext.When(model, m => m.Password)
            .IsNullOrWhitespace()
            .AddValidationDetail("Укажите ваш пароль");

            if (validationContext.IsValid(model, m => m.Email) && validationContext.IsValid(model, m => m.Password))
            {
                var account = await databaseContext
                              .Accounts
                              .FirstOrDefaultAsync(x => x.Email == model.Email);

                var accountExists = account != null &&
                                    passwordHasher.VerifyHashedPassword(
                    account,
                    account.Password,
                    model.Password) == PasswordVerificationResult.Success;

                validationContext.When()
                .IsNot(() => accountExists)
                .AddValidationDetail("Email/пароль неверный, либо аккаунт не существует");
            }
        }
Exemplo n.º 8
0
        public async Task <Label> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var model = context.GetArgument <Label>();

            var label = await databaseContext.Labels.SingleAsync(x => x.Id == model.Id);

            if (model.Name != null)
            {
                label.Name = model.Name;
            }

            if (model.Description != null)
            {
                label.Description = model.Description;
            }

            if (model.Color != null)
            {
                label.Color = model.Color;
            }

            await databaseContext.SaveChangesAsync();

            return(label);
        }
Exemplo n.º 9
0
        public Task Validate(DocumentIOResolveFieldContext <object> context, IValidationContext validationContext)
        {
            // TODO: Валидация
            // Проверить что у этой организации есть эта карточка и лейбл передан с той самой доски

            return(Task.CompletedTask);
        }
Exemplo n.º 10
0
        public async Task Validate(DocumentIOResolveFieldContext <object> context, IValidationContext validationContext)
        {
            var accountId = context.GetAccountId();
            var model     = context.GetArgument <Column>();

            var columnExists = await databaseContext
                               .Columns
                               .Include(x => x.Board)
                               .Where(x => x.Board.Organization.Accounts.Any(account => account.Id == accountId))
                               .AnyAsync(x => x.Id == model.Id);

            validationContext.When()
            .IsNot(() => columnExists)
            .AddValidationDetail("Колонка не существует");

            if (validationContext.IsValid())
            {
                var hasColumns = await databaseContext
                                 .Columns
                                 .Where(x => x.Id == model.Id)
                                 .Where(x => x.Cards.Any())
                                 .AnyAsync();

                validationContext.When()
                .Is(() => hasColumns)
                .AddValidationDetail("Колонка содержит карточки");
            }
        }
Exemplo n.º 11
0
        public async Task <CardComment> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var accountId = context.GetAccountId();
            var comment   = context.GetArgument <CardComment>();

            comment.AccountId = accountId;
            comment.CreatedAt = DateTime.UtcNow;

            var card = await databaseContext.Cards
                       .Include(x => x.Assignments)
                       .FirstOrDefaultAsync(x => x.Id == comment.CardId);

            await databaseContext.CardEvents.AddRangeAsync(card.Assignments
                                                           .Select(x => new CardEvent
            {
                Card      = card,
                AccountId = x.AccountId,
                CreatedAt = DateTime.UtcNow,
                Content   = $"К карточке '{card.Name}' добавлен комментарий"
            }));

            await databaseContext.CardComments.AddAsync(comment);

            await databaseContext.SaveChangesAsync();

            return(comment);
        }
Exemplo n.º 12
0
        public async Task <Organization> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var accountId = context.GetAccountId();

            return(await databaseContext.Organizations
                   .AsNoTracking()
                   .GetByAccountId(accountId));
        }
Exemplo n.º 13
0
        public Task Validate(DocumentIOResolveFieldContext <object> context, IValidationContext validationContext)
        {
            // TODO: Валидация
            // Проверить что у этой организации есть эта карточка и лейбл передан с той самой доски
            // Проверить что CardLabel с такими id уже есть (чтобы его можно было удалить)

            return(Task.CompletedTask);
        }
Exemplo n.º 14
0
        public async Task <Organization> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var organization = context.GetArgument <Organization>();

            foreach (var account in organization.Accounts)
            {
                var invite = new Invite
                {
                    Role         = Roles.Admin,
                    Secret       = Guid.NewGuid(),
                    CreatedAt    = DateTime.UtcNow,
                    Description  = "Создание организации",
                    Organization = organization,
                    Account      = account
                };

                account.Role      = invite.Role;
                account.CreatedAt = DateTime.UtcNow;
                account.Password  = passwordHasher.HashPassword(account, account.Password);

                await databaseContext.Invites.AddAsync(invite);
            }

            organization.Boards = new List <Board>
            {
                new Board
                {
                    Name      = "Ваша первая доска",
                    CreatedAt = DateTime.UtcNow,
                    Columns   = new List <Column>
                    {
                        new Column
                        {
                            Name      = "Ваша первая колонка",
                            Order     = 1,
                            CreatedAt = DateTime.UtcNow,
                            Cards     = new List <Card>
                            {
                                new Card
                                {
                                    Name      = "Ваша первая карточка",
                                    Order     = 1,
                                    Content   = "Ваша первая карточка",
                                    CreatedAt = DateTime.UtcNow
                                }
                            }
                        }
                    }
                }
            };

            await databaseContext.Organizations.AddAsync(organization);

            await databaseContext.SaveChangesAsync();

            return(organization);
        }
Exemplo n.º 15
0
        public Task Validate(DocumentIOResolveFieldContext <object> context, IValidationContext validationContext)
        {
            // TODO: Валидация
            // Доска существует
            // На доске еще нет такого лейбла
            // Описание либо null, либо не пустое
            // Цвет в формате #AABBCCDD

            return(Task.CompletedTask);
        }
Exemplo n.º 16
0
        public Task <Card> Resolve(DocumentIOResolveFieldContext <CardComment> context)
        {
            var loader = accessor.Context.GetOrAddBatchLoader <Guid, Card>(
                "CommentCard",
                async ids => await databaseContext.Cards.AsNoTracking()
                .Where(x => ids.Contains(x.Id))
                .ToDictionaryAsync(x => x.Id));

            return(loader.LoadAsync(context.Source.CardId));
        }
Exemplo n.º 17
0
        public Task Validate(DocumentIOResolveFieldContext <object> context, IValidationContext validationContext)
        {
            // TODO: Валидация
            // Карточка существует
            // Имя либо null, либо задано
            // Описание либо null, либо задано
            // Цвет либо null, либо задан #AABBCCDD

            return(Task.CompletedTask);
        }
Exemplo n.º 18
0
        public async Task <Label> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var label = context.GetArgument <Label>();

            await databaseContext.Labels.AddAsync(label);

            await databaseContext.SaveChangesAsync();

            return(label);
        }
Exemplo n.º 19
0
        public Task <Guid?> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var accountId = context.GetAccountId();

            var result = accountId == Guid.Empty
                                ? (Guid?)null
                                : accountId;

            return(Task.FromResult(result));
        }
Exemplo n.º 20
0
        public async Task <IEnumerable <Label> > Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var accountId = context.GetAccountId();
            var filter    = context.GetFilter <LabelsFilter>();

            return(await filter.Filtered(
                       databaseContext.Labels.AsNoTracking(),
                       labels => labels.Where(label => label.Board.Organization.Accounts.Any(account => account.Id == accountId)),
                       label => label.Id)
                   .ToListAsync());
        }
Exemplo n.º 21
0
        public Task <Account> Resolve(DocumentIOResolveFieldContext <CardAttachment> context)
        {
            var loader = accessor.Context.GetOrAddBatchLoader <Guid, Account>(
                "AttachmentAccount",
                async ids => await databaseContext.CardAttachments.AsNoTracking()
                .Include(assignment => assignment.Account)
                .Where(assignment => ids.Contains(assignment.AccountId))
                .ToDictionaryAsync(x => x.AccountId, x => x.Account));

            return(loader.LoadAsync(context.Source.AccountId));
        }
Exemplo n.º 22
0
        public async Task <CardAttachment> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var attachment = context.GetArgument <CardAttachment>();

            attachment.AccountId = context.GetAccountId();
            await databaseContext.CardAttachments.AddAsync(attachment);

            await databaseContext.SaveChangesAsync();

            return(attachment);
        }
Exemplo n.º 23
0
        public Task <int> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var accountId = context.GetAccountId();
            var filter    = context.GetFilter <BoardsFilter>();

            return(filter.Filtered(
                       databaseContext.Boards.AsNoTracking(),
                       boards => boards.Where(board => board.Organization.Accounts.Any(account => account.Id == accountId)),
                       board => board.CreatedAt)
                   .CountAsync());
        }
Exemplo n.º 24
0
        public Task <Organization> Resolve(DocumentIOResolveFieldContext <Board> context)
        {
            var loader = accessor.Context.GetOrAddBatchLoader <Guid, Organization>(
                "BoardOrganization",
                async ids => await databaseContext.Boards
                .AsNoTracking()
                .Include(board => board.Organization)
                .Where(board => ids.Contains(board.Id))
                .ToDictionaryAsync(board => board.Id, board => board.Organization));

            return(loader.LoadAsync(context.Source.Id));
        }
Exemplo n.º 25
0
        public async Task <IEnumerable <Account> > Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var accountId = context.GetAccountId();
            var filter    = context.GetFilter <AccountFilter>();

            return(await filter.Filtered(
                       databaseContext.Accounts.AsNoTracking(),
                       accounts => accounts.Where(
                           account => account.Organization.Accounts.Any(x => x.Id == accountId)),
                       account => account.CreatedAt)
                   .ToListAsync());
        }
Exemplo n.º 26
0
        public async Task <IEnumerable <Column> > Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var accountId = context.GetAccountId();
            var filter    = context.GetFilter <ColumnsFilter>();

            return(await filter.Filtered(
                       databaseContext.Columns.AsNoTracking(),
                       columns => columns.Where(column =>
                                                column.Board.Organization.Accounts.Any(account => account.Id == accountId)),
                       orderBy : column => column.Order)
                   .ToListAsync());
        }
Exemplo n.º 27
0
        public Task <Board> Resolve(DocumentIOResolveFieldContext <Column> context)
        {
            var loader = accessor.Context.GetOrAddBatchLoader <Guid, Board>(
                "ColumnBoard",
                async ids => await databaseContext.Columns
                .AsNoTracking()
                .Include(column => column.Board)
                .Where(column => ids.Contains(column.Id))
                .ToDictionaryAsync(column => column.Id, column => column.Board));

            return(loader.LoadAsync(context.Source.Id));
        }
Exemplo n.º 28
0
        public async Task <Column> Resolve(DocumentIOResolveFieldContext <object> context)
        {
            var model = context.GetArgument <Column>();

            var column = await databaseContext.Columns.SingleAsync(x => x.Id == model.Id);

            databaseContext.Columns.Remove(column);

            await databaseContext.SaveChangesAsync();

            return(column);
        }
Exemplo n.º 29
0
        public async Task Validate(DocumentIOResolveFieldContext <object> context, IValidationContext validationContext)
        {
            var accountId = context.GetAccountId();
            var model     = context.GetArgument <Card>();

            await ValidateColumnExists(validationContext, model, accountId);
            await ValidateCardName(validationContext, model, accountId);

            validationContext.When(model, m => m.Description)
            .IsNullOrWhitespace()
            .AddValidationDetail("Описание не задано");
        }
Exemplo n.º 30
0
        public Task <Board> Resolve(DocumentIOResolveFieldContext <Label> context)
        {
            var loader = accessor.Context.GetOrAddBatchLoader <Guid, Board>(
                "LabelBoard",
                async ids => await databaseContext.Labels
                .AsNoTracking()
                .Include(label => label.Board)
                .Where(label => ids.Contains(label.Id))
                .ToDictionaryAsync(label => label.Id, label => label.Board));

            return(loader.LoadAsync(context.Source.Id));
        }