public IActionResult BuscarItensPerdidosMatch(long usuarioId, [FromServices] IItemMatchService itemMatchService) { try { List <ItemPerdido> perdidos = itemMatchService.BuscarMatchsPerdidos(usuarioId); return(Ok(perdidos)); } catch (Exception e) { return(BadRequest(e)); } }
public ActionResult Atualizar([FromBody] ItemPerdido itemPerdido, [FromServices] IItemMatchService itemMatchService, [FromServices] IItemAchadoService itemAchadoService) { try { if (itemPerdido == null) { return(BadRequest("Item não informado")); } itemPerdidoService.Atualizar(itemPerdido); List <ItemMatch> matchs = itemMatchService.BuscarMatchsPerdidos(itemPerdido.UsuarioId, itemPerdido.Id); if (itemPerdido.Recuperado) { matchs.ForEach(match => { match.ItemAchado.Devolvido = true; }); } else { matchs.ForEach(match => { match.ItemAchado.Devolvido = false; }); } itemAchadoService.Atualizar(matchs.Select(match => match.ItemAchado).ToList()); itemPerdidoService.AtualizarItensCompativeis(itemPerdido); return(Ok(new RequestResponse() { message = "Item Atualizado com sucesso", status = "200" })); } catch (EntityNotFoundException ex) { return(NotFound(ex.Message)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
public IActionResult BuscarTodos(long idUsuario) { List <ItemPerdido> itens = itemMatchService.BuscarMatchsPerdidos(idUsuario); return(Ok(itens)); }