public Pessoa Inserir(Pessoa model) { try { using (EGContext db = new EGContext()) { var pessoa = model; if (model.Id > 0) { var exists = db.Pessoas.Find(model.Id); if (exists == null) { return(null); } exists.Nome = model.Nome; db.Entry(exists).State = EntityState.Modified; } else { db.Pessoas.Add(pessoa); } db.SaveChanges(); return(pessoa); } } catch (System.Exception) { throw; } }
public Jogo Inserir(Jogo model) { try { using (EGContext db = new EGContext()) { var jogo = model; if (model.Id > 0) { var exists = db.Jogos.Find(model.Id); if (exists == null) { return(null); } exists.Descricao = model.Descricao; exists.Nome = model.Nome; db.Entry(exists).State = EntityState.Modified; } else { db.Jogos.Add(model); } db.SaveChanges(); return(jogo); } } catch (System.Exception) { throw; } }
public List <Jogo> Get() { try { using (EGContext db = new EGContext()) { return(db.Jogos.ToList()); } } catch (System.Exception) { throw; } }
public Jogo GetId(int Id) { try { using (EGContext db = new EGContext()) { return(db.Jogos.Find(Id)); } } catch (System.Exception) { throw; } }
public List <Pessoa> GetPessoa(int JogoId) { try { using (EGContext db = new EGContext()) { return(db.PessoasXJogos.Where(a => a.JogoId == JogoId).Select(a => a.Pessoas).ToList()); } } catch (System.Exception) { throw; } }
public List <Jogo> GetJogosNaoEmprestados() { try { using (EGContext db = new EGContext()) { var jogosemprestados = db.Emprestimos.Where(x => x.DataDevolvido == null).Select(x => x.JogoId).ToArray(); var itens = db.Jogos.Where(p => !jogosemprestados.Contains(p.Id)).ToList(); return(itens); } } catch (System.Exception) { throw; } }
public List <EmprestimoResponse> GetSoEmprestado() { try { using (EGContext db = new EGContext()) { var itens = (from emp in db.Emprestimos join jogo in db.Jogos on emp.JogoId equals jogo.Id join pessoaDona in db.Pessoas on emp.PessoaDonoJogoId equals pessoaDona.Id join pessoaEmprestada in db.Pessoas on emp.PessoaEmprestadaId equals pessoaEmprestada.Id where emp.DataDevolvido == null select new { emp.Id, emp.JogoId, emp.PessoaEmprestadaId, nomejogo = jogo.Nome, dequem = pessoaDona.Nome, praquem = pessoaEmprestada.Nome, emp.DataEmprestimo, emp.DataDevolvido }).ToList(); var list = new List <EmprestimoResponse>(); foreach (var item in itens) { list.Add(new EmprestimoResponse { Id = item.Id, Jogo = item.nomejogo, DeQuem = item.dequem, PraQuem = item.praquem, DataEmprestimo = item.DataEmprestimo, DataDevolvido = item.DataDevolvido }); } return(list); } } catch (System.Exception) { throw; } }
public PessoaXJogo Inserir(PessoaXJogo model) { try { using (EGContext db = new EGContext()) { var jogo = model; db.PessoasXJogos.Add(model); db.SaveChanges(); return(jogo); } } catch (System.Exception) { throw; } }
public Emprestimo Inserir(Emprestimo model) { try { using (EGContext db = new EGContext()) { var emprestimo = model; emprestimo.DataEmprestimo = DateTime.Now; db.Emprestimos.Add(emprestimo); db.SaveChanges(); return(emprestimo); } } catch (System.Exception) { throw; } }
public bool Remove(int Id) { try { using (EGContext db = new EGContext()) { if (Id == 0) { return(false); } var model = db.Emprestimos.Find(Id); db.Emprestimos.Remove(model); db.SaveChanges(); return(true); } } catch (System.Exception) { return(false); } }
public List <PessoaXJogosResponsecs> Get() { try { using (EGContext db = new EGContext()) { var itens = (from pxj in db.PessoasXJogos join jogo in db.Jogos on pxj.JogoId equals jogo.Id join pessoa in db.Pessoas on pxj.PessoaId equals pessoa.Id select new { pxj.Id, pxj.JogoId, pxj.PessoaId, nomejogo = jogo.Nome, nomepessoa = pessoa.Nome }).ToList(); var list = new List <PessoaXJogosResponsecs>(); foreach (var item in itens) { list.Add(new PessoaXJogosResponsecs { Id = item.Id, JogoId = item.JogoId, NomeJogo = item.nomejogo, NomePessoa = item.nomepessoa, PessoaId = item.PessoaId }); } return(list); } } catch (System.Exception) { throw; } }
public bool Devolver(int Id) { try { using (EGContext db = new EGContext()) { if (Id == 0) { return(false); } var model = db.Emprestimos.Find(Id); model.DataDevolvido = DateTime.Now; db.Entry(model).State = EntityState.Modified; db.SaveChanges(); return(true); } } catch (System.Exception) { return(false); } }
public SpellsController(EGContext data) { _data = data; }