Ejemplo n.º 1
0
        public static bool Update(DepartmentCOMMON pDepart)
        {
            bool retorno = true;

            try
            {
                var conn = new SqlConnection(CadenaDeConexion);
                conn.Open();

                // 1. identificamos el store procedure a ejecutar
                SqlCommand cmd = new SqlCommand("Update_Department", conn);

                // 2. identificamos el tipo de ejecución, en este caso un SP
                cmd.CommandType = CommandType.StoredProcedure;

                // 3. en caso de que los lleve se ponen los parametros del SP
                cmd.Parameters.Add(new SqlParameter("@Id", pDepart.Id));
                cmd.Parameters.Add(new SqlParameter("@Name", pDepart.Name));
                foreach (CityCOMMON c in pDepart.ListCities)
                {
                    if (c.Id == 0)
                    {
                        Boolean allOk = CityPERS.Add(pDepart.Id, c);
                    }
                }
                // ejecutamos el store desde c#
                int rtn = cmd.ExecuteNonQuery();

                if (rtn <= 0)
                {
                    retorno = false;
                }

                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(retorno);
        }
Ejemplo n.º 2
0
        public static List <DepartmentCOMMON> SearchAll()
        {
            List <DepartmentCOMMON> retorno = new List <DepartmentCOMMON>();
            DepartmentCOMMON        Department;

            try
            {
                var conn = new SqlConnection(CadenaDeConexion);
                conn.Open();

                // 1. identificamos el store procedure a ejecutar
                SqlCommand cmd = new SqlCommand("Select_All_Department", conn);

                // 2. identificamos el tipo de ejecución, en este caso un SP
                cmd.CommandType = CommandType.StoredProcedure;

                // ejecutamos el store desde c#
                using (SqlDataReader oReader = cmd.ExecuteReader())
                {
                    while (oReader.Read())
                    {
                        Department      = new DepartmentCOMMON();
                        Department.Id   = short.Parse(oReader["Department_Id"].ToString());
                        Department.Name = oReader["Department_Name"].ToString();
                        try{
                            Department.ListCities = CityPERS.SearchAllofDepartment(Department.Id);
                        }
                        catch (Exception ex) {
                            throw ex;
                        }

                        retorno.Add(Department);
                    }

                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(retorno);
        }