public async Task <ActionResult <ActorLookupDto> > Add([FromBody] ActorLookupDto actor) { if (!ModelState.IsValid) { return(BadRequest(new ActorLookupDtoValidator().Validate(actor).Errors)); } try { var model = await _repository.AddAsync(actor); //await _actorPhotosRepository.AddAsync(new ActorPhotoLookupDto{ActorId = model.ActorId, Path = "Hello path"}); //foreach(var photo in actor.Photos) //{ // await _actorPhotosRepository.AddAsync(new ActorPhotoLookupDto { ActorId = model.ActorId, Path = photo.Path }); //} //model.Photos = _actorPhotosRepository.Find(e => e.ActorId == model.ActorId); return(Ok(model)); } // TODO: Specify more specific exceptions. catch (Exception) { return(BadRequest(new ActorLookupDto { Errors = new List <string> { "Error at add entity." } })); } }
public async Task <ActionResult <ActorLookupDto> > Update([FromBody] ActorLookupDto obj) { if (!ModelState.IsValid) { return(BadRequest(new ActorLookupDtoValidator().Validate(obj).Errors)); } try { return(Ok(await _repository.UpdateAsync(e => e.ActorId == obj.ActorId, obj))); } // TODO: Specify more specific exceptions. catch (Exception e) { return(BadRequest(e.Message)); } }