コード例 #1
0
        public async Task <IActionResult> ViewSingle(int id, double distance = 0.0D)
        {
            string userId   = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var    thisUser = _context.AspNetUsers.FirstOrDefault(x => x.Id == userId);
            //INSERT call to Mike's code here, MAYBE, that COULD return similar startups from the API and write them to a list of our Startup model
            //OR we could add a list of API startup model to the viewmodel class, filter by what Mike's code returns, and pass that on...
            //INSERT call to Jesse's code here, that will return an int for successViewStartupFavorite view = new ViewStartupFavorite() {

            List <PredictedApiStartup> topMatching = await CompareSuccess(id);

            Models.Startup startupToView = _context.Startup.Find(id);
            string         nameToSearch  = startupToView.Name.Replace(" ", "+");
            NewsResult     searchResult  = (await Utilities.GetApiResponse <NewsResult>("v2", "everything", "https://newsapi.org", "apiKey", NewsApiKey, "q", nameToSearch)).FirstOrDefault(); //       "v0 /appFo187B73tuYhyg", "Master List", "https://api.airtable.com", "api_key", ApiKey)).FirstOrDefault();
            List <Article> articles      = new List <Article>();

            for (int i = 0; i < 5; i++)
            {
                try
                {
                    articles.Add(searchResult.articles[i]);
                }
                catch
                {
                    continue;
                }
            }


            FavoritesViewModel view = new FavoritesViewModel()
            {
                SingleStartupToView       = startupToView,
                FavoriteStartups          = _context.Favorites.Where(x => x.UserId == userId).ToList <Favorites>(),
                UserAssociation           = thisUser.Association,
                MatchingPredictedStartups = topMatching,
                Comments = _context.Comment.Where(x => x.StartupId == id &&
                                                  x.Restricted == false).ToList <Comment>(),
                ExclusiveComments = _context.Comment.Where(x => x.StartupId == id &&
                                                           x.Restricted == true &&
                                                           x.Association == thisUser.Association).ToList <Comment>(),
                Articles = articles
            };

            ViewBag.Distance = distance;

            return(View(view));
        }
コード例 #2
0
        public IActionResult AddStartup(string name, string summary, int teamscore, int uniqueness, string thegoodlife = "", string healthbeyondthehotpital = "",
                                        string robustfuture = "", string convenienceandproductivity = "", string softwareai = "", string sensing = "",
                                        string robotics     = "", string products = "", string advancedmaterials = "", string businessprocess    = "",
                                        string city         = "", string country  = "", string dateadded = "")
        {
            if (name == null)
            {
                return(View());
            }

            Models.Startup startupToAdd = new Models.Startup();
            startupToAdd.Name        = name;
            startupToAdd.Summary     = summary;
            startupToAdd.City        = city;
            startupToAdd.Country     = country;
            startupToAdd.TeamScore   = teamscore;
            startupToAdd.UniqueScore = uniqueness;
            string themes = "";

            if (thegoodlife != "")
            {
                themes += thegoodlife;
            }
            if (healthbeyondthehotpital != "")
            {
                if (themes == "")
                {
                    themes += healthbeyondthehotpital;
                }
                else
                {
                    themes += ", " + healthbeyondthehotpital;
                }
            }
            if (robustfuture != "")
            {
                if (themes == "")
                {
                    themes += robustfuture;
                }
                else
                {
                    themes += ", " + robustfuture;
                }
            }
            if (convenienceandproductivity != "")
            {
                if (themes == "")
                {
                    themes += convenienceandproductivity;
                }
                else
                {
                    themes += ", " + convenienceandproductivity;
                }
            }

            startupToAdd.Theme = themes;

            string techArea = "";

            if (softwareai != "")
            {
                techArea += softwareai;
            }
            if (sensing != "")
            {
                if (techArea == "")
                {
                    techArea += sensing;
                }
                else
                {
                    techArea += ", " + sensing;
                }
            }
            if (robotics != "")
            {
                if (techArea == "")
                {
                    techArea += robotics;
                }
                else
                {
                    techArea += ", " + robotics;
                }
            }
            if (products != "")
            {
                if (techArea == "")
                {
                    techArea += products;
                }
                else
                {
                    techArea += ", " + products;
                }
            }
            if (advancedmaterials != "")
            {
                if (techArea == "")
                {
                    techArea += advancedmaterials;
                }
                else
                {
                    techArea += ", " + advancedmaterials;
                }
            }
            if (businessprocess != "")
            {
                if (techArea == "")
                {
                    techArea += businessprocess;
                }
                else
                {
                    techArea += ", " + businessprocess;
                }
            }

            startupToAdd.TechArea = techArea;

            startupToAdd.DateAdded = DateTime.Parse(dateadded);


            if (ModelState.IsValid)
            {
                _context.Startup.Add(startupToAdd);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <List <PredictedApiStartup> > CompareSuccess(int id)
        {
            //List<string> techAreasStrings = new List<string>();
            Models.Startup startupToEdit = _context.Startup.Find(id);
            // List<ApiStartup> newList = new List<ApiStartup>();
            //var newList = startupToEdit;

            string[] techAreaStrings                  = startupToEdit.TechArea.Replace(" ", "").Split(',');
            StartupListRootObject startupList         = (await Utilities.GetApiResponse <StartupListRootObject>("v0/appFo187B73tuYhyg", "Master List", "https://api.airtable.com", "api_key", ApiKey)).FirstOrDefault();
            StartupListRootObject filteredStartupList = new StartupListRootObject();

            filteredStartupList.Records = new List <StartupContainer>();
            foreach (string ta in techAreaStrings)
            {
                foreach (var record in startupList.Records)
                {
                    if (record.Fields.TechAreas != null)
                    {
                        string apiTechAreas = record.Fields.TechAreas.Replace(" ", "").ToLower();
                        string thisTechArea = ta.Replace(" ", "").ToLower();
                        if (apiTechAreas.Contains(thisTechArea))
                        {
                            filteredStartupList.Records.Add(record);
                        }
                    }
                }
            }

            FeedbackListRootObject     feedbackList             = (await Utilities.GetApiResponse <FeedbackListRootObject>("v0/appFo187B73tuYhyg", "Feedback", "https://api.airtable.com", "api_key", ApiKey)).FirstOrDefault();
            List <PredictedApiStartup> ratedFilteredApiStartups = new List <PredictedApiStartup>();

            for (int i = 0; i < filteredStartupList.Records.Count; i++)
            {
                ApiStartup singleStartup = (ApiStartup)filteredStartupList.Records[i].Fields;
                //PredictedApiStartup thisone = singleStartup as PredictedApiStartup;

                if (singleStartup != null)
                {
                    PredictedApiStartup pas = new PredictedApiStartup();
                    pas.CompanyName     = singleStartup.CompanyName;
                    pas.CompanySummary  = singleStartup.CompanySummary;
                    pas.PredictedRating = SuccessPredictor.PredictSuccess(filteredStartupList.Records[i].Fields, feedbackList.Records);
                    ratedFilteredApiStartups.Add(pas);
                }
            }

            ratedFilteredApiStartups = ratedFilteredApiStartups.OrderBy(x => x.PredictedRating).Reverse().ToList();
            List <PredictedApiStartup> topResults = new List <PredictedApiStartup>();

            for (int i = 0; i < 3; i++) //change i<# to change number of results
            {
                try
                {
                    topResults.Add(ratedFilteredApiStartups[i]);
                }
                catch
                {
                    break;
                }
            }

            return(topResults);
        }