private Models.Emprestimo retornarEmprestimo(int amigoId) { var usuarioId = getUsuarioId(); List <Entities.Models.Emprestimo> emprestimos = _repository.Emprestimo.ObterTodos(usuarioId).ToList(); List <Entities.Models.Jogo> jogos = _repository.Jogo.ObterTodos(usuarioId).ToList(); var lstJogosEmprestados = new List <Models.JogoEmprestado>(); foreach (var item in jogos) { bool emprestado = false; if (emprestimos.Any()) { var oEmprestimo = (from obj in emprestimos where obj.Amigo == amigoId && item.Id == obj.Jogo select obj).FirstOrDefault(); if (oEmprestimo != null) { emprestado = (oEmprestimo.Emprestado == 1); } } var jogoEmprestado = new Models.JogoEmprestado(item, amigoId, emprestado); lstJogosEmprestados.Add(jogoEmprestado); } var Emprestimo = new Models.Emprestimo(); Emprestimo.lstJogosEmprestados = lstJogosEmprestados; return(Emprestimo); }
public IActionResult GravarEmprestimo(Models.Emprestimo Emprestimo) { try { _repository.Emprestimo.Excluir(getUsuarioId()); if (Emprestimo.lstJogosEmprestados.Any()) { foreach (var item in Emprestimo.lstJogosEmprestados) { var emprestimo = new Entities.Models.Emprestimo(); emprestimo.Amigo = item.geAmigoId; if (item.emprestado) { emprestimo.Emprestado = 1; } else { emprestimo.Emprestado = 0; } emprestimo.Jogo = item.getJogoId; emprestimo.Usuario = getUsuarioId(); _repository.Emprestimo.CriarEmprestimo(emprestimo); } } return(View()); } catch (Exception) { throw; } }
public IActionResult BuscarJogosEmprestado(Entities.Models.Amigo amigo) { Models.Emprestimo Emprestimo = retornarEmprestimo(amigo.Id); Emprestimo.lstAmigos = getAmigos(getUsuarioId()); Emprestimo.Usuario = getUsuarioId(); ViewBag.Emprestimo = Emprestimo; return(View()); }
public IActionResult Devolver(int id) { string msg = new Models.Emprestimo().DevolverEmprestimo(id); return(Json(new { msg })); }
public void Put(int id, [FromBody] Models.Emprestimo value) { }
public void Post([FromBody] Models.Emprestimo value) { }