Example #1
0
        public ActionResult Details(int id)//funcao que ira mostrar os detalhes sobre um item
        {
            EntertainmentDAO   entertainmentDAO = new EntertainmentDAO();
            EntertainmentModel entertainment    = entertainmentDAO.FetchOne(id, 0);//para saber sobre o FetchOne olhe a classe entertainmentDAO

            return(View("Details", entertainment));
        }
Example #2
0
        public ActionResult Pcreate(EntertainmentModel entertainmentModel)//funcao que ira criar um novo item e adiciona-lo a base de dados
        {
            EntertainmentDAO entertainmentDAO = new EntertainmentDAO();

            entertainmentDAO.Create(entertainmentModel, 0);//para saber sobre o Create olhe a classe entertainmentDAO
            return(View("Details", entertainmentModel));
        }
Example #3
0
        /// <summary>
        /// Ira colocar um novo item na database
        /// </summary>
        /// <param name="entertainmentModel">O item que será colocado na database</param>
        /// <param name="tipo">Se o tipo for 0 ele vai pegar as informações da database de jogos se for 1 ele vai pegar as de mangas</param>
        /// <returns></returns>
        public void Create(EntertainmentModel entertainmentModel, int tipo)
        {
            SqlConnection ligacao = new SqlConnection();//acessando a database
            string        tipoD = "", tipoS = "";

            if (tipo == 0)//Data Base de Jogos
            {
                tipoD = "GameDB";
                tipoS = "Games";
            }
            else if (tipo == 1)//Data Base de Mangas
            {
                tipoD = "MangaDB";
                tipoS = "Manga";
            }
            ligacao.ConnectionString = @"Server = (localdb)\MSSQLLocalDB; Database = " + tipoD + "; Trusted_Connection = True"; //acessando a database
            ligacao.Open();                                                                                                     //acessando a database
            SqlCommand command = new SqlCommand("INSERT INTO  dbo." + tipoS + " Values(@Nome,@Nota,@Resumo,@Imagem)", ligacao); //Está associando os valores @Nome,@Nota,@Resumo e ,@Imagem com os repectivos similares na tabela

            command.Parameters.Add("@Nome", System.Data.SqlDbType.VarChar).Value   = entertainmentModel.Nome;                   //Está associando os valor @Nome com o de Nome
            command.Parameters.Add("@Nota", System.Data.SqlDbType.VarChar).Value   = entertainmentModel.Nota;                   //Está associando os valor @Nota com o de Nota
            command.Parameters.Add("@Resumo", System.Data.SqlDbType.VarChar).Value = entertainmentModel.Resumo;                 //Está associando os valor @Resumo com o de Resumo
            command.Parameters.Add("@Imagem", System.Data.SqlDbType.VarChar).Value = entertainmentModel.Imagem;                 //Está associando os valor @Imagem com o de Imagem

            command.ExecuteNonQuery();                                                                                          //Ira ira exucutar a ação
        }
Example #4
0
        /// <summary>
        /// Vai procurar uma palavra entre os nomes na database
        /// </summary>
        /// <param name="searchWord">A palavra que vai ser procurada na database</param>
        /// <param name="tipo">Se o tipo for 0 ele vai pegar as informações da database de jogos se for 1 ele vai pegar as de mangas</param>
        /// <returns></returns>
        internal List <EntertainmentModel> SearchForEntertainment(string searchWord, int tipo)
        {
            List <EntertainmentModel> returnList = new List <EntertainmentModel>(); //acessando a database
            SqlConnection             ligacao = new SqlConnection();                //acessando a database
            string tipoD = "", tipoS = "";

            if (tipo == 0)//Data Base de Jogos
            {
                tipoD = "GameDB";
                tipoS = "Games";
            }
            else if (tipo == 1)//Data Base de Manga
            {
                tipoD = "MangaDB";
                tipoS = "Manga";
            }
            ligacao.ConnectionString = @"Server = (localdb)\MSSQLLocalDB; Database = " + tipoD + "; Trusted_Connection = True"; //acessando a database
            ligacao.Open();
            SqlCommand command = new SqlCommand("SELECT * FROM dbo." + tipoS + " WHERE Nome LIKE @search", ligacao);            //Associando o @search com o Id

            command.Parameters.Add("@search", System.Data.SqlDbType.NVarChar).Value = "%" + searchWord + "%";                   //Associando @search com searchWord


            SqlDataReader reader = command.ExecuteReader();

            //colacando os dados na lista
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    EntertainmentModel entertainmentModel = new EntertainmentModel();
                    entertainmentModel.Id     = reader.GetInt32(0);
                    entertainmentModel.Nome   = reader.GetString(1);
                    entertainmentModel.Nota   = reader.GetString(2);
                    entertainmentModel.Resumo = reader.GetString(3);
                    entertainmentModel.Imagem = reader.GetString(4);
                    returnList.Add(entertainmentModel);
                }
            }

            return(returnList);
        }
