Esempio n. 1
0
        public async Task UpdateObjective(long objectiveId, long operationId, bool solved, CancellationToken token)
        {
            var obj = await Context.Objectives
                      .Where(obj => obj.Id == objectiveId)
                      .SingleAsync(token);

            obj.Solved = solved;
            await Context.SaveChangesAsync(token);

            await OperationsChannel.Publish(operationId, Settings.Value.RedisConfiguration);
        }
Esempio n. 2
0
        public async Task CreateOperation(string name, CancellationToken token)
        {
            Logger.LogDebug($"CreateOperation({name})");
            var newOp = new Operation()
            {
                Name = name
            };

            Context.Operations.Add(newOp);
            await Context.SaveChangesAsync(token);

            await OperationsChannel.Publish(newOp.Id, Settings.Value.RedisConfiguration);
        }
Esempio n. 3
0
        public async Task CreateObjective(string name, string category, long points, long operationId, CancellationToken token)
        {
            Logger.LogDebug($"CreateObjective({name}, {category}, {points}, {operationId})");
            Context.Objectives
            .Add(new Objective()
            {
                Name        = name,
                Category    = category,
                Points      = points,
                OperationId = operationId,
                Visible     = true
            });
            await Context.SaveChangesAsync(token);

            await OperationsChannel.Publish(operationId, Settings.Value.RedisConfiguration);
        }
Esempio n. 4
0
        public async Task AddFiles(ICollection <IFormFile> files, long id, bool isObjectiveFile, string username, CancellationToken token)
        {
            long operationId;
            List <UploadedFile> dbFiles;

            if (isObjectiveFile)
            {
                var objective = await Context.Objectives
                                .Where(o => o.Id == id)
                                .Include(o => o.Files)
                                .SingleAsync(token);

                operationId = objective.OperationId;
                dbFiles     = objective.Files;
            }
            else
            {
                var operation = await Context.Operations
                                .Where(o => o.Id == id)
                                .Include(o => o.Files)
                                .SingleAsync(token);

                operationId = id;
                dbFiles     = operation.Files;
            }

            foreach (var formFile in files)
            {
                var uf = new UploadedFile()
                {
                    Filename  = formFile.FileName,
                    Username  = username,
                    Timestamp = DateTime.UtcNow
                };
                dbFiles.Add(uf);
                await Context.SaveChangesAsync(token);

                var filePath = $"./Uploads/{uf.Id}";
                using var stream = new FileStream(filePath, FileMode.Create);
                await formFile.CopyToAsync(stream, token);
            }
            await OperationsChannel.Publish(operationId, Settings.Value.RedisConfiguration);
        }