Example #1
0
        public JsonResult SearchGroupsByID(int id, bool displayArtists = true)
        {
            List <Group> groups = allGroups.Where(group => group.Id == id).ToList();

            if (displayArtists)
            {
                List <Artist> allArtists = JsonToFile <Artist> .ReadJson();

                var artists = from Group in groups
                              join Artist in allArtists on Group.Id equals Artist.GroupId
                              where Artist.GroupId == Group.Id
                              select Artist;
                return(Json(new { groups, artists }));
            }
            else
            {
                return(Json(groups));
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist FromMV = Artists.Where(artist => artist.Hometown == "Mount Vernon").Single();

            Console.WriteLine($"{0} - {1}", FromMV.ArtistName, FromMV.Age);
            //Who is the youngest artist in our collection of artists?
            Artist Youngest = Artists.OrderBy(artist => artist.Age).First();

            Console.WriteLine($"The Youngest Artist is {0} at {1} years old", Youngest.ArtistName, Youngest.Age);
            //Display all artists with 'William' somewhere in their real name
            List <Artist> William = Artists.Where(artist => artist.RealName.Contains("William")).ToList();

            foreach (var artist in William)
            {
                Console.WriteLine(artist.ArtistName + " - " + artist.RealName);
            }
            //Display all groups with names less than 8 characters in length
            List <Group> LessThan = Groups.Where(group => group.GroupName.Length < 8).ToList();

            foreach (var group in LessThan)
            {
                Console.WriteLine(group.GroupName);
            }
            //Display the 3 oldest artist from Atlanta
            List <Artist> AtlantasOldest = Artists.OrderByDescending(artist => artist.Age).Take(3).ToList();

            foreach (var artist in AtlantasOldest)
            {
                Console.WriteLine($"{0} - {1} years old", artist.ArtistName, artist.Age);
            }
            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            List <Group> NonNY = Artists.Join(Groups, artist => artist.GroupId, group => group.Id, (artist, group) => { artist.Group = group, return(artist); })
Example #3
0
        public JsonResult SearchGroupsByName(string name, bool displayArtists = true)
        {
            Regex.Regex  r      = new Regex.Regex($"(?i){name}");
            List <Group> groups = allGroups.Where(group => r.IsMatch(group.GroupName)).ToList();

            if (displayArtists)
            {
                List <Artist> allArtists = JsonToFile <Artist> .ReadJson();

                var artists = from Group in groups
                              join Artist in allArtists on Group.Id equals Artist.GroupId
                              where Artist.GroupId == Group.Id
                              select Artist;
                return(Json(new { groups, artists }));
            }
            else
            {
                return(Json(groups));
            }
        }
Example #4
0
        public RapperController()
        {
            Rapper = JsonToFile <Artist> .ReadJson();

            Groups = JsonToFile <Group> .ReadJson();

            Routes = new Dictionary <string, List <string> > {
                ["rapper"] = new List <string> {
                    "/api",
                    "/api/name/{name}",
                    "/api/realname/{realname}",
                    "/api/hometown/{hometown}"
                },
                ["group"] = new List <string> {
                    "/api/groups",
                    "/api/groups/{groupname}",
                    "/api/groups/showMembers={true/false}"
                }
            };
        }
 public void TimerCallback(object obj)
 {
     try
     {
         var json = RandomChoise.SomethingActionsWithUsers();
         var n    = _random.Next(0, 2);
         if (n == 0)
         {
             JsonToFile.WriteJson(json);
         }
         else
         {
             _jsonToRabbit.AddToRabbit(json);
         }
     }
     finally
     {
         _timer.Change(800, Timeout.Infinite);
     }
 }
 public GroupController()
 {
     allGroups = JsonToFile <Group> .ReadJson();
 }
Example #7
0
        public GroupController()
        {
            allGroups = JsonToFile <Group> .ReadJson();

            allArtists = JsonToFile <Artist> .ReadJson();
        }
 public ArtistController()
 {
     allArtists = JsonToFile <Artist> .ReadJson();
 }
    static void ImportFile()
    {
        JsonToFile jsonToFile = new JsonToFile();

        jsonToFile.DoEverythingFile();
    }