Ejemplo n.º 1
0
        public IActionResult AddArticle([FromForm] ArticleViewModel articleViewModel)
        {
            if (!_authorService.isThereAnAuthorWithEmail(articleViewModel.Email))
            {
                return(Redirect(Url.Action("AddAuthor", "Author", articleViewModel)));
            }

            _articleService.AddArticle(articleViewModel.Email,
                                       articleViewModel.Title,
                                       articleViewModel.Content,
                                       (DateTime)articleViewModel.Date);

            String[] hashtags = articleViewModel.Hashtags.Split(" ");
            _tagsService.AddTags(hashtags);

            var recentlyCreatedArticle = _articleService.GetNewestAddedArticle(articleViewModel.Title,
                                                                               articleViewModel.Content,
                                                                               articleViewModel.Email);

            foreach (var hashtag in hashtags)
            {
                var tag = _tagsService.GetTagBy(hashtag);

                _articleTagsService.Add(tag, recentlyCreatedArticle);
            }
            return(Redirect(Url.Action("Index", "Home")));
        }
        public async Task <string> PostAsync(
            CustomBuildDefinitionPayload payload)
        {
            try
            {
                var client = await _azureClient.GetBuildClientAsync();

                var definition = new BuildDefinition
                {
                    Name       = $"{payload.ApplicationName}-{payload.BuildTemplate}-{payload.Branch}",
                    Path       = payload.Path,
                    Repository = new BuildRepository
                    {
                        DefaultBranch = payload.Branch,
                        Name          = payload.Repository,
                        Type          = "TfsGit",
                    },
                    Queue = new AgentPoolQueue
                    {
                        Name = payload.QueuePool,
                        Pool = new TaskAgentPoolReference
                        {
                            Name = payload.QueuePool
                        }
                    }
                };

                await _variableGroupService.AddVariableGroups(definition, payload);

                await _taskGroupService.AddTaskGroupSteps(definition, payload);

                _variableService.AddVariables(definition, payload);
                _triggersService.AddTriggers(definition, payload);

                var result = await client
                             .CreateDefinitionAsync(definition, payload.Project);

                await _tagsService.AddTags(result, payload);

                return($"{payload.Project}@@@{result.Id.ToString()}");
            }
            catch (Exception e)
            {
                throw new Exception(
                          "Error: Something went wrong when calling the AzureDevOps API", e);
            }
        }