Example #1
0
        protected override void Seed(CTrackerContext context)
        {
            CouncilMemberData data      = new CouncilMemberData();
            OrdinanceData     ordData   = new OrdinanceData();
            ResolutionData    resData   = new ResolutionData();
            Ordinance         ordinance = new Ordinance();
            ApplicationUser   user      = new ApplicationUser();

            context.Ordinances.AddOrUpdate(
                ord => new { ord.OrdNumber },
                ordData.ordinanceScraper()
                );
            context.Resolutions.AddOrUpdate(
                res => new { res.ResNumber },
                resData.resolutionScraper()
                );
            context.Council_Members.AddOrUpdate(
                cm => new { cm.Name, cm.Office },
                data.seedDistrictedMembers()
                );
            context.Council_Members.AddOrUpdate(
                cm => new { cm.Name, cm.Office },
                data.seedViceMayor()
                );
            context.Council_Members.AddOrUpdate(
                cm => new { cm.Name, cm.Office },
                data.seedAtLargeMembers()
                );
        }
        public void UntrackOrdinance(int ordNumber, string userID)
        {
            Ordinance       ordinance = Context.Ordinances.FirstOrDefault(o => o.OrdNumber == ordNumber);
            ApplicationUser user      = Context.Users.FirstOrDefault(u => u.Id == userID);

            ordinance.Users.Remove(user);
            Context.SaveChanges();
        }
Example #3
0
        public Ordinance[] ordinanceScraper()
        {
            int       allYears = numberOf2015Ords + numberOf2016Ords + numberOf2017Ords;
            WebClient client   = new WebClient();

            highestOrdNumCollector();
            Ordinance[] scrapedOrds = new Ordinance[numberOf2017Ords];
            for (var k = 541; k < highest2017OrdNumber + 1; k++) // 541 IS FIRST 2017 NUMBER
            {
                Ordinance ordinance = new Ordinance();
                string    rawHtml   = client.DownloadString($"http://www.nashville.gov/mc/ordinances/term_2015_2019/bl2016_{k}.htm"); // REMINDER: THEY HAVEN'T CHANGED THE URL TO bl2017 YET!

                ordinance.OrdNumber = k;

                ordinance.Year = 2017;

                string captionPattern = @"<\/font><\/b>(?<caption>An ordinance.*?)<\/p>";
                Regex  captionRgx     = new Regex(captionPattern);
                Match  captionMatch   = captionRgx.Match(rawHtml);
                string caption        = captionMatch.Groups["caption"].Value;
                ordinance.Caption = caption;

                string          bodyTextPattern = @"<p class=""ordinancecontent"">(?<body>.)*<\/p>";
                Regex           bodyTextRgx     = new Regex(bodyTextPattern);
                MatchCollection bodyTextMatch   = bodyTextRgx.Matches(rawHtml);
                string          bodyText        = "";
                for (var j = 0; j < bodyTextMatch.Count; j++)
                {
                    string match = bodyTextMatch[j].ToString();
                    bodyText += match;
                }
                ordinance.Body = bodyText;

                //string sponsorPattern = @"Sponsored by: (?<sponsor>.*?)<\/p>";
                //Regex sponsorRgx = new Regex(sponsorPattern);
                //MatchCollection sponsorMatch = sponsorRgx.Matches(rawHtml);
                //string sponsorString = sponsorMatch[0].ToString();
                //SQL matching with council member. Send to list.
                //ordinance.Sponsor = blah.

                scrapedOrds[k - 541] = ordinance;
            }
            //for (var j = 99; j < highest2016OrdNumber+1; j++) // 99 IS FIRST 2016 NUMBER
            //{
            //    Ordinance ordinance = new Ordinance();
            //    ordinance.OrdNumber = j;
            //    ordinance.Body = client.DownloadString($"http://www.nashville.gov/mc/ordinances/term_2015_2019/bl2016_{j}.htm");
            //    scrapedOrds[j - 99] = ordinance;
            //}
            //for (var i = 1; i < highest2015OrdNumber+1; i++)
            //{
            //    Ordinance ordinance = new Ordinance();
            //    ordinance.OrdNumber = i;
            //    ordinance.Body = client.DownloadString($"http://www.nashville.gov/mc/ordinances/term_2015_2019/bl2015_{i}.htm");
            //    scrapedOrds[i-1] = ordinance;
            //}
            return(scrapedOrds);
        }
