Exemplo n.º 1
0
        public Usuario Insert(Usuario u)
        {
            using (DiscosDAL dal = new DiscosDAL())
            {
                dal.Usuarios.Add(u);

                if (dal.SaveChanges() == 0)
                {
                    u = null;
                }
                else
                {
                    UsuarioGrupo ug = new UsuarioGrupo();

                    ug.IdUsuario = dal.Usuarios.OrderByDescending(us => us.IdUsuario)
                                   .Select(us => us.IdUsuario)
                                   .Take(1).Single();
                    ug.IdGrupo = 2;

                    dal.UsuariosGrupos.Add(ug);

                    if (dal.SaveChanges() == 0)
                    {
                        u = null;
                    }
                }
            }

            return(u);
        }
Exemplo n.º 2
0
        public List <Cliente> Get()
        {
            List <Cliente> clientes = new List <Cliente>();

            using (DiscosDAL context = new DiscosDAL())
            {
                clientes = context.Clientes.ToList();
            }

            return(clientes);
        }
Exemplo n.º 3
0
        public Cliente Get(int Id)
        {
            Cliente cliente = new Cliente();

            using (DiscosDAL context = new DiscosDAL())
            {
                cliente = (Cliente)context.Clientes.Where(c => c.Id == Id);
            }

            return(cliente);
        }
Exemplo n.º 4
0
        public List <Interprete> Get()
        {
            List <Interprete> interpretes = new List <Interprete>();

            using (DiscosDAL context = new DiscosDAL())
            {
                interpretes = context.Interpretes.ToList();
            }

            return(interpretes);
        }
Exemplo n.º 5
0
        public List <Disco> Get()
        {
            List <Disco> discos = new List <Disco>();

            using (DiscosDAL context = new DiscosDAL())
            {
                discos = context.Discos
                         .Include("Interprete")
                         .Include("Puntuaciones").ToList();
            }

            return(discos);
        }
Exemplo n.º 6
0
        public Cliente Remove(Cliente cli)
        {
            using (DiscosDAL context = new DiscosDAL())
            {
                context.Clientes.Remove(cli);
                if (context.SaveChanges() == 0)
                {
                    cli = null;
                }
            }

            return(cli);
        }
Exemplo n.º 7
0
        public List <Puntuacion> Get(int Id)
        {
            List <Puntuacion> puntuaciones = new List <Puntuacion>();

            using (DiscosDAL context = new DiscosDAL())
            {
                puntuaciones = context.Puntuaciones
                               .Include("Disco")
                               .Where(p => p.IdCliente == Id).ToList();
            }

            return(puntuaciones);
        }
Exemplo n.º 8
0
        public Usuario IsAuthenticated(Usuario u)
        {
            Usuario authUser = null;

            using (DiscosDAL dal = new DiscosDAL())
            {
                string password = u.Password;

                authUser = dal.Usuarios.Include(usu => usu.UsuariosGrupos.Select(g => g.Grupo))
                           .FirstOrDefault(usu => usu.Login == u.Login && usu.Password == password);
            }

            return(authUser);
        }