Exemplo n.º 1
0
        public async Task <IHttpActionResult> PutAsync(int id, [FromBody] ActionItemDto model, CancellationToken cancellationToken)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }
            var action = await _projectManager.GetActionByIdAsync(id, cancellationToken);

            if (action == null)
            {
                return(NotFound());
            }
            var project = await _projectManager.FindByIdAsync(action.Project.Id, cancellationToken);

            await ApiSecurity.AuthorizeAsync(project, AccessPermission.CanEdit, cancellationToken);

            action.Type         = model.Type;
            action.Enabled      = model.Enabled;
            action.Name         = model.Name;
            action.Options      = model.Options;
            action.ModifiedDate = DateTime.UtcNow;

            var validationResult = await _projectManager.ReplaceActionAsync(project, action, action, cancellationToken);

            if (!validationResult.Succeeded)
            {
                return(this.ValidationContent(validationResult));
            }
            return(new ActionContentResult(_actionLinkService, action, this));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> PostAsync(int projectId, int?parentId, [FromBody] ActionItemDto model, CancellationToken cancellationToken)
        {
            if (model == null || !ModelState.IsValid)
            {
                return(BadRequest());
            }
            var project = await _projectManager.FindByIdAsync(projectId, cancellationToken);

            await ApiSecurity.AuthorizeAsync(project, AccessPermission.CanEdit, cancellationToken);

            var parentAction = default(ActionItem);

            if (parentId != null)
            {
                parentAction = await _projectManager.GetActionByIdAsync((int)parentId, cancellationToken);

                if (parentAction == null || parentAction.Project.Id != project.Id)
                {
                    return(BadRequest());
                }
            }
            var action = new ActionItem
            {
                Type    = model.Type,
                Enabled = model.Enabled,
                Name    = model.Name,
                Options = model.Options
            };
            var validationResult = await _projectManager.AddActionAsync(project, parentAction, action, cancellationToken);

            if (!validationResult.Succeeded)
            {
                return(this.ValidationContent(validationResult));
            }
            var actionResult = await _projectManager.GetActionByIdAsync(action.Id, cancellationToken);

            return(new ActionContentResult(HttpStatusCode.Created, _actionLinkService, actionResult, this));
        }
Exemplo n.º 3
0
 public Task <IHttpActionResult> PostAsync(int projectId, [FromBody] ActionItemDto model, CancellationToken cancellationToken)
 {
     return(PostAsync(projectId, null, model, cancellationToken));
 }