-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jeremy Mill
committed
Nov 12, 2015
1 parent
bfd6223
commit f457f38
Showing
11 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
63 changes: 63 additions & 0 deletions
63
TeamDBAwesome/TeamDBAwesome/Controllers/SearchController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text.RegularExpressions; | ||
using System.Web.Http; | ||
using TeamDBAwesome.Models; | ||
|
||
namespace TeamDBAwesome.Controllers | ||
{ | ||
public class SearchController : ApiController | ||
{ | ||
// GET: api/Search | ||
public HttpResponseMessage Get(string search="") | ||
{ | ||
//make the message that we are going to return | ||
HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK); | ||
|
||
//by default we're going to return everything, unless we get something with the expression type:'type' | ||
//for instance type:artist will only return artist types | ||
Regex regex = new Regex("type:(Media|Album|Artist|Track|Composer|Genre)"); | ||
MatchCollection m = regex.Matches(search); | ||
Debug.WriteLine(m); | ||
Search dbsearch = new Search(); | ||
if(m.Count > 0) | ||
{ | ||
//set each one to blank first | ||
dbsearch.Media = ""; | ||
dbsearch.Album = ""; | ||
dbsearch.Artist = ""; | ||
dbsearch.Track = ""; | ||
dbsearch.Composer = ""; | ||
dbsearch.Genre = ""; | ||
|
||
foreach (Match match in m) | ||
{ | ||
string tag = match.Value.Split(':')[1]; | ||
if (tag == "Media") { dbsearch.Media = search; } | ||
else if (tag == "Album") { dbsearch.Album = search; } | ||
else if (tag == "Artist") { dbsearch.Artist = search; } | ||
else if (tag == "Track") { dbsearch.Track = search; } | ||
else if (tag == "Composer") { dbsearch.Composer = search; } | ||
else if (tag == "Genre") { dbsearch.Genre = search; } | ||
} | ||
} | ||
else | ||
{ | ||
dbsearch.Media = search; | ||
dbsearch.Album = search; | ||
dbsearch.Artist = search; | ||
dbsearch.Track = search; | ||
dbsearch.Composer = search; | ||
dbsearch.Genre = search; | ||
} | ||
//return it | ||
return message; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace TeamDBAwesome.Models | ||
{ | ||
public class Album | ||
{ | ||
public int AlbumId { get; set; } | ||
public string Title { get; set; } | ||
public int ArtistId { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace TeamDBAwesome.Models | ||
{ | ||
public class Artist | ||
{ | ||
public int ArtistId { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace TeamDBAwesome.Models | ||
{ | ||
public class Genre | ||
{ | ||
public int GenreId { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace TeamDBAwesome.Models | ||
{ | ||
public class Media | ||
{ | ||
//as a note, in the DB this is mediatype | ||
public int MediaTypeId { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace TeamDBAwesome.Models | ||
{ | ||
public class Search | ||
{ | ||
public string Media { get; set; } | ||
public string Album { get; set; } | ||
public string Artist { get; set; } | ||
public string Track { get; set; } | ||
public string Composer { get; set; } | ||
public string Genre { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace TeamDBAwesome.Models | ||
{ | ||
public class SearchResult | ||
{ | ||
List<String> Media { get; set; } | ||
List<String> Album { get; set; } | ||
List<String> Artist { get; set; } | ||
List<String> Track { get; set; } | ||
List<String> Composer { get; set; } | ||
List<String> Genre { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace TeamDBAwesome.Models | ||
{ | ||
public class Track | ||
{ | ||
public int TrackId { get; set; } | ||
public string Name { get; set; } | ||
public int AlbumId { get; set; } | ||
public int MediaTypeId { get; set; } | ||
public int GenreId { get; set; } | ||
public string Composer { get; set; } | ||
public int Milliseconds { get; set; } | ||
public int Bytes { get; set; } | ||
public float UnitPrice { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters