Ejemplo n.º 1
0
 public Handler(IDbContextInjector dbContextInjector, IPasswordHasher passwordHasher, IJwtTokenGenerator jwtTokenGenerator, IMapper mapper)
 {
     _context           = dbContextInjector.ReadContext;
     _passwordHasher    = passwordHasher;
     _jwtTokenGenerator = jwtTokenGenerator;
     _mapper            = mapper;
 }
        public static void CleanUp(TasksBoardContext context)
        {
            var getTablesQuery =
                "SELECT table_name FROM information_schema.tables WHERE table_schema = " +
                $"'{TasksBoardContext.SCHEMA_NAME}';";

            var dbConnection = context.Database.GetDbConnection();

            var tableNames = dbConnection.Query <string>(getTablesQuery).ToList();

            foreach (var tableName in tableNames)
            {
                var query = $"ALTER TABLE \"{TasksBoardContext.SCHEMA_NAME}\".\"{tableName}\" DISABLE TRIGGER ALL;";
                dbConnection.Execute(query);
            }

            foreach (var tableName in tableNames)
            {
                var query = $"DELETE FROM \"{TasksBoardContext.SCHEMA_NAME}\".\"{tableName}\";";
                dbConnection.Execute(query);
            }

            foreach (var tableName in tableNames)
            {
                var query = $"ALTER TABLE \"{TasksBoardContext.SCHEMA_NAME}\".\"{tableName}\" ENABLE TRIGGER ALL;";
                dbConnection.Execute(query);
            }
        }
Ejemplo n.º 3
0
        public static async Task <Guid> CreateTask(TasksBoardContext context, Guid userId, Guid columnId,
                                                   string header             = "header",
                                                   string description        = "desc",
                                                   List <Guid> assignedUsers = null)
        {
            var task = new Backend.Domain.Task
            {
                ColumnId    = columnId,
                OwnerId     = userId,
                Header      = header,
                Description = description,
                OrderNum    = context.Tasks.Any() ? context.Tasks.Max(t => t.OrderNum) + 1 : default
            };

            await context.Tasks.AddAsync(task);

            await context.UserTasks.AddAsync(new UserTask { TaskId = task.Id, UserId = userId });

            assignedUsers?.ForEach(t => context.UserTasks.Add(new UserTask {
                TaskId = task.Id, UserId = t
            }));

            await context.SaveChangesAsync();

            return(task.Id);
        }
Ejemplo n.º 4
0
 public QueryHandler(IDbContextInjector dbContextInjector, ICurrentUserAccessor currentUserAccessor,
                     IMapper mapper)
 {
     _context             = dbContextInjector.ReadContext;
     _currentUserAccessor = currentUserAccessor;
     _mapper = mapper;
 }
Ejemplo n.º 5
0
 public Handler(IDbContextInjector dbContextInjector, IPasswordHasher passwordHasher,
                ICurrentUserAccessor currentUserAccessor, IMapper mapper)
 {
     _context             = dbContextInjector.WriteContext;
     _passwordHasher      = passwordHasher;
     _currentUserAccessor = currentUserAccessor;
     _mapper = mapper;
 }
        public static void Migrate(string connectionString)
        {
            var migrationOptions = new DbContextOptionsBuilder <TasksBoardContext>()
                                   .UseNpgsql(connectionString)
                                   .Options;

            using var migrationContext = new TasksBoardContext(migrationOptions);
            migrationContext.Database.Migrate();
        }
Ejemplo n.º 7
0
        public static async Task AddTasksTo(TasksBoardContext context, Guid columnId, IEnumerable <Guid> taskIds)
        {
            var column = await context.Columns.Include(t => t.Tasks).SingleOrDefaultAsync(t => t.Id == columnId);

            var tasks = context.Tasks.Where(t => taskIds.Contains(t.Id));

            await tasks.ForEachAsync(t => column.Tasks.Add(t));

            await context.SaveChangesAsync();
        }
Ejemplo n.º 8
0
        public static async Task <Guid> CreateBoard(TasksBoardContext context, Guid userId, string boardName = "board")
        {
            var board = new Board {
                Name = boardName, OwnerId = userId
            };
            await context.Boards.AddAsync(board);

            await context.SaveChangesAsync();

            return(board.Id);
        }
Ejemplo n.º 9
0
        public static async Task AssignUsers(TasksBoardContext context, Guid taskId, List <Guid> userIds)
        {
            var task = await context.Tasks.Include(t => t.AssignedUsers).FirstOrDefaultAsync(t => t.Id == taskId);

            var users = context.Users.Where(t => userIds.Contains(t.Id)).ToList();

            users.ForEach(t => task.AssignedUsers.Add(new UserTask {
                TaskId = taskId, UserId = t.Id
            }));
            await context.SaveChangesAsync();
        }
Ejemplo n.º 10
0
        public static async Task AddUserBoards(TasksBoardContext context, Guid boardId, IEnumerable <Guid> userIds)
        {
            var board = await context.Boards.Include(t => t.UserBoards).FirstOrDefaultAsync(t => t.Id == boardId);

            var users = context.Users.Where(t => userIds.Contains(t.Id)).ToList();

            users.ForEach(t => board.UserBoards.Add(new UserBoard()
            {
                BoardId = boardId, UserId = t.Id
            }));
            await context.SaveChangesAsync();
        }
Ejemplo n.º 11
0
        public static async Task <Guid> CreateColumn(TasksBoardContext context, Guid userId, Guid boardId,
                                                     string columnHeader = "header", string columnColor = "color")
        {
            var column = new Column
            {
                Header  = columnHeader,
                BoardId = boardId,
                OwnerId = userId,
                Color   = columnColor
            };

            await context.Columns.AddAsync(column);

            await context.SaveChangesAsync();

            return(column.Id);
        }
Ejemplo n.º 12
0
        public static async Task <Guid> CreateColumn(TasksBoardContext context, Guid userId, string boardName = "board",
                                                     string columnHeader = "column")
        {
            var board = new Board {
                Name = boardName, OwnerId = userId
            };
            await context.Boards.AddAsync(board);

            await context.SaveChangesAsync();

            var column = new Column {
                Header = columnHeader, BoardId = board.Id, OwnerId = userId
            };
            await context.Columns.AddAsync(column);

            await context.SaveChangesAsync();

            return(column.Id);
        }
Ejemplo n.º 13
0
        public static async Task <List <Column> > CreateColumns(TasksBoardContext context, Guid userId, Guid boardId, int columnsCount)
        {
            var columns = new List <Column>();

            for (int i = 0; i < columnsCount; i++)
            {
                columns.Add(new Column
                {
                    OwnerId = userId,
                    BoardId = boardId,
                    Header  = $"header{i}",
                });
            }

            await context.Columns.AddRangeAsync(columns);

            await context.SaveChangesAsync();

            return(columns.ToList());
        }
Ejemplo n.º 14
0
        public static async Task <List <Backend.Domain.Task> > CreateTasks(TasksBoardContext context, Guid userId, Guid columnId,
                                                                           int taskCount)
        {
            var tasks = new List <Backend.Domain.Task>();

            for (int i = 0; i < taskCount; i++)
            {
                tasks.Add(new Backend.Domain.Task
                {
                    ColumnId    = columnId,
                    OwnerId     = userId,
                    Header      = $"header{i}",
                    Description = $"description{i}"
                });
            }

            await context.Tasks.AddRangeAsync(tasks);

            await context.SaveChangesAsync();

            return(tasks.ToList());
        }
Ejemplo n.º 15
0
 public Handler(IDbContextInjector dbContextInjector)
 {
     _context = dbContextInjector.WriteContext;
 }
 public DbContextTransactionPipelineBehavior(IDbContextInjector injector)
 {
     _context = injector.WriteContext;
 }
Ejemplo n.º 17
0
 public Handler(IDbContextInjector dbContextInjector, ICurrentUserAccessor currentUserAccessor)
 {
     _currentUserAccessor = currentUserAccessor;
     _context             = dbContextInjector.WriteContext;
 }
Ejemplo n.º 18
0
 public QueryHandler(IDbContextInjector dbContextInjector, IJwtTokenGenerator jwtTokenGenerator, IMapper mapper)
 {
     _context           = dbContextInjector.ReadContext;
     _jwtTokenGenerator = jwtTokenGenerator;
     _mapper            = mapper;
 }
Ejemplo n.º 19
0
 public QueryHandler(IDbContextInjector dbContextInjector)
 {
     _context = dbContextInjector.ReadContext;
 }