Пример #1
0
        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;
            }
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
 public List <Jogo> Get()
 {
     try
     {
         using (EGContext db = new EGContext())
         {
             return(db.Jogos.ToList());
         }
     }
     catch (System.Exception)
     {
         throw;
     }
 }
Пример #4
0
 public Jogo GetId(int Id)
 {
     try
     {
         using (EGContext db = new EGContext())
         {
             return(db.Jogos.Find(Id));
         }
     }
     catch (System.Exception)
     {
         throw;
     }
 }
Пример #5
0
 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;
     }
 }
Пример #6
0
 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;
     }
 }
Пример #7
0
        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;
            }
        }
Пример #8
0
        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;
            }
        }
Пример #9
0
        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;
            }
        }
Пример #10
0
        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);
            }
        }
Пример #11
0
        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;
            }
        }
Пример #12
0
        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);
            }
        }
Пример #13
0
 public SpellsController(EGContext data)
 {
     _data = data;
 }