/// <summary>
        /// This function is called when the client navigates to *hostname*/CompanyListings/DisplayCompany/*info*
        /// </summary>
        /// <param name="id">The name of the company whos info is to be displayed</param>
        /// <returns>A view to be sent to the client</returns>
        public ActionResult DisplayCompany(string id)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(id))
            {
                return(View("Index"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ViewBag.CompanyName = id;

            GetCompanyInfoRequest  infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            GetCompanyInfoResponse infoResponse = connection.getCompanyInfo(infoRequest);

            ViewBag.CompanyInfo = infoResponse.companyInfo;

            return(View("DisplayCompany"));
        }
        /// <summary>
        /// This function is called when the client navigates to *hostname*/CompanyListings/DisplayCompany/*info*
        /// </summary>
        /// <param name="id">The name of the company whos info is to be displayed</param>
        /// <returns>A view to be sent to the client</returns>
        public ActionResult DisplayCompany(string id)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(id))
            {
                return(View("Index"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ViewBag.CompanyName = id;

            GetCompanyInfoRequest  infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            GetCompanyInfoResponse infoResponse = connection.getCompanyInfo(infoRequest);

            ViewBag.CompanyInfo = infoResponse.companyInfo;

            GetWeatherRequest  weatherRequest  = new GetWeatherRequest(infoResponse.companyInfo.city, infoResponse.companyInfo.province);
            GetWeatherResponse weatherResponse = connection.getWeather(weatherRequest);

            ViewBag.foundWeather = weatherResponse.result;
            if (weatherResponse.result)
            {
                ViewBag.currentTemp = weatherResponse.weather.Temperature.Metric.Value;
                ViewBag.feelTemp    = weatherResponse.weather.RealFeelTemperature.Metric.Value;
                ViewBag.weatherText = weatherResponse.weather.WeatherText;
                WeatherIcon url = new WeatherIcon();
                ViewBag.weatherIconURL = url.weatherURL[weatherResponse.weather.WeatherIcon];
            }
            else
            {
                ViewBag.currentTemp = "N/A";
                ViewBag.feelTemp    = "N/A";
                ViewBag.weatherText = "N/A";
            }

            string            company        = ViewBag.CompanyName;
            GetReviewRequest  reviewRequest  = new GetReviewRequest(company);
            GetReviewResponse reviewResponse = connection.getCompanyReviews(reviewRequest);

            ViewBag.companyReviews = reviewResponse.reviews;

            return(View("DisplayCompany"));
        }
Esempio n. 3
0
        /// <summary>
        /// This function is called when the client navigates to *hostname*/CompanyListings/DisplayCompany/*info*
        /// </summary>
        /// <param name="id">The name of the company whos info is to be displayed</param>
        /// <returns>A view to be sent to the client</returns>
        public ActionResult DisplayCompany(string id)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(id))
            {
                return(View("Index"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ViewBag.CompanyName = id;
            companyNameeeee     = id;
            string location = "";

            GetCompanyInfoRequest  infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            GetCompanyInfoResponse infoResponse = connection.getCompanyInfo(infoRequest);

            ViewBag.CompanyInfo = infoResponse.companyInfo;
            location            = infoResponse.companyInfo.locations[0];

            //CompanyReviewSearchRequest reviewRequest = new CompanyReviewSearchRequest(id);
            // CompanyReviewResponse reviewResponse = connection.searchCompanyReview(reviewRequest);
            // ViewBag.Reviewlist = reviewResponse.reviews;

            WeatherNeededRequest  weatherRequest  = new WeatherNeededRequest(location);
            WeatherNeededResponse weatherResponse = connection.getWeatherData(weatherRequest);

            if (!weatherResponse.result)
            {
                WeatherData wd = new WeatherData("not available", "not available", "not available", "not available", "not available", "not available");
                ViewBag.WeatherData = wd;
            }
            else
            {
                ViewBag.WeatherData = weatherResponse.weatherData;
            }



            return(View("DisplayCompany"));
        }
Esempio n. 4
0
        /// <summary>
        /// This function is called when the client navigates to *hostname*/CompanyListings/DisplayCompany/*info*
        /// </summary>
        /// <param name="id">The name of the company whos info is to be displayed</param>
        /// <returns>A view to be sent to the client</returns>
        public ActionResult DisplayCompany(string id)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if (String.IsNullOrWhiteSpace(id))
            {
                return(View("Index"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ViewBag.CompanyName = id;


            GetCompanyInfoRequest  infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            GetCompanyInfoResponse infoResponse = connection.getCompanyInfo(infoRequest);

            ViewBag.CompanyInfo = infoResponse.companyInfo;

            if (infoResponse.result)
            {
                GetCompanyReviewsRequest  request = new GetCompanyReviewsRequest(id);
                GetCompanyReviewsResponse result  = connection.getReviews(request);
                ViewBag.Reviews = result;
            }
            else
            {
                return(View("Index"));
            }

            WeatherRequest  weatherRequest  = new WeatherRequest(infoResponse.companyInfo.locations[0]);
            WeatherResponse weatherResponse = connection.getWeather(weatherRequest);

            ViewBag.WeatherResponse = weatherResponse;

            return(View("DisplayCompany"));
        }
Esempio n. 5
0
        /// <summary>
        /// This function is called when the client navigates to *hostname*/CompanyListings/DisplayCompany/*info*
        /// </summary>
        /// <param name="id">The name of the company whos info is to be displayed</param>
        /// <returns>A view to be sent to the client</returns>
        public ActionResult DisplayCompany(string id)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(id))
            {
                return(View("Index"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ViewBag.CompanyName = id;

            GetCompanyInfoRequest infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            ServiceBusResponse    infoResponse = connection.getCompanyInfo(infoRequest);



            String[] responseToArray = infoResponse.response.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            String[] locations       = new String[responseToArray.Length - 3];

            Array.Copy(responseToArray, 3, locations, 0, responseToArray.Length - 3);
            CompanyInstance value = new CompanyInstance(responseToArray[0], responseToArray[1], responseToArray[2], locations);

            ViewBag.CompanyInfo = value;
            ViewBag.username    = Globals.getUser();
            ViewBag.time        = DateTime.Now.ToString();


            //Harjee format the string into an array or something, then display it nicely on the view
            string reviews = GetReview(value.companyName);

            if (!reviews.Contains(":]"))
            {
                JObject json = JObject.Parse(reviews);

                JProperty allReviews = json.Property("reviews");

                string   totalReviews       = allReviews.Value.ToString();
                string[] unformattedResults = totalReviews.Split(',');

                for (int i = 4; i < unformattedResults.Length; i += 5)
                {
                    int position = unformattedResults[i].IndexOf('}');

                    if (position < 0)
                    {
                        position = unformattedResults[i].IndexOf(']');
                    }

                    if (position >= 0)
                    {
                        unformattedResults[i] = unformattedResults[i].Substring(0, position);
                    }
                }
                if (unformattedResults.Length > 2)
                {
                    for (int i = 0; i < unformattedResults.Length; i += 5)
                    {
                        int      reviewNumber = (i / 5) + 1;
                        string[] temp         = unformattedResults[i + 1].Split(':');
                        ViewBag.reviews += "Review #" + reviewNumber + ": ";
                        ViewBag.reviews += temp[1];
                        ViewBag.reviews += " <br/> ";

                        temp             = unformattedResults[i + 2].Split(':');
                        ViewBag.reviews += "Stars: ";
                        ViewBag.reviews += temp[1];
                        ViewBag.reviews += " <br/> ";

                        temp             = unformattedResults[i + 3].Split(':');
                        ViewBag.reviews += "Timestamp: ";
                        ViewBag.reviews += temp[1];
                        ViewBag.reviews += " <br/> ";

                        temp             = unformattedResults[i + 4].Split(':');
                        ViewBag.reviews += "Username: "******" <br/> <br/> ";
                    }

                    ViewBag.reviews += " <br/> ";
                }
            }

            else
            {
                ViewBag.reviews = " No reviews found <br/> ";
            }

            //Call Weather Service

            WeatherServiceRequest  info     = new WeatherServiceRequest(value.locations[0]);
            WeatherServiceResponse response = (WeatherServiceResponse)connection.getWeather(info);

            ViewBag.weatherText         = response.returnData.weatherText;
            ViewBag.temperature         = response.returnData.temperature;
            ViewBag.realFeelTemperature = response.returnData.realFeelTemperature;
            if (response.returnData.weatherIcon < 10)
            {
                ViewBag.weatherIcon = "https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/0" + response.returnData.weatherIcon + "-s.png";
            }
            else
            {
                ViewBag.weatherIcon = "https://apidev.accuweather.com/developers/Media/Default/WeatherIcons/" + response.returnData.weatherIcon + "-s.png";
            }


            return(View("DisplayCompany"));
        }
        /// <summary>
        /// This function is called when the client navigates to *hostname*/CompanyListings/DisplayCompany/*info*
        /// </summary>
        /// <param name="id">The name of the company whos info is to be displayed</param>
        /// <returns>A view to be sent to the client</returns>
        public ActionResult DisplayCompany(string id)
        {
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            if ("".Equals(id))
            {
                return(View("Index"));
            }

            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                return(RedirectToAction("Index", "Authentication"));
            }

            ViewBag.CompanyName = id;
            GetCompanyInfoRequest  infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            GetCompanyInfoResponse infoResponse = connection.getCompanyInfo(infoRequest);

            if (infoResponse.result)
            {
                ViewBag.CheckReviews = true;
                ViewBag.CompanyInfo  = infoResponse.companyInfo;
                if (infoResponse.companyInfo.reviewList.reviews == null)
                {
                    ViewBag.CheckReviews = false;
                }
                else
                {
                    List <ReviewInstance> r     = infoResponse.companyInfo.reviewList.reviews;
                    string[] timestamp_readable = new string[r.Count];

                    for (int i = 0; i < timestamp_readable.Length; i++)
                    {
                        System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
                        dtDateTime            = dtDateTime.AddSeconds(Convert.ToInt64(r[i].timestamp)).ToLocalTime();
                        timestamp_readable[i] = Convert.ToString(dtDateTime);
                    }
                    ViewBag.Timestamp = timestamp_readable;
                }
            }

            //Still assume location array is of one value.
            GetWeatherRequest weatherRequest = new GetWeatherRequest(new CompanyWeather {
                location = infoResponse.companyInfo.locations[0]
            });
            GetWeatherResponse weatherResponse = connection.getWeather(weatherRequest);

            if (!weatherResponse.result)
            {
                ViewBag.success = false;
            }
            else
            {
                ViewBag.success     = true;
                ViewBag.realFeel    = weatherResponse.companyWeather.realFeelTemperature;
                ViewBag.temp        = weatherResponse.companyWeather.temperature;
                ViewBag.weatherText = weatherResponse.companyWeather.weatherText;
            }

            return(View("DisplayCompany"));
        }
Esempio n. 7
0
        public ActionResult DisplayReviews(string id)
        {
            //Check if user is logged in
            if (Globals.isLoggedIn() == false)
            {
                return(RedirectToAction("Index", "Authentication"));
            }
            //Check the the company name was not null
            if ("".Equals(id))
            {
                return(View("Index"));
            }
            ViewBag.CompanyName = id;
            ServiceBusConnection connection = ConnectionManager.getConnectionObject(Globals.getUser());

            if (connection == null)
            {
                //If can't connect to db, return false to view
                ViewBag.CompanyExists = false;
                return(View("DisplayReviews"));
            }

            GetCompanyInfoRequest  infoRequest  = new GetCompanyInfoRequest(new CompanyInstance(id));
            GetCompanyInfoResponse infoResponse = connection.getCompanyInfo(infoRequest);

            if (!infoResponse.result)
            {
                //If company doesn't exist in db, return false to view
                ViewBag.CompanyExists = false;
                return(View("DisplayReviews"));
            }
            //Otherwise company eixsts
            ViewBag.CompanyExists = true;

            var companyReviewClient = new HttpClient();
            var jsonObject          = JsonConvert.SerializeObject(new CompanyName()
            {
                companyName = id
            });
            var stringContent = new StringContent(jsonObject, Encoding.UTF8, "application/json");
            //This url is the one where the rest call it to
            var         res       = companyReviewClient.PostAsync("http://35.226.157.66/Home/GetCompanyReview", stringContent).Result.Content.ReadAsStringAsync().Result;
            GetResponse resObject = JsonConvert.DeserializeObject <GetResponse>(res);

            int?   totalStars   = 0;
            int    totalReviews = 0;
            string avgStars     = "0.00";

            //Check if any reviews were returned
            if (resObject.reviews != null)
            {
                //Loop reviews calculating avg stars
                foreach (var review in resObject.reviews)
                {
                    totalStars += review.stars;
                    totalReviews++;
                }
                avgStars = ((float)totalStars / totalReviews).ToString("0.00");
            }
            //Pass all to display
            ViewBag.AvgStars   = avgStars;
            ViewBag.ReviewList = resObject.reviews;
            return(View("DisplayReviews"));
        }