Example #5
0
        /// <summary>
        /// Vai pegar apenas a informação de um item da lista de acordo com o seu id e ira retornar o item
        /// </summary>
        /// <param name="Id">O id do tem que será pego</param>
        /// <param name="tipo">Se o tipo for 0 ele vai pegar as informações da database de jogos se for 1 ele vai pegar as de mangas</param>
        /// <returns></returns>
        public EntertainmentModel FetchOne(int Id, int tipo)
        {
            SqlConnection ligacao = new SqlConnection();//acessando a database
            string        tipoD = "", tipoS = "";

            if (tipo == 0)
            {
                tipoD = "GameDB";
                tipoS = "Games";
            }
            else if (tipo == 1)
            {
                tipoD = "MangaDB";
                tipoS = "Manga";
            }
            ligacao.ConnectionString = @"Server = (localdb)\MSSQLLocalDB; Database = " + tipoD + "; Trusted_Connection = True"; //acessando a database
            ligacao.Open();                                                                                                     //acessando a database
            SqlCommand command = new SqlCommand("SELECT * FROM " + tipoS + " WHERE Id = @id", ligacao);                         //Associando o @id com o Id

            command.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value = Id;                                                //Colando o valor de @id


            SqlDataReader      reader             = command.ExecuteReader();//Criando um reader com o item id selecionado
            EntertainmentModel entertainmentModel = new EntertainmentModel();

            if (reader.HasRows)
            {
                reader.Read();

                entertainmentModel.Id     = reader.GetInt32(0);
                entertainmentModel.Nome   = reader.GetString(1);
                entertainmentModel.Nota   = reader.GetString(2);
                entertainmentModel.Resumo = reader.GetString(3);
                entertainmentModel.Imagem = reader.GetString(4);
            }


            return(entertainmentModel);
        }
        public ActionResult LoadDataEList(EntertainmentModel EM)
        {
            List <string> ModelData = new List <string>();
            string        ConString = myConn.ConnectionString;
            SqlConnection conn      = new SqlConnection(ConString);

            conn.Open();
            try
            {
                using (SqlCommand command = new SqlCommand("EntertainTransac", conn))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@Option", System.Data.SqlDbType.Int);
                    command.Parameters["@Option"].Value = 1;
                    SqlDataAdapter sa = new SqlDataAdapter();
                    sa.SelectCommand = command;
                    sa.Fill(dt);
                }
            }
            catch (Exception ex) {
                return(View(ex.Message));
            }
            conn.Close();

            List <Dictionary <string, Object> > rows = new List <Dictionary <string, object> >();
            Dictionary <string, Object>         row;

            foreach (DataRow dr in dt.Rows)
            {
                row = new Dictionary <string, object>();
                foreach (DataColumn col in dt.Columns)
                {
                    row.Add(col.ColumnName, dr[col]);
                }
                rows.Add(row);
            }
            return(Json(rows));
        }
Example #7
0
        /// <summary>
        /// Ele vai pegar todos as informações da database e colocar em uma lista
        /// </summary>
        /// <param name="tipo">Se o tipo for 0 ele vai pegar as informações da database de jogos se for 1 ele vai pegar as de mangas</param>
        /// <returns></returns>
        public List <EntertainmentModel> FetchAll(int tipo)
        {
            List <EntertainmentModel> returnList = new List <EntertainmentModel>(); //Lista que será retornada no final da função
            SqlConnection             ligacao = new SqlConnection();                //acessando a database
            string tipoD = "", tipoS = "";

            if (tipo == 0)
            {
                tipoD = "GameDB";
                tipoS = "Games";
            }
            else if (tipo == 1)
            {
                tipoD = "MangaDB";
                tipoS = "Manga";
            }
            ligacao.ConnectionString = @"Server = (localdb)\MSSQLLocalDB; Database = " + tipoD + "; Trusted_Connection = True"; //acessando a database
            ligacao.Open();                                                                                                     //acessando a database
            SqlDataAdapter adaptador = new SqlDataAdapter("SELECT * FROM " + tipoS, ligacao);                                   //O adaptador vai peegar todas as informções da lista
            DataTable      dados = new DataTable();

            adaptador.Fill(dados);

            //colacando os dados na lista

            foreach (DataRow linha in dados.Rows)
            {
                EntertainmentModel entertainmentModel = new EntertainmentModel();
                entertainmentModel.Id     = Int32.Parse(linha["Id"].ToString());
                entertainmentModel.Nome   = linha["Nome"].ToString();
                entertainmentModel.Nota   = linha["Nota"].ToString();
                entertainmentModel.Resumo = linha["Resumo"].ToString();
                entertainmentModel.Imagem = linha["Imagem"].ToString();
                returnList.Add(entertainmentModel);
            }

            return(returnList);
        }