public async Task <ActionResult <CompanyDto> > CreateCompany([FromBody] CompanyAddDto company) { // 使用了api controller就不需要这个判断了。 //if (company == null) //{ // return BadRequest(); //} var entity = _mapper.Map <Company>(company); _companyRepositroy.AddCompany(entity); await _companyRepositroy.SaveAsync(); var returnDto = _mapper.Map <CompanyDto>(entity); var links = CreateLinksForCompany(returnDto.Id, null); var linkedDict = returnDto.shapeData(null) as IDictionary <string, object>; linkedDict.Add("links", links); return(CreatedAtRoute(nameof(GetCompany), new { companyId = linkedDict["Id"] }, linkedDict)); }
public async Task <ActionResult <IEnumerable <CompanyDto> > > CreateCompanyCollection([FromBody] IEnumerable <CompanyAddDto> companyCollection) { var companyEntities = _mapper.Map <IEnumerable <Company> >(companyCollection); foreach (var item in companyEntities) { _companyRepositroy.AddCompany(item); } await _companyRepositroy.SaveAsync(); //return Ok(); var returnDto = _mapper.Map <IEnumerable <CompanyDto> >(companyEntities); var idsString = string.Join(",", returnDto.Select(x => x.Id)); return(CreatedAtRoute(nameof(GetCompanyCollection), new { ids = idsString }, returnDto)); }