Beispiel #1
0
        public IActionResult GetUniversitiesByState(string state)
        {
            string apiExtension = "school.state=" + state;
            string apiFields    = "&_fields=id,school.school_url,school.name,2018.student.size,school.zip,latest.cost.tuition.out_of_state,school.accreditor_code,";
            string apiKey       = "&api_key=ck1LVrQunLhfsjSgoithxWggF6ZbNSp3SvalD4d4";
            string API_PATH     = BASE_URL + apiExtension + apiFields + apiKey;

            string         responseString = "";
            UniversityData data           = null;

            // Connect to the IEXTrading API and retrieve information
            httpClient.BaseAddress = new Uri(API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(API_PATH).GetAwaiter().GetResult();

            // Read the Json objects in the API response
            if (response.IsSuccessStatusCode)
            {
                responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                responseString = responseString.Replace("school.name", "schoolName");
                responseString = responseString.Replace("school.school_url", "schoolUrl");
                responseString = responseString.Replace("2018.student.size", "studentSize");
                responseString = responseString.Replace("school.zip", "schoolZip");
                responseString = responseString.Replace("latest.cost.tuition.out_of_state", "tuitionOutState");
                responseString = responseString.Replace("school.accreditor_code", "accCode");
            }

            // Parse the Json strings as C# objects
            if (!responseString.Equals(""))
            {
                data = System.Text.Json.JsonSerializer.Deserialize <UniversityData>(responseString);
                //data = JsonConvert.DeserializeObject<UniversityData>(responseString);
            }

            return(View("Explore", data));
        }
        /// <summary>
        /// Lista de universidades
        /// </summary>
        /// <returns></returns>
        public List <object> GetUniversitys()
        {
            List <Object> dataList = new List <object>();

            using (tecAirlinesEntities entities = new tecAirlinesEntities())
            {
                try
                {
                    var universityList = entities.Universidads.ToList();
                    int n = universityList.Count;
                    if (n == 0)
                    {
                        dataList = null;
                        return(dataList);
                    }
                    else
                    {
                        for (int i = 0; i < universityList.Count; ++i)
                        {
                            UniversityData data = new UniversityData();
                            data.Identificador = universityList.ElementAt(i).Identificador;
                            data.Nombre        = universityList.ElementAt(i).Nombre;

                            dataList.Add(data);
                        }
                        return(dataList);
                    }
                }
                catch
                {
                    dataList = null;
                    return(dataList);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Read records from database
        /// </summary>
        /// <returns></returns>
        private String getRecordsFromDB()
        {
            String recordsList = null;

            try
            {
                // SQL query to read college records from database
                SqlCommand    sqlQury = new SqlCommand("SELECT * FROM University", _sqlConnection);
                SqlDataReader reader  = sqlQury.ExecuteReader();

                // Build a list of colleges
                List <mqHelpers.UniversityData> ciList = new List <mqHelpers.UniversityData>();

                // Iterate through all records we have got and build a list
                while (reader.Read())
                {
                    UniversityData ci = new UniversityData();

                    ci.universityName   = reader[Constants.SQL_COLMN_COLLEGE_NAME].ToString();
                    ci.universityAdress = reader[Constants.SQL_COLMN_COLLEGE_ADRESS].ToString();
                    ci.universityRating = reader[Constants.SQL_COLMN_COLLEGE_REATING].ToString();
                    ciList.Add(ci);
                }

                // Convert the list to a JSon object
                JSonHelper js = new JSonHelper();
                recordsList = js.ConvertObjectToJSon(ciList);
            }
            catch (Exception ex)
            {
                Trace.TraceInformation("Failed reading records" + ex.ToString());
            }
            return(recordsList);
        }
        public IActionResult GetUniversitiesByState(string state)
        {
            string apiExtension = "school.state=" + state;
            //  apiFields = "&_fields=id,school.school_url,school.name,2018.student.size,school.city,latest.cost.tuition.out_of_state,school.accreditor_code,&per_page=30";
            string API_PATH = BASE_URL + apiExtension + apiFields + apiKey;

            string         responseString = "";
            UniversityData data           = null;


            httpClient.BaseAddress = new Uri(API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(API_PATH).GetAwaiter().GetResult();

            // Read the Json objects in the API response
            if (response.IsSuccessStatusCode)
            {
                responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                responseString = responseString.Replace("school.name", "schoolName");
                responseString = responseString.Replace("school.school_url", "schoolUrl");
                responseString = responseString.Replace("2018.student.size", "studentSize");
                responseString = responseString.Replace("school.city", "schoolCity");
                responseString = responseString.Replace("latest.cost.tuition.out_of_state", "tuitionOutState");
                responseString = responseString.Replace("school.accreditor_code", "accCode");
                responseString = responseString.Replace("id", "uId");
            }

            // Parse the Json strings as C# objects
            if (!responseString.Equals(""))
            {
                data = System.Text.Json.JsonSerializer.Deserialize <UniversityData>(responseString);
            }

            return(View("Explore", data));
        }
Beispiel #5
0
        public IActionResult GetUniversitiesByStateChart(string state)
        {
            string apiExtension = "school.state=" + state + "&latest.cost.tuition.out_of_state__range=100..";

            apiFields = "&_fields=id,school.school_url,school.name,2018.student.size,school.city,latest.cost.tuition.out_of_state,school.accreditor_code,&per_page=5";

            string         API_PATH       = BASE_URL + apiExtension + apiFields + apiKey;
            string         responseString = "";
            UniversityData data           = null;

            // Connect to the IEXTrading API and retrieve information
            httpClient.BaseAddress = new Uri(API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(API_PATH).GetAwaiter().GetResult();

            // Read the Json objects in the API response
            if (response.IsSuccessStatusCode)
            {
                responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                responseString = replaceString(responseString);
            }

            // Parse the Json strings as C# objects
            if (!responseString.Equals(""))
            {
                data = System.Text.Json.JsonSerializer.Deserialize <UniversityData>(responseString);
            }
            ViewBag.State = state;
            return(View("Charts", data));
        }
        /// <summary>
        /// Get de un vuelo especifico
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public UniversityData GetUniversity(int id)
        {
            UniversityData university = new UniversityData();

            using (tecAirlinesEntities entities = new tecAirlinesEntities())
            {
                try
                {
                    if (!this.ExistUniversity(id))
                    {
                        university = null;
                        return(university);
                    }
                    var universityx = entities.Universidads.Find(id);
                    university.Identificador = universityx.Identificador;
                    university.Nombre        = universityx.Nombre;


                    return(university);
                }
                catch (Exception)
                {
                    university = null;
                    return(university);
                }
            }
        }
Beispiel #7
0
        public IActionResult Details(int id)
        {
            string apiExtension = "id=" + id;

            apiFields = "&_fields=id,school.school_url,school.name,2018.student.size,school.city,latest.cost.tuition.out_of_state,school.accreditor_code,&per_page=5";

            string         API_PATH       = BASE_URL + apiExtension + apiFields + apiKey;
            string         responseString = "";
            UniversityData data           = null;


            httpClient.BaseAddress = new Uri(API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(API_PATH).GetAwaiter().GetResult();


            if (response.IsSuccessStatusCode)
            {
                responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                responseString = replaceString(responseString);
            }


            if (!responseString.Equals(""))
            {
                data = System.Text.Json.JsonSerializer.Deserialize <UniversityData>(responseString);
            }

            return(View(data));
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            UniversityData           universityData           = new UniversityData();
            UniversityCatalog        universityCatalog        = new UniversityCatalog(universityData);
            UniversityAdministration universityAdministration = new UniversityAdministration(universityData);

            ScreenManager screenManager = new ScreenManager(universityAdministration, universityCatalog);

            screenManager.Start();
        }
        // GET: Students
        public async Task <IActionResult> Index()
        {
            var viewModel = new UniversityData();

            viewModel.Universities = await _context.Universities
                                     .Include(i => i.Departments)
                                     .ToListAsync();

            return(View(viewModel));
        }
Beispiel #10
0
        /// <summary>
        /// Gets the data from the Graph object and in case it does not exist in the
        /// database it is addded.
        /// </summary>
        /// <param name="givenUser"></param>
        /// <returns>UserData object pointing to the Database</returns>
        public static async Task <UserData> ToDBObject(this User givenUser)
        {
            Dictionary <string, string> data = givenUser.GetDataFromGraphUser();

            using MSPAppContext dbContext = new MSPAppContext();
            string mspMail        = data[Constants.MailKey];
            string countryName    = data[Constants.CountryKey];
            string universityName = data[Constants.UniversityKey];

            if (!dbContext.UserData.Any(x => x.Mspmail == mspMail))
            {
                if (!dbContext.CountryData.Any(x => x.Name == countryName))
                {
                    await dbContext.CountryData.AddAsync(
                        new CountryData
                    {
                        Name = countryName,
                        Id   = dbContext.CountryData.Count()
                    });

                    dbContext.SaveChanges();
                }
                CountryData currentCountry =
                    dbContext.CountryData.FirstOrDefault(x => x.Name == countryName);

                if (!dbContext.UniversityData.Any(x => x.Name == universityName))
                {
                    await dbContext.UniversityData.AddAsync(
                        new UniversityData
                    {
                        Name = universityName,
                        Id   = dbContext.UniversityData.Count()
                    });

                    dbContext.SaveChanges();
                }
                UniversityData currentUniversity =
                    dbContext.UniversityData.FirstOrDefault(x => x.Name == universityName);

                await dbContext.UserData.AddAsync(
                    new UserData
                {
                    Mspmail      = mspMail,
                    CountryId    = currentCountry.Id,
                    UniversityId = currentUniversity.Id,
                    Name         = data[Constants.NameKey],
                    Id           = dbContext.UserData.Count()
                });

                await dbContext.SaveChangesAsync();
            }

            return(dbContext.UserData.FirstOrDefault(x => x.Mspmail == mspMail));
        }
        public IActionResult GetUniversitiesByName(string universityName)
        {
            if (universityName != null)
            {
                universityName = universityName.Replace(" ", "%20");
            }
            string apiExtension = "school.name=" + universityName;

            string API_PATH = BASE_URL + apiExtension + apiFields + apiKey;

            string         responseString = "";
            UniversityData data           = null;

            httpClient.BaseAddress = new Uri(API_PATH);
            HttpResponseMessage response = httpClient.GetAsync(API_PATH).GetAwaiter().GetResult();

            // Read the Json objects in the API response
            if (response.IsSuccessStatusCode)
            {
                responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                responseString = responseString.Replace("school.name", "schoolName");
                responseString = responseString.Replace("school.school_url", "schoolUrl");
                responseString = responseString.Replace("2018.student.size", "studentSize");
                responseString = responseString.Replace("school.city", "schoolCity");
                responseString = responseString.Replace("latest.cost.tuition.out_of_state", "tuitionOutState");
                responseString = responseString.Replace("school.accreditor_code", "accCode");
                responseString = responseString.Replace("id", "uId");
            }

            // Parse the Json strings as C# objects
            if (!responseString.Equals(""))
            {
                data = System.Text.Json.JsonSerializer.Deserialize <UniversityData>(responseString);

                //data = JsonConvert.DeserializeObject<UniversityData>(responseString);
            }
            ViewBag.search = "name";

            foreach (Results item in data.results)
            {
                applicationDbContext.Results.Add(item);
            }

            return(View("Explore", data));
        }
Beispiel #12
0
 public IHttpActionResult AddUniversity([FromBody] UniversityData data)
 {
     if (data == null)
     {
         //Bad request code 400
         return(BadRequest());
     }
     if (universityLogic.AddUniversity(data))
     {
         //petición correcta y se ha creado un nuevo recurso code 201
         return(StatusCode(HttpStatusCode.Created));
     }
     else
     {
         //No se pudo crear el recurso por un error interno code 500
         return(InternalServerError());
     }
 }
Beispiel #13
0
        /// <summary>
        /// Actualizar un universidad
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool UpdateUniversity(UniversityData data)
        {
            using (tecAirlinesEntities entities = new tecAirlinesEntities())
            {
                try
                {
                    var university = entities.Universidads.Find(data.Identificador);

                    university.Identificador = data.Identificador;
                    university.Nombre        = data.Nombre;

                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
Beispiel #14
0
        public IHttpActionResult GetUniversity(int id)
        {
            if (!universityLogic.ExistUniversity(id))
            {
                //No se encontró el recurso code 404
                return(NotFound());
            }
            UniversityData user = universityLogic.GetUniversity(id);

            if (user != null)
            {
                // ok code 200
                return(Ok(user));
            }
            else
            {
                //No se pudo crear el recurso por un error interno code 500
                return(InternalServerError());
            }
        }
Beispiel #15
0
        /// <summary>
        /// Agrega un nuevo universidad
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool AddUniversity(UniversityData data)
        {
            using (tecAirlinesEntities entities = new tecAirlinesEntities())
            {
                Universidad newUniversity = new Universidad();
                newUniversity.Identificador = data.Identificador;
                newUniversity.Nombre        = data.Nombre;


                try
                {
                    //entities.Universidads.Add(newUniversity);
                    //entities.SaveChanges();
                    int entity = entities.udsp_ins_universidad(data.Nombre);
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
Beispiel #16
0
 public IHttpActionResult UpdateUniversity([FromBody] UniversityData data)
 {
     if (data == null)
     {
         //Bad request code 400
         return(BadRequest());
     }
     if (!universityLogic.ExistUniversity(data.Identificador))
     {
         //petición correcta pero no pudo ser procesada porque no existe el archivo code 404
         return(NotFound());
     }
     if (universityLogic.UpdateUniversity(data))
     {
         //petición correcta y se ha creado un nuevo recurso code 200 ok
         return(Ok());
     }
     else
     {
         //No se pudo crear el recurso por un error  code 500
         return(InternalServerError());
     }
 }
Beispiel #17
0
 public UniversityCatalog(UniversityData universityData)
 {
     _universityData = universityData;
 }
Beispiel #18
0
 public UniversityAdministration(UniversityData universityData)
 {
     _universityData = universityData;
 }