public Task Handle(GetCompanyInfoRequest message, IMessageHandlerContext context) { CompanyInstance instance = CompanyDirectoryServiceDatabase.getInstance().GetCompanyInfo(message.companyInfo); String response = ""; return(context.Reply(new GetCompanyInfoResponse(true, response, instance))); }
public GetCompanyInfoResponse getCompanyInfo(string companyName) { string message = ""; CompanyInstance company = new CompanyInstance(companyName); bool result = false; if (openConnection() == true) { string query = @"SELECT * FROM businesses as b WHERE b.username='******'"; MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { result = true; company.companyName = reader.GetString("username"); company.email = reader.GetString("email"); company.locations = new string[] { reader.GetString("address") }; company.phoneNumber = reader.GetString("phonenumber"); } else { message = "No businesses with the name '" + companyName + "' found"; } closeConnection(); } else { message = "Could not establish connection to the database"; Debug.consoleMsg("Could not establish connection to the database"); } return(new GetCompanyInfoResponse(result, message, company)); }
public CompanyInstance getCompany(CompanyInstance company) { if (openConnection() == true) { string query = "SELECT * FROM companylisting WHERE companyname = '" + company.companyName + "';"; MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader reader = command.ExecuteReader(); CompanyInstance c = null; while (reader.Read()) { String[] list = new String[1]; list[0] = reader.GetString("locations"); c = new CompanyInstance(reader.GetString("companyname"), reader.GetString("phonenumber"), reader.GetString("email"), list); } closeConnection(); return(c); } else { throw new Exception("Unable to connect to database."); } }
public CompanyInstance GetCompanyInfo(CompanyInstance info) { if (openConnection() == true) { string query = @"SELECT * FROM company WHERE companyname = '" + info.companyName + "';"; MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader reader = command.ExecuteReader(); CompanyInstance value = new CompanyInstance(info.companyName); value.locations = new String[1]; while (reader.Read()) { value.phoneNumber = (String)reader["phonenumber"]; value.email = (String)reader["email"]; value.locations[0] = (String)reader["location"]; value.city = (String)reader["city"]; value.province = (String)reader["province"]; } closeConnection(); return(value); } else { Debug.consoleMsg("unable to connect to database"); return(null); } }
/// <summary> /// Gets the info of a single company /// </summary> /// <param name="companyName">Name of the company</param> public GetCompanyInfoResponse getCompanyInfo(string companyName) { bool result = false; string message = ""; CompanyInstance companyInst = new CompanyInstance(companyName); if (openConnection() == true) { string query = @"SELECT * FROM businessinfo as b WHERE b.username='******' COLLATE utf8_general_ci;"; MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { result = true; companyInst.companyName = reader.GetString("username"); companyInst.email = reader.GetString("email"); companyInst.locations = new string[] { reader.GetString("address") }; companyInst.phoneNumber = reader.GetString("phonenumber"); } else { message = "No company named '" + companyName + "' found"; } closeConnection(); } else { message = "Unable to connect to database"; Debug.consoleMsg("Unable to connect to database"); } return(new GetCompanyInfoResponse(result, message, companyInst)); }
public GetCompanyInfoResponse getCompany(GetCompanyInfoRequest request) { bool result = false; string message = ""; CompanyInstance company = null; string query = @"SELECT * FROM " + databaseName + @".companies WHERE companyname='" + request.companyInfo.companyName + @"';"; if (openConnection() == true) { try { MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader dataReader = command.ExecuteReader(); if (dataReader.Read()) { string companyname = dataReader.GetString("companyname"); string phonenumber = dataReader.GetString("phonenumber"); string email = dataReader.GetString("email"); string location = dataReader.GetString("location"); company = new CompanyInstance(companyname, phonenumber, email, new string[] { location }); } else { throw new Exception("Reader cannot read. DirectoryServiceDatabase Error."); } dataReader.Close(); result = true; } catch (MySqlException e) { Messages.Debug.consoleMsg("Unable to complete select from company into database." + " Error :" + e.Number + e.Message); Messages.Debug.consoleMsg("The query was:" + query); message = e.Message; } catch (Exception e) { Messages.Debug.consoleMsg("Unable to Unable to complete insert new user into database." + " Error:" + e.Message); message = e.Message; } finally { closeConnection(); } } else { message = "Unable to connect to database"; } return(new GetCompanyInfoResponse(result, message, company)); }
/// <summary> /// Saves the echo to the database /// This method will be called by the NServiceBus framework when an event of type "AsIsEchoEvent" is published. /// </summary> /// <param name="message">Information about the echo</param> /// <param name="context"></param> /// <returns>Nothing</returns> public Task Handle(AccountCreated message, IMessageHandlerContext context) { if (message.type == Messages.DataTypes.AccountType.business) { CompanyInstance inst = new CompanyInstance(message.username, message.phonenumber, message.email, new string[] { message.address }); DirectoryServiceDatabase.getInstance().saveCompany(inst); } return(Task.CompletedTask); }
public static string companyInstanceToString(CompanyInstance company) { string ret = company.companyName + ";" + company.phoneNumber + ";" + company.email + ";"; foreach (string i in company.locations) { ret += i + ";"; } return(ret.Substring(0, ret.Length - 1)); }
public Task Handle(AccountCreated message, IMessageHandlerContext context) { if (message.type == Messages.DataTypes.AccountType.business) { List <String> addresses = new List <string>(); addresses.Add(message.address); CompanyInstance company = new CompanyInstance(message.username, message.phonenumber, message.email, addresses.ToArray()); CompanyListingDatabase.getInstance().saveCompany(company); } return(Task.CompletedTask); }
public Task Handle(AccountCreated message, IMessageHandlerContext context) { //will need to change this String[] arr = new String[1]; arr[0] = message.address; if (message.type == Messages.DataTypes.AccountType.business) { CompanyInstance company = new CompanyInstance(message.username, message.phonenumber, message.email, arr, message.city, message.province); CompanyDirectoryServiceDatabase.getInstance().insertNewCompany(company); } return(Task.CompletedTask); }
/// <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) { Debug.consoleMsg("Got to GetCompanyInfoHandler"); CompanyInstance temp = CompanyServiceDatabase.getInstance().getCompanyInfo(message.companyInfo.companyName); //Format the company list so it looks like what it is below, With ; dividing the different companies //NARINDER string response = CompanyServiceDatabase.companyInstanceToString(temp); //The context is used to give a reply back to the endpoint that sent the request return(context.Reply(new ServiceBusResponse(true, response))); }
public void saveCompany(CompanyInstance company) { if (openConnection() == true) { string query = $@"INSERT INTO companylisting(timestamp, companyname, phonenumber, email, locations) VALUES('{DateTimeOffset.Now.ToUnixTimeSeconds().ToString()}', '{company.companyName}', '{company.phoneNumber}', '{company.email}', '{company.locations[0]}');"; MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); closeConnection(); } else { throw new Exception("Unable to connect to database."); } }
public ServiceBusResponse insertNewCompany(CompanyInstance info) { System.Diagnostics.Debug.WriteLine("-----------------Starting insertNewCompany----------------"); bool result = false; string message = ""; if (openConnection() == true) { string query = @"INSERT INTO company(companyname, phonenumber, email, location, city, province) " + @"VALUES('" + info.companyName + @"', '" + info.phoneNumber + @"', '" + info.email + @"', '" + info.locations[0] + @"', '" + info.city + @"', '" + info.province + @"');"; try { MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); result = true; } catch (MySqlException e) { Messages.Debug.consoleMsg("Unable to complete insert new user into database." + " Error :" + e.Number + e.Message); Messages.Debug.consoleMsg("The query was:" + query); message = e.Message; } catch (Exception e) { Messages.Debug.consoleMsg("Unable to Unable to complete insert new user into database." + " Error:" + e.Message); message = e.Message; } finally { closeConnection(); } } else { message = "Unable to connect to database"; } return(new ServiceBusResponse(result, message)); }
public Task Handle(GetCompanyInfoRequest message, IMessageHandlerContext context) { try { CompanyInstance company = CompanyListingDatabase.getInstance().getCompany(message.companyInfo); if (company == null) { return(context.Reply(new GetCompanyInfoResponse(false, "No company found", company))); } else { return(context.Reply(new GetCompanyInfoResponse(true, "Company info found", company))); } } catch (Exception err) { return(context.Reply(new GetCompanyInfoResponse(false, err.Message, null))); } }
/// <summary> /// Saves the foreward echo to the database /// </summary> /// <param name="company">Information about the company</param> public ServiceBusResponse saveCompany(CompanyInstance company) { bool result = false; string message = ""; if (openConnection() == true) { string query = @"INSERT INTO companies(companyname, phonenumber, email, location)" + @"VALUES('" + company.companyName + @"', '" + company.phoneNumber + @"', '" + company.email + @"', '" + company.locations[0] + @"');"; try { MySqlCommand command = new MySqlCommand(query, connection); command.ExecuteNonQuery(); result = true; } catch (MySqlException e) { Messages.Debug.consoleMsg("Unable to complete insert new company into database." + " Error :" + e.Number + e.Message); Messages.Debug.consoleMsg("The query was:" + query); message = e.Message; } catch (Exception e) { Messages.Debug.consoleMsg("Unable to complete insert new user into database." + " Error:" + e.Message); message = e.Message; } finally { closeConnection(); } } else { message = "Unable to connect to database"; } return(new ServiceBusResponse(result, message)); }
///<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)); } }
// will return null if cannot get company info public CompanyInstance getCompanyInfo(string companyName) { if (openConnection() == true) { string query = "SELECT * FROM " + dbname + ".companies" + " WHERE companyName = @Name;"; MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.AddWithValue("@Name", companyName); MySqlDataReader reader = command.ExecuteReader(); CompanyInstance ret = new CompanyInstance(companyName); List <string> locs = new List <string>(); if (reader.Read()) { do { ret.email = reader.GetString("email"); locs.Add(reader.GetString("locations")); ret.phoneNumber = reader.GetString("phonenumber"); } while (reader.Read()); } else { Debug.consoleMsg("Error: No such company: '" + companyName + "' in database"); return(null); } ret.locations = locs.ToArray <string>(); closeConnection(); return(ret); } else { Debug.consoleMsg("Unable to connect to database"); return(null); } }
// will throw error if it cannot save company public void saveCompany(CompanyInstance company) { if (openConnection() == true) { for (int i = 0; i < company.locations.Length; i++) { string query = "INSERT INTO companies(companyName,phoneNumber,email,locations)" + "VALUES(@Name,@Number,@Email,@Location);"; MySqlCommand command = new MySqlCommand(query, connection); command.Parameters.AddWithValue("@Name", company.companyName); command.Parameters.AddWithValue("@Number", company.phoneNumber); command.Parameters.AddWithValue("@Email", company.email); command.Parameters.AddWithValue("@Location", company.locations[i]); command.ExecuteNonQuery(); } closeConnection(); } else { Debug.consoleMsg("Unable to connect to database"); } }
/// <summary> /// Searches the database for a company matching the given name /// </summary> /// <param name="name">The name of the company to search for</param> /// <returns>Info about the company being returned</returns> public GetCompanyInfoResponse getCompanyInfo(GetCompanyInfoRequest request) { bool result = false; string response = ""; CompanyInstance requestData = request.companyInfo; if (openConnection() == true) { string query = @"SELECT * FROM " + databaseName + @".company " + @"WHERE companyname='" + requestData.companyName + @"';"; MySqlDataReader dataReader = null; CompanyInstance returnData = null; try { MySqlCommand command = new MySqlCommand(query, connection); dataReader = command.ExecuteReader(); if (!dataReader.Read()) { return(new GetCompanyInfoResponse(false, "No company with the given name exists in our database.", requestData)); } string companyName = dataReader.GetString("companyname"); string phoneNumber = dataReader.GetString("phonenumber"); string email = dataReader.GetString("email"); List <string> locations = new List <string>(); dataReader.Close(); query = @"SELECT * FROM " + databaseName + @".location " + @"WHERE companyname='" + requestData.companyName + @"';"; command = new MySqlCommand(query, connection); dataReader = command.ExecuteReader(); while (dataReader.Read()) { locations.Add(dataReader.GetString("address")); } returnData = new CompanyInstance( companyName, phoneNumber, email, locations.ToArray() ); result = true; } catch (Exception e) { response = e.Message; } finally { if (dataReader != null && dataReader.IsClosed == false) { dataReader.Close(); } closeConnection(); } return(new GetCompanyInfoResponse(result, response, returnData)); } return(new GetCompanyInfoResponse(false, "Unable to connect to database", null)); }
public GetCompanyInfoResponse(bool result, string response, CompanyInstance companyInfo) : base(result, response) { this.companyInfo = companyInfo; }
/// <summary> /// Saves the company records /// </summary> public static void SaveCompany(CompanyInstance objParams) { BrightPlatformEntities m_objBrightPlatformEntity = new BrightPlatformEntities(UserSession.EntityConnection); account objCompany = new account() { company_name = objParams.company_name, org_no = objParams.org_no, box_address = objParams.box_address, street_address = objParams.street_address, zipcode = objParams.zip_code, city = objParams.city, country = objParams.country, telephone = objParams.telephone, telefax = objParams.telefax, www = objParams.site, year_established = objParams.year_established, parent_company = objParams.parent_company, activity_code = objParams.activity_code, //activity_code_description = objParams.activity_code_description, activity_code_2 = objParams.activity_code_2, //activity_code2_description = objParams.activity_code_2_description, currency = objParams.currency, fiscal = objParams.fiscal, //consolidated_figures = objParams.consolidated_figures, turnover = objParams.turnover, export = objParams.export, result = objParams.result, sales_abroad = objParams.sales_abroad, employees_abroad = objParams.employees_abroad, employees_total = objParams.employees_total, //net_interest_incom = objParams.net_interest_income, //gross_premiums = objParams.gross_premiums, validated = true, created_date = DateTime.Now, created_by = UserSession.CurrentUser.UserId }; m_objBrightPlatformEntity.accounts.AddObject(objCompany); m_objBrightPlatformEntity.SaveChanges(); //if (objParams.activity_code.Length > 0) // SaveActivityCode(objParams.activity_code, objParams.activity_code_description); }
/// <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")); }
public CompanyListingsEvent(CompanyInstance comp) { company = comp; }
public GetCompanyInfoRequest(CompanyInstance companyInfo) : base(CompanyDirectoryRequest.GetCompanyInfo) { this.companyInfo = companyInfo; }