示例#1
0
 public IList <Jogo> CarregarTodos()
 {
     using (var ctx = new SEJContext())
     {
         return(ctx.Jogos.Where(x => x.Ativo).OrderBy(x => x.Id).ToList());
     }
 }
 public IList <Amigo> CarregarTodos()
 {
     using (var ctx = new SEJContext())
     {
         return(ctx.Amigos.Where(x => x.Ativo).ToList());
     }
 }
 public Amigo CarregarPorId(int id)
 {
     using (var ctx = new SEJContext())
     {
         return(ctx.Amigos.Single(x => x.Id == id));
     }
 }
示例#4
0
 public Jogo CarregarPorId(int?id)
 {
     using (var ctx = new SEJContext())
     {
         return(ctx.Jogos.Single(x => x.Id == id && x.Ativo));
     }
 }
示例#5
0
 public IList <Jogo> CarregarNaoEmprestados()
 {
     using (var ctx = new SEJContext())
     {
         return(ctx.Jogos.Where(x => !x.Emprestado && x.Ativo).ToList());
     }
 }
示例#6
0
 public Emprestimo CarregarJogosEmprestados(int id)
 {
     using (var ctx = new SEJContext())
     {
         return(ctx.Emprestimos.SingleOrDefault(x => x.IdJogo == id && !x.Devolvido));
     }
 }
 public Emprestimo CarregarListaAmigosComEmprestimo(int id)
 {
     using (var ctx = new SEJContext())
     {
         return(ctx.Emprestimos.SingleOrDefault(x => x.IdAmigo == id && !x.Devolvido));
     }
 }
示例#8
0
 public void Excluir(int id)
 {
     using (var ctx = new SEJContext())
     {
         var removido = ctx.Jogos.Single(x => x.Id == id);
         removido.Ativo = false;
         ctx.SaveChanges();
     }
 }
 public IList <Emprestimo> CarregarPorJogo(int id)
 {
     using (var ctx = new SEJContext())
     {
         return(ctx.Emprestimos
                .Include(x => x.Jogo)
                .Include(x => x.Amigo)
                .Where(x => x.IdJogo == id).ToList());
     }
 }
 public Emprestimo CarregarPorId(int id)
 {
     using (var ctx = new SEJContext())
     {
         return(ctx.Emprestimos
                .Include(x => x.Jogo)
                .Include(x => x.Amigo)
                .Single(x => x.Id == id));
     }
 }
        public void Cadastrar(Amigo amigo)
        {
            using (var ctx = new SEJContext())
            {
                amigo.Ativo = true;
                ctx.Amigos.Add(amigo);

                ctx.SaveChanges();
            }
        }
示例#12
0
 public void Cadastrar(Jogo jogo)
 {
     using (var ctx = new SEJContext())
     {
         jogo.Emprestado = false;
         jogo.Ativo      = true;
         ctx.Jogos.Add(jogo);
         ctx.SaveChanges();
     }
 }
        public void Excluir(int id)
        {
            using (var ctx = new SEJContext())
            {
                var excluido = ctx.Emprestimos.Single(x => x.Id == id);

                ctx.Emprestimos.Remove(excluido);

                ctx.SaveChanges();
            }
        }
        public IList <Emprestimo> CarregarTodos()
        {
            using (var ctx = new SEJContext())
            {
                var emprestimos = ctx.Emprestimos
                                  .Include(x => x.Jogo)
                                  .Include(x => x.Amigo)
                                  .Where(x => !x.Devolvido).OrderByDescending(x => x.Id).ToList();

                return(emprestimos);
            }
        }
        public void Cadastrar(Emprestimo emprestimo)
        {
            using (var ctx = new SEJContext())
            {
                emprestimo.Devolvido = false;
                var emprestado = ctx.Jogos.Single(x => x.Id == emprestimo.IdJogo);
                emprestado.Emprestado = true;
                ctx.Emprestimos.Add(emprestimo);

                ctx.SaveChanges();
            }
        }
示例#16
0
        public void Alterar(Jogo jogo)
        {
            using (var ctx = new SEJContext())
            {
                var alterado = ctx.Jogos.Single(x => x.Id == jogo.Id);
                alterado.Descricao     = jogo.Descricao;
                alterado.Distribuidora = jogo.Distribuidora;
                alterado.Valor         = jogo.Valor;

                ctx.SaveChanges();
            }
        }
        public IList <Emprestimo> CarregarHistorico()
        {
            using (var ctx = new SEJContext())
            {
                var emprestimos = ctx.Emprestimos
                                  .Include(x => x.Jogo)
                                  .Include(x => x.Amigo)
                                  .OrderByDescending(x => x.DataEmprestimo).ToList();

                return(emprestimos);
            }
        }
        public void Alterar(Amigo amigo)
        {
            using (var ctx = new SEJContext())
            {
                var alterado = ctx.Amigos.Single(x => x.Id == amigo.Id);
                alterado.Nome     = amigo.Nome;
                alterado.Idade    = amigo.Idade;
                alterado.Endereco = amigo.Endereco;

                ctx.SaveChanges();
            }
        }
        public void Devolver(int id)
        {
            using (var ctx = new SEJContext())
            {
                var devolvido = ctx.Emprestimos.Single(x => x.Id == id);
                var jogo      = ctx.Jogos.Single(x => x.Id == devolvido.IdJogo);
                jogo.Emprestado         = false;
                devolvido.Devolvido     = true;
                devolvido.DataDevolucao = DateTime.Now;

                ctx.SaveChanges();
            }
        }