public async Task <IActionResult> CreateCenter([FromBody] CenterForCreationDto centerForCreation) { if (_centerRepository.CenterExists(centerForCreation.Name)) { return(Conflict(new { message = "Center already exists in the database" })); } var center = _mapper.Map <Center> (centerForCreation); _centerRepository.AddCenter(center); await _centerRepository.SaveChangesAsync(); var centerToReturn = _mapper.Map <CenterDto> (center); var links = CreateLinksForCenter(centerToReturn.CenterId, null); var linkedResourceToReturn = centerToReturn.ShapeData(null) as IDictionary <string, object>; linkedResourceToReturn.Add("links", links); return(CreatedAtRoute("GetCenterById", new { centerId = linkedResourceToReturn["CenterId"] }, linkedResourceToReturn)); }
public void AddCenter(CenterDto center) { _centerRepository.AddCenter(center.MapToDbModel()); }