Exemple #1
0
        /// <summary>
        /// Create a new workspace
        /// </summary>
        /// <param name="model"></param>
        /// <returns>Workspace</returns>
        public async Task <Workspace> Create(NewWorkspace model)
        {
            if (!User.IsCreator &&
                User.WorkspaceLimit <= await _workspaceStore.GetWorkspaceCount(User.Id))
            {
                throw new WorkspaceLimitReachedException();
            }

            var workspace = Mapper.Map <Data.Workspace>(model);

            workspace.TemplateLimit = _options.DefaultTemplateLimit;

            workspace.ShareCode = Guid.NewGuid().ToString("N");

            workspace.Author = User.Name;

            workspace.LastActivity = DateTime.UtcNow;

            workspace = await _workspaceStore.Add(workspace);

            workspace.Workers.Add(new Data.Worker
            {
                PersonId   = User.Id,
                Permission = Data.Permission.Manager
            });

            await _workspaceStore.Update(workspace);

            return(Mapper.Map <Workspace>(workspace, WithActor()));
        }
Exemple #2
0
        /// <summary>
        /// Create a new workspace
        /// </summary>
        /// <param name="model"></param>
        /// <param name="subjectId"></param>
        /// <param name="subjectName"></param>
        /// <returns>Workspace</returns>
        public async Task <Workspace> Create(NewWorkspace model, string subjectId, string subjectName)
        {
            var workspace = Mapper.Map <Data.Workspace>(model);

            workspace.TemplateLimit = _options.DefaultTemplateLimit;
            workspace.WhenCreated   = DateTimeOffset.UtcNow;
            workspace.LastActivity  = DateTimeOffset.UtcNow;

            if (workspace.Challenge.IsEmpty())
            {
                workspace.Challenge = JsonSerializer.Serialize <ChallengeSpec>(
                    new ChallengeSpec(),
                    jsonOptions
                    );
            }

            workspace.Workers.Add(new Data.Worker
            {
                SubjectId   = subjectId,
                SubjectName = subjectName,
                Permission  = Permission.Manager
            });

            workspace = await _store.Create(workspace);

            // TODO: consider handling document here

            return(Mapper.Map <Workspace>(workspace));
        }
Exemple #3
0
        public async Task <ActionResult <Workspace> > CreateWorkspace([FromBody] NewWorkspace model)
        {
            await Validate(model);

            AuthorizeAny(
                () => Actor.IsAdmin,
                () => Actor.IsCreator,
                () => _svc.CheckWorkspaceLimit(Actor.Id).Result
                );

            return(Ok(
                       await _svc.Create(model, Actor.Id, Actor.Name)
                       ));
        }
        public async Task <ActionResult <Workspace> > Create([FromBody] NewWorkspace model)
        {
            Workspace workspace = await _workspaceService.Create(model);

            return(Created(Url.Action("Load", new { Id = workspace.Id }), workspace));
        }
Exemple #5
0
 private async Task _validate(NewWorkspace model)
 {
     await Task.CompletedTask;
 }