Exemplo n.º 1
0
        public async Task CreateResource(RkResource resource)
        {
            await VerifyProjectExists(resource.ProjectId);
            await VerifyProjectAccess(resource.ProjectId);

            resource.NormalizedName = resource.Name.ToLowerInvariant();
            var existsResource = await dbContext.RkResources.FirstOrDefaultAsync(r => r.ProjectId == resource.ProjectId && r.NormalizedName == resource.NormalizedName);

            if (existsResource != null)
            {
                throw new ApplicationException($"Resource with name [{resource.Name}] already exists");
            }

            await dbContext.RkResources.AddAsync(resource);

            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task CreateProduct(RkProduct product)
        {
            await VerifyProjectExists(product.ProjectId);
            await VerifyProjectAccess(product.ProjectId);

            product.NormalizedName = product.Name.ToLowerInvariant();
            var existsProduct = await dbContext.RkProducts.FirstOrDefaultAsync(r => r.ProjectId == product.ProjectId && r.NormalizedName == product.NormalizedName);

            if (existsProduct != null)
            {
                throw new ApplicationException($"Product with name [{product.Name}] already exists");
            }

            await dbContext.RkProducts.AddAsync(product);

            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task MarkExperimentAsProcessed(Guid experimentId)
        {
            var experiment = await dbContext.RkExperiments.FirstOrDefaultAsync(e => e.RkExperimentId == experimentId);

            if (experiment == null)
            {
                throw new ApplicationException($"Experiment [{experimentId}] does not exists");
            }

            if (experiment.Status != ExperimentStatus.Created)
            {
                throw new ApplicationException($"Experiment [{experimentId}] cannot be marked as processed - it's in status [{experiment.Status}]");
            }

            experiment.Status          = ExperimentStatus.InProgress;
            experiment.StatusChangedAt = DateTime.UtcNow;

            await dbContext.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <Guid> CreateProject(string name, string organization, string comments)
        {
            VerifyAdminAccess();

            var project = new Project()
            {
                ProjectName      = name,
                OrganizationName = organization,
                Comments         = comments,
                CreatedAt        = DateTime.UtcNow,
                ModifiedAt       = DateTime.UtcNow,
                ProjectType      = RkExperimentType.RK
            };

            await dbContext.Projects.AddAsync(project);

            await dbContext.SaveChangesAsync();

            return(project.ProjectId);
        }
Exemplo n.º 5
0
        public async Task <Guid> CreateExperimentTemplate(string name, string description, Guid projectId)
        {
            await VerifyAccessToProject(projectId);

            var accounts = await dbContext.RkAccounts.ToListAsync();

            var experimentTemplate = new RkExperimentTemplate()
            {
                Name        = name,
                Description = description,
                CreatedAt   = DateTime.UtcNow,
                ModifiedAt  = DateTime.UtcNow,
                OwnerId     = userContext.UserId,
                ProjectId   = projectId,
                Accounts    = accounts.Select(a => new RkAccountInExperiment()
                {
                    AccountId = a.RkAccountId
                }).ToList()
            };

            await dbContext.AddAsync(experimentTemplate);

            await dbContext.SaveChangesAsync();

            return(experimentTemplate.RkExperimentTemplateId);
        }