public async Task <IActionResult> Create([FromBody] CreateSiteDto dto) { await Task.Run(() => { int result = _siteService.Create(dto); }); return(Ok(new StringResult { Result = "Created" })); }
public int Create(CreateSiteDto createSiteDto) { // //if the same task name exists for this tenant //not allowed // if (_context.Sites.Where(x => x.Name == createSiteDto.Name && x.TenantId == createSiteDto.TenantId).Any()) { throw new OccumetricException("Site name already exists"); } var site = _mapper.Map <Site>(createSiteDto); _context.Sites.Add(site); _context.SaveChanges(); return(site.Id); }
public async Task <ActionResult <SiteDto> > PostAsync(CreateSiteDto createSiteDto) { var site = new SiteEntity { SiteID = createSiteDto.SiteID, CustomerCID = createSiteDto.CustomerCID, SiteName = createSiteDto.SiteName, Distance = createSiteDto.Distance }; await _siteRepository.CreateAsync(site); await _publishEndpoint.Publish(new SiteCreated(site.SiteID, site.CustomerCID, site.SiteName, site.Distance)); return(CreatedAtAction(nameof(GetByIDAsync), new { id = site.SiteID }, site)); }