// GET: Reviews/GetCompanyReviews/{"companyName":"SEARCH NAME HERE"} public JsonResult GetCompanyReviews(string id) { List <CompanyReview> result = null; try { LinkDatabase db = LinkDatabase.getInstance(); JObject JsonObj = JObject.Parse(id); string companyName = JsonObj.GetValue("companyName").ToObject <string>(); result = db.readReview(companyName); } catch (Exception e) { return(Json(new { response = "operation failed" }, JsonRequestBehavior.AllowGet)); } if (result == null || result.Count == 0) { return(Json(new { response = "company does not exist" }, JsonRequestBehavior.AllowGet)); } else { return(Json(result, "application/json", JsonRequestBehavior.AllowGet)); } }
//Action to redirect to public ActionResult Go(string id = null) { //Get the db instance var dbInstance = LinkDatabase.getInstance(); if (id != null) { int decoding = Shortener.GetLongDecoding(id); try { string longUrl = dbInstance.getLongUrl(decoding.ToString()); //Ideally, with the above ID we will query the DB and get the respective url and redirect to that page //Response.Redirect(longUrl); return(new RedirectResult(longUrl)); } catch (ArgumentException) { //If long url couldn't be found, redirect back to our homepage return(RedirectToAction("LinkShortener", "Home")); } } else { //Otherwise, redirect back to our homepage return(RedirectToAction("LinkShortener", "Home")); } }
public ActionResult GetCompanyReview(string id) { LinkDatabase database = LinkDatabase.getInstance(); ViewBag.Json = database.getReview(id); return(Json(database.getReview(id))); }
public ActionResult About() { LinkDatabase database = LinkDatabase.getInstance(); //Creates DB instance string resultLong = database.getLongUrl(Request.QueryString["id"]); //Returns long URL based on key return(new RedirectResult(resultLong)); //Redirects user to intended page }
public ActionResult SaveCompanyReview(int?id) { Stream req = Request.InputStream; req.Seek(0, System.IO.SeekOrigin.Begin); string json = new StreamReader(req).ReadToEnd(); LinkDatabase database = LinkDatabase.getInstance(); //Creates DB instance ViewBag.Json = database.saveReview(json); return(View()); }
public ActionResult Index(string URL) { LinkDatabase dataBase = LinkDatabase.getInstance(); //Create DB instance string key = dataBase.saveLongURL(URL); //Saves long URL to DB and returns ID key string valueShort = Globals.getIp() + "/home/about?id=" + key; //Appends key returned from DB to shortened URL ViewBag.MyMessage = valueShort; //Places shortened URL in view bag to be dislayed in view return(View()); }
public void Go(string id = null) { var dbInstance = LinkDatabase.getInstance(); if (id != null) { string origUrl = dbInstance.getLongUrl(id); //Ideally, with the above ID we will squery the DB and get the respective url and redirect to that page Response.Redirect(origUrl); } else { //Otherwise, redirect back to our homepage Response.Redirect(HttpContext.Request.Url.Host); } }
public ActionResult LinkShortener(string longURL) { var dbInstance = LinkDatabase.getInstance(); dbInstance.createDB(); string shortURL = longURL; ViewData["Title"] = "Link Shortener"; //If string from post was null, then this field isn't displayed if (longURL != null) { //Randomly choose and int... This will actually be the PK value in the DB string shortUrl_iD = dbInstance.saveLongURL(longURL); string urlHost = HttpContext.Request.Url.Host; shortURL = urlHost + "/Home/Go/" + shortUrl_iD; } ViewData["shortURL"] = shortURL; return(View()); }
//Defualt action of home controller is linkshortener rather than index (changed in route config) //Action takes an optional parameter (longURL) - The url to be shortened public ActionResult LinkShortener(string longURL = null) { //Save the short url as the long url (currently) string shortURL = longURL; //Add the current title to the view bag (for display in the tab on a web broswer) ViewBag.Title = "Link Shortener"; //If string from post was null, then this if statement is never entered if (longURL != null) { //Get the DB instance (and if necessary the DB itself) var dbInstance = LinkDatabase.getInstance(); dbInstance.createDB(); //Save the longurl in the db and save the return as primary key string pk = dbInstance.saveLongURL(longURL); //Encode the PK string encoding = Shortener.GetShortEncoding(Int32.Parse(pk)); //Get the host and port parts of our website url string urlHost = HttpContext.Request.Url.Host; int urlPort = HttpContext.Request.Url.Port; //If no port, ignore adding it to the shortened url if (urlPort == 80) { //Short url looks like: <website name>:<port>/Home/Go/<encoded pk> shortURL = urlHost + "/Home/Go/" + encoding; } else { //Short url looks like: <website name>/Home/Go/<encoded pk> shortURL = urlHost + ":" + urlPort.ToString() + "/Home/Go/" + encoding; } } //Return the shortened (or null) short url to the view ViewBag.shortURL = shortURL; //Render the view return(View()); }
public JsonResult SaveCompanyReview(ReviewHolder data) { if (data == null) { return(Json(new { response = "Error: Invalid body JSON" })); } else if (!data.Review.CheckStars()) { return(Json(new { response = "Error: Stars must be a value between 0 and 5" })); } else if (!data.Review.CheckTimeStamp()) { return(Json(new { response = "Error: Invalid UNIX Timestamp" })); } else if (!data.Review.CheckCompanyName()) { return(Json(new { response = "Error: Empty Company Name Supplied" })); } else if (!data.Review.CheckUsername()) { return(Json(new { response = "Error: Empty Username Supplied" })); } else { try { LinkDatabase db = LinkDatabase.getInstance(); db.SaveReview(data.Review); return(Json(new { response = "success" })); } catch (Exception e) { return(Json(new { response = "exception thrown", exception = e.Message })); } } }
public void Session_OnStart() { LinkDatabase LD = LinkDatabase.getInstance(); HttpContext.Current.Session.Add("user", "Not Logged In"); }