public async Task <IActionResult> Post([FromBody] SubdomainDto subdomainDto, CancellationToken cancellationToken) { if (!ModelState.IsValid) { return(BadRequest()); } var target = await this.targetService.GetByCriteriaAsync(t => t.Name == subdomainDto.Target, cancellationToken); if (target == null) { return(BadRequest()); } if (await this.subdomainService.AnyAsync(s => s.Name == subdomainDto.Name && s.Target == target)) { return(BadRequest()); } var newSubdoamin = await this.subdomainService.AddAsync(new Subdomain { Target = target, Name = subdomainDto.Name }, cancellationToken); return(Ok(mapper.Map <Subdomain, SubdomainDto>(newSubdoamin))); }
public ICollection <SubdomainLabel> Resolve(SubdomainDto source, Subdomain destination, ICollection <SubdomainLabel> member, ResolutionContext context) { var SubdomainLabels = new List <SubdomainLabel>(); source.Labels.ForEach(label => { var labelDb = this.labelService.GetByCriteriaAsync(c => c.Name == label.Name).Result; if (labelDb != null) { SubdomainLabels.Add(new SubdomainLabel { LabelId = labelDb.Id }); } else { SubdomainLabels.Add(new SubdomainLabel { Label = new Label { Name = label.Name } }); } }); return(SubdomainLabels); }
public async Task <IActionResult> Put(Guid id, [FromBody] SubdomainDto subdomainDto, 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 editedSubdmain = this.mapper.Map <SubdomainDto, Subdomain>(subdomainDto); subdomain.Name = editedSubdmain.Name; subdomain.IsMainPortal = editedSubdmain.IsMainPortal; subdomain.Labels = await this.labelService.GetLabelsAsync(subdomain.Labels, subdomainDto.Labels.Select(l => l.Name).ToList(), cancellationToken); await this.subdomainService.UpdateAsync(subdomain, cancellationToken); return(NoContent()); }
public async Task <IActionResult> Put(Guid id, [FromBody] SubdomainDto subdomainDto, CancellationToken cancellationToken) { var subdomain = await this.subdomainService.GetWithLabelsAsync(a => a.Id == id, cancellationToken); if (subdomain == null) { return(NotFound()); } var editedSubdmain = this.mapper.Map <SubdomainDto, Subdomain>(subdomainDto); subdomain.Name = editedSubdmain.Name; subdomain.IsMainPortal = editedSubdmain.IsMainPortal; subdomain.Labels = await this.labelService.GetLabelsAsync(subdomain.Labels, subdomainDto.Labels.Select(l => l.Name).ToList(), cancellationToken); await this.subdomainService.UpdateAsync(subdomain, cancellationToken); return(NoContent()); }
public async Task <IActionResult> Post([FromBody] SubdomainDto subdomainDto, CancellationToken cancellationToken) { if (!ModelState.IsValid) { return(BadRequest()); } var target = await this.targetService.GetTargetNotTrackingAsync(t => t.Name == subdomainDto.Target, cancellationToken); if (target == null) { return(BadRequest()); } var rootDomain = await this.rootDomainService.GetRootDomainNoTrackingAsync(r => r.Target == target && r.Name == subdomainDto.RootDomain, cancellationToken); if (rootDomain == null) { return(BadRequest()); } var subdomainExist = await this.subdomainService.AnyAsync(s => s.RootDomain == rootDomain && s.Name == subdomainDto.Name); if (subdomainExist) { return(BadRequest($"The subdomain {subdomainDto.Name} exist")); } var newSubdoamin = await this.subdomainService.AddAsync(new Subdomain { RootDomain = rootDomain, Name = subdomainDto.Name }, cancellationToken); return(Ok(mapper.Map <Subdomain, SubdomainDto>(newSubdoamin))); }