public async Task <IActionResult> Post([FromBody] IncidentPostRp model) { var(result, created) = await this._incidentComponent.Post(model); if (created) { return(this.Created(Url.RouteUrl("GetIncidentId", new { id = result.Id }), result)); } else { return(this.Ok(result)); } }
public async Task <(IncidentGetListRp incident, bool created)> Post(IncidentPostRp model) { bool created = false; var createdBy = this._identityGateway.GetIdentity(); var entity = await this._dbContext.Incidents.Where(c => c.Key == model.Key && c.ProductId == model.ProductId).SingleOrDefaultAsync(); if (entity == null) { created = true; var product = await this._dbContext.Products.Where(c => c.Id == model.ProductId).SingleAsync(); entity = IncidentEntity.Factory.Create(model.Key, model.Title, this._datetimeGateway.GetCurrentDateTime(), createdBy, product); this._dbContext.Incidents.Add(entity); await this._dbContext.SaveChangesAsync(); } return(this._mapper.Map <IncidentGetListRp>(entity), created); }