public async Task <ActionResult <PublicApi.v1.DTO.Person> > PostPerson(PublicApi.v1.DTO.Person person) { person.AppUserId = User.GetUserId(); person = PublicApi.v1.Mappers.PersonMapper.MapFromBLL( _bll.Persons.Add(PublicApi.v1.Mappers.PersonMapper.MapFromExternal(person))); await _bll.SaveChangesAsync(); person = PublicApi.v1.Mappers.PersonMapper.MapFromBLL( _bll.Persons.GetUpdatesAfterUOWSaveChanges(PublicApi.v1.Mappers.PersonMapper.MapFromExternal(person))); // get the new id into the object return(CreatedAtAction("GetPerson", new { id = person.Id }, person)); }
public async Task <IActionResult> PutPerson(int id, PublicApi.v1.DTO.Person person) { if (id != person.Id) { return(BadRequest()); } // check for the ownership - is this Person record really belonging to logged in user. if (!await _bll.Persons.BelongsToUserAsync(id, User.GetUserId())) { return(NotFound()); } person.AppUserId = User.GetUserId(); _bll.Persons.Update(PublicApi.v1.Mappers.PersonMapper.MapFromExternal(person)); await _bll.SaveChangesAsync(); return(NoContent()); }