Example #4
0
        public void CanGetSingleOrd()
        {
            //Arrange
            int ordnumber = 1;
            //Act
            Ordinance foundOrd = repo.GetSingleOrd(ordnumber);

            //Assert
            Assert.AreEqual(1, repo.Context.Ordinances.Count());
            Assert.AreEqual(1, foundOrd.ID);
        }
    void applyOrdinance()
    {
        Ordinance ordinance = (Ordinance)manager.currentEquipment[1];

        if (ordinance == null)
        {
            ordinance = defaultOrdinance;
        }
        GameObject ordinanceGO = ordinance.itemObject;

        this.GetComponent <PlayerAttack>().ordinancePrefab = ordinanceGO;
        this.GetComponent <PlayerAttack>().launchDelay     = ordinance.launchDelay;
    }
        public void CanGetSingleOrd()
        {
            int       ordnumber = 150;
            Ordinance ord       = new Ordinance {
                Body = "blah", OrdNumber = 150
            };

            repo.ManuallyAddOrd(ord);
            Ordinance singleOrd = repo.GetSingleOrd(ordnumber);
            int       expected  = ord.OrdNumber;

            Assert.AreEqual(expected, singleOrd.OrdNumber);
        }
Example #7
0
        public void Initialize()
        {
            mock_context = new Mock <CTrackerContext>();

            mock_members     = new Mock <DbSet <CouncilMember> >();
            mock_member_list = new List <CouncilMember>();
            CouncilMember bogus_council_member = new CouncilMember()
            {
                ID = 1, Name = "Roger"
            };

            mock_member_list.Add(bogus_council_member);

            mock_ords     = new Mock <DbSet <Ordinance> >();
            mock_ord_list = new List <Ordinance>();
            Ordinance bogus_ord = new Ordinance()
            {
                ID = 1, Body = "Bogus Ordinance", OrdNumber = 1, Users = new List <ApplicationUser>()
            };

            mock_ord_list.Add(bogus_ord);


            mock_resolutions = new Mock <DbSet <Resolution> >();
            mock_res_list    = new List <Resolution>();
            Resolution bogus_res = new Resolution()
            {
                ID = 1, Body = "Bogus Resolution", ResNumber = 1, Users = new List <ApplicationUser>()
            };

            mock_res_list.Add(bogus_res);

            mock_app_user       = new Mock <DbSet <ApplicationUser> >();
            mock_app_users_list = new List <ApplicationUser>();
            ApplicationUser bogus_user1 = new ApplicationUser()
            {
                Id = "1", UserName = "******"
            };

            mock_app_users_list.Add(bogus_user1);

            bogus_user1.Ordinances.Add(new Ordinance()
            {
                ID = 2, OrdNumber = 2, Body = "Tracked Ord"
            });
            //bogus_user1.Resolutions.Add(bogus_res);

            repo = new CTrackerRepository(mock_context.Object);
            ConnectToDatastore();
        }
        public string DeleteRes(int resNumber)
        {
            ApplicationUser loggedInUser = userManager.FindById(User.Identity.GetUserId());
            Ordinance       ord          = new Ordinance();

            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                repo.UntrackResolution(resNumber, loggedInUser.Id);
                return("Removed.");
            }
            else
            {
                return("Error! Not deleted.");
            }
        }
        public string PostOrd(int ordNumber)
        {
            ApplicationUser loggedInUser = userManager.FindById(User.Identity.GetUserId());
            Ordinance       ord          = new Ordinance();

            if (ModelState.IsValid && User.Identity.IsAuthenticated)
            {
                repo.TrackOrdinance(ordNumber, loggedInUser.Id);
                return("Posted. Nice work.");
            }
            else
            {
                return("Error! Bummer dude.");
            }
        }
        public void CanGetOrds()
        {
            //Arrange
            Ordinance ord = new Ordinance {
                Body = "blah", OrdNumber = 1
            };

            //Act
            repo.ManuallyAddOrd(ord);
            int expected = 1;
            int actual   = repo.GetOrds().Count();

            //Assert
            Assert.AreEqual(expected, actual);
        }
Example #11
0
 protected override void Seed(Council_Tracker.DAL.CTrackerContext context)
 {
     CouncilMemberData data      = new CouncilMemberData();
     OrdinanceData     ordData   = new OrdinanceData();
     ResolutionData    resData   = new ResolutionData();
     Ordinance         ordinance = new Ordinance();
     ApplicationUser   user      = new ApplicationUser();
     //context.Ordinances.AddOrUpdate(
     //    ord => new { ord.OrdNumber },
     //    ordData.ordinanceScraper()
     //    );
     //context.Resolutions.AddOrUpdate(
     //    res => new { res.ResNumber },
     //    resData.resolutionScraper()
     //    );
     //context.Council_Members.AddOrUpdate(
     //    cm => new { cm.Name, cm.Office },   //Reminder, this is checking that the name and office are unique
     //                                        //data.seedViceMayor()              // Was not allowing me to seed with muliple methods from the councilmemberdata...
     //                                        //data.seedAtLargeMembers()
     //    data.seedDistrictedMembers()
     //);
 }
        public Ordinance GetSingleOrd(int ordnumber)
        {
            Ordinance ord = Context.Ordinances.FirstOrDefault(o => o.OrdNumber == ordnumber);

            return(ord);
        }
 public void ManuallyAddOrd(Ordinance ord)
 {
     Context.Ordinances.Add(ord);
     Context.SaveChanges();
 }