public async Task <ActionResult <PublicApi.v1.DTO.Dog> > PostDog(PublicApi.v1.DTO.Dog dog) { if (!await _bll.Dog.BelongsToUserAsync(dog.Id, User.GetUserId())) { return(NotFound()); } dog = PublicApi.v1.Mappers.DogMapper.MapFromInternal( _bll.Dog.Add(PublicApi.v1.Mappers.DogMapper.MapFromExternal(dog))); await _bll.Dog.AddAsync(PublicApi.v1.Mappers.DogMapper.MapFromExternal(dog)); await _bll.SaveChangesAsync(); dog = PublicApi.v1.Mappers.DogMapper.MapFromInternal( _bll.Dog.GetUpdatesAfterUOWSaveChanges( PublicApi.v1.Mappers.DogMapper.MapFromExternal(dog))); return(CreatedAtAction("GetDog", new { version = HttpContext.GetRequestedApiVersion().ToString(), id = dog.Id }, dog));; }
public async Task <IActionResult> PutDog(int id, PublicApi.v1.DTO.Dog dog) { if (id != dog.Id) { return(BadRequest()); } dog.AppUserId = User.GetUserId(); // check, that the Person being used is really belongs to logged in user if (!await _bll.Dog.BelongsToUserAsync(id, User.GetUserId())) { return(NotFound()); } _bll.Dog.Update(PublicApi.v1.Mappers.DogMapper.MapFromExternal(dog)); await _bll.SaveChangesAsync(); return(NoContent()); }