/// <summary> /// Searches for company information /// </summary> /// <param name="message">Information about the company</param> /// <param name="context">Used to access information regarding the endpoints used for this handle</param> /// <returns>The response to be sent back to the calling process</returns> public Task Handle(GetCompanyInfoRequest message, IMessageHandlerContext context) { GetCompanyInfoResponse infoResponse = CompanyListingsDatabase.getInstance().getCompanyInfo(message); // Get Reviews string result = ""; if (infoResponse.result) { try { HttpClient getRevs = new HttpClient(); //TODO: --ENSURE THIS IS CORRECT BEFORE DEPLOYMENT-- string uri = "http://localhost:50151/DBLS/GetCompanyReviews/%7B%22companyName%22:%22" + infoResponse.companyInfo.companyName + "%22%7D"; result = getRevs.GetStringAsync(uri).Result; System.Diagnostics.Debug.WriteLine(result); ReviewList r = new JavaScriptSerializer().Deserialize <ReviewList>(result); infoResponse.companyInfo.reviewList = r; } catch (Exception a) { infoResponse.result = false; infoResponse.response = "Issue communicating with review system."; } } return(context.Reply(infoResponse)); }
/// <summary> /// Searches the db, and returns it's result back to the calling endpoint. /// </summary> /// <param name="message">Information about the echo</param> /// <param name="context">Used to access information regarding the endpoints used for this handle</param> /// <returns>The response to be sent back to the calling process</returns> public Task Handle(GetCompanyInfoRequest request, IMessageHandlerContext context) { GetCompanyInfoResponse response = CompanyDirectoryServiceDatabase.getInstance().getCompanyInfo(request.companyInfo.companyName); //The context is used to give a reply back to the endpoint that sent the request return(context.Reply(response)); }
/// <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> /// Saves the echo to the database, reverses the data, and returns it back to the calling endpoint. /// </summary> /// <param name="message">Information about the echo</param> /// <param name="context">Used to access information regarding the endpoints used for this handle</param> /// <returns>The response to be sent back to the calling process</returns> public Task Handle(GetCompanyInfoRequest message, IMessageHandlerContext context) { //Save the echo to the database GetCompanyInfoResponse resp = DirectoryServiceDatabase.getInstance().getCompany(message); // Do something here and return a COMPANYSEARCHRESPONSE //The context is used to give a reply back to the endpoint that sent the request return(context.Reply(resp)); }
/// <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")); }
/// <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")); }
/// <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")); }
///<summary> ///Retrieves company info based on company name ///</summary> ///<param name="compo">Information about the company</param> public GetCompanyInfoResponse getCompanyInfo(GetCompanyInfoRequest compo) { if (openConnection()) { GetCompanyInfoResponse toReturn = new GetCompanyInfoResponse(false, "Could not find any company information.", null); try { string query = @"SELECT * FROM " + databaseName + @".Companies " + @"WHERE companyName='" + compo.companyInfo.companyName + @"';"; MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader dataReader = command.ExecuteReader(); if (dataReader.Read()) { string[] loc = new string[1]; loc[0] = dataReader.GetString("location"); CompanyInstance cump = new CompanyInstance(dataReader.GetString("companyName"), dataReader.GetString("phoneNumber"), dataReader.GetString("email"), loc); toReturn = new GetCompanyInfoResponse(true, "Successfully retrieved company information.", cump); } } catch (Exception a) { Console.WriteLine("Issue saving company to the database."); Console.WriteLine(a.Message); } finally { closeConnection(); } return(toReturn); } else { Debug.consoleMsg("Unable to connect to database"); return(new GetCompanyInfoResponse(false, "Could not find any company information.", null)); } }
/// <summary> /// Searches the CompanyDirectory database for a company matching the one in the comand object and returns its information if it exists /// </summary> /// <param name="message">The command object that was sent</param> /// <param name="context">Contains information relevent to the current command being handled.</param> /// <returns>A CompanyInstance response containing information about the requested company, or null if the company was not found</returns> public Task Handle(GetCompanyInfoRequest message, IMessageHandlerContext context) { GetCompanyInfoResponse dbResponse = CompanyDirectoryDB.getInstance().getCompanyInfo(message); return(context.Reply(dbResponse)); }
/// <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")); }
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")); }