public async Task <IActionResult> AddLabel(Guid id, [FromBody] SubdomainLabelDto subdomainLabelDto, CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var subdomain = await this.subdomainService.GetAllQueryableByCriteria(a => a.Id == id, cancellationToken)
                            .Include(a => a.Labels)
                            .ThenInclude(ac => ac.Label)
                            .FirstOrDefaultAsync();

            if (subdomain == null)
            {
                return(NotFound());
            }

            var myLabels = subdomain.Labels.Select(l => l.Label.Name).ToList();

            myLabels.Add(subdomainLabelDto.Label);

            subdomain.Labels = await this.labelService.GetLabelsAsync(subdomain.Labels, myLabels, cancellationToken);

            subdomain = await this.subdomainService.UpdateAsync(subdomain, cancellationToken);

            var newLabel = subdomain.Labels.First(l => l.Label.Name == subdomainLabelDto.Label).Label;

            return(Ok(mapper.Map <Label, LabelDto>(newLabel)));
        }
Пример #2
0
        public async Task <IActionResult> AddLabel(Guid id, [FromBody] SubdomainLabelDto subdomainLabelDto, CancellationToken cancellationToken)
        {
            var subdomain = await this.subdomainService.GetWithLabelsAsync(a => a.Id == id, cancellationToken);

            if (subdomain == null)
            {
                return(NotFound());
            }

            await this.subdomainService.AddLabelAsync(subdomain, subdomainLabelDto.Label, cancellationToken);

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> AddLabel(Guid id, [FromBody] SubdomainLabelDto subdomainLabelDto, CancellationToken cancellationToken)
        {
            var subdomain = await this.subdomainService.GetWithIncludeAsync(a => a.Id == id, cancellationToken);

            if (subdomain == null)
            {
                return(NotFound());
            }

            var myLabels = subdomain.Labels.Select(l => l.Label.Name).ToList();

            myLabels.Add(subdomainLabelDto.Label);

            subdomain.Labels = await this.labelService.GetLabelsAsync(subdomain.Labels, myLabels, cancellationToken);

            subdomain = await this.subdomainService.UpdateAsync(subdomain, cancellationToken);

            var newLabel = subdomain.Labels.First(l => l.Label.Name == subdomainLabelDto.Label).Label;

            return(Ok(mapper.Map <Label, LabelDto>(newLabel)));
        }