Skip to content
Permalink
Browse files

Create new media functions work except for AddAlbum

  • Loading branch information
sec11008 committed Dec 9, 2015
1 parent d3faf96 commit 8d7ac367af1c6f2de1185a0dce6f63fc9b132e83
@@ -9,7 +9,7 @@ public class Track
{
public int TrackId { get; set; }
public string TrackName { get; set; }
public string AlbumTitle { get; set; } //Should this be album id to match the sql?
public string AlbumTitle { get; set; }
public string MediaType { get; set; }
public string Genre { get; set; }
public string Composer { get; set; }
@@ -248,6 +248,9 @@ public int AddGenre(string name)
int nextNum = int.Parse(cmd.ExecuteScalar() + "") + 1;

string insertGenre = "insert into Genre(GenreId,Name) VALUES (" + nextNum + ",\"" + name + "\")";
cmd = new MySqlCommand(insertGenre, SqlConn);
cmd.ExecuteNonQuery();

return nextNum;
}
else
@@ -266,6 +269,9 @@ public int AddMediaType(string name)
int nextNum = int.Parse(cmd.ExecuteScalar() + "") + 1;

string insertGenre = "insert into MediaType(MediaTypeId,Name) VALUES (" + nextNum + ",\"" + name + "\")";
cmd = new MySqlCommand(insertGenre, SqlConn);
cmd.ExecuteNonQuery();

return nextNum;
}
else
@@ -143,3 +143,22 @@ app.run(['$rootScope', '$state', '$stateParams','$http',
$rootScope.$stateParams = $stateParams;
$http.defaults.headers.common.Authentication = 'Basic Token';
}]);

app.filter('formatTime', function() {
return function(milliseconds) {
var seconds = parseInt((milliseconds/1000)%60);
var minutes = parseInt((milliseconds/(100060))%60);
var hours = parseInt((milliseconds/(100060*60))%24);
var out = "";

minutes = (parseInt(minutes) + (60 * parseInt(hours)));
minutes = (minutes < 10) ? "0" + minutes : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds;

out = minutes + ":" + seconds;


return out;
};

});
@@ -43,35 +43,159 @@ angular.module('routerApp').controller('adminController', function ($scope, $htt
};
$scope.toCreateAlbum = function () {
$scope.showMediaOptions = false;
$scope.showAlbumFields = true;

};
$scope.toCreateArtist = function () {
$scope.showMediaOptions = false;
$scope.showArtistFields = true;
};
$scope.toCreateGenre = function () {
$scope.showMediaOptions = false;
$scope.showGenreFields = true;
};
$scope.toCreateMediaType = function () {
$scope.showMediaOptions = false;
$scope.showMediaTypeFields = true;

};

$scope.createTrack = function (newTrack) {
var sub = HolderService.getBlankTrack();
if (newTrack.company == null) {
newTrack.company = null;
}
sub.TrackName = newTrack.trackName;
sub.artist = newTrack.artist;
sub.AlbumTitle = newTrack.albumTitle;
sub.MediaType = newTrack.mediaType;
sub.Genre = newTrack.genre;
sub.Composer = newTrack.composer;
sub.Milliseconds = newTrack.milliseconds;
sub.Bytes = newTrack.bytes;
sub.UnitPrice = newTrack.unitPrice;
console.log(sub);

var promise = $http({
method: "post",
url: "http://localhost:50031/api/AddTrack",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
$scope.messages = 'You created a track!';
console.log(response);
alert($scope.messages);
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
alert($scope.messages);
});
}

$scope.createArtist = function (newArtist) {
var sub = {
ArtistID: null,
Name: null
}
sub.Name = newArtist.artistName;
console.log(sub);

var promise = $http({
method: "post",
url: "http://localhost:50031/api/AddArtist",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
$scope.messages = 'You created an artist!';
console.log(response);
alert($scope.messages);
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
alert($scope.messages);
});
}

$scope.createAlbum = function (newAlbum) {
var sub = {
AlbumID: null,
Title: null,
Artist: null
}
sub.Title = newAlbum.albumName;
sub.Artist = newAlbum.artistName;
console.log(sub);

var promise = $http({
method: "post",
url: "http://localhost:50031/api/AddAlbum",
headers: {
contentType: "application/json"
},
data: sub
}).
success(function (data, status, headers, config) {
$scope.messages = 'You created an album!';
console.log(response);
alert($scope.messages);
}).
error(function (error, status, headers, config) {
$scope.messages = 'There was a network error. Try again later.';
alert($scope.messages);
console.log(error);
console.log(error.ExceptionMessage);
console.log(error.ExeceptionType);
console.log(error.StackTrace);
});

}

$scope.createGenre = function (genreName) {
$http.get("http://localhost:50031/api/AddGenre?GenreName=" + genreName)
.success(function (response) {
$scope.messages = 'You created a genre!';
console.log(response);
alert($scope.messages);
})

}

$scope.createMediaType = function (mediaTypeName) {
$http.get("http://localhost:50031/api/AddMediaType?TypeName=" + mediaTypeName)
.success(function (response) {
$scope.messages = 'You created a media type!';
console.log(response);
alert($scope.messages);
})

}


//End New Media

//CustomerDemographics
$scope.custInfoGridOptions = {
enableFiltering: true,
columnDefs: [
{field: 'Fname', displayName: 'First Name'},
{field: 'Lname', displayName: 'Last Name'},
{field: 'Address'},
{field: 'City'},
{field: 'State'},
{field: 'Post'},
{field: 'Country'},
{field: 'Phone'},
{field: 'Fax'},
{field: 'Email'},
{field: 'Company'}
]
}
columnDefs: [
{field: 'Fname', displayName: 'First Name'},
{field: 'Lname', displayName: 'Last Name'},
{field: 'Address'},
{field: 'City'},
{field: 'State'},
{field: 'Post'},
{field: 'Country'},
{field: 'Phone'},
{field: 'Fax'},
{field: 'Email'},
{field: 'Company'}
]
}

//End Customer Demographics

@@ -89,7 +213,7 @@ angular.module('routerApp').controller('adminController', function ($scope, $htt
})
}
$scope.getPlaylists();
$state.go($state.current, {}, { reload: true });
$state.reload();
}

$scope.toEdit = function (playlistID) {
@@ -112,7 +236,7 @@ angular.module('routerApp').controller('adminController', function ($scope, $htt
$scope.dropPlaylist(playlistID);
}
$scope.getPlaylists();
$state.go($state.current, {}, { reload: true });
$state.reload();
}

$scope.dropPlaylist = function (playlistID) {
@@ -3,6 +3,7 @@
<meta charset="utf-8" />
</head>
<div ng-controller="adminController">
<!--List of playlists-->
<div ng-hide="editing" ng-init="getPlaylists();">
<a ng-click="addPlaylist();">Create New Playlist</a>
<table>
@@ -20,9 +21,11 @@
</tr>
</table>
</div>
<!--Edit Playlist view-->
<div ng-show="editing">
<a ng-click="editing=false; addingTrack=false;" ui-sref="admin-playlist-manager" class="btn btn-lg btn-primary center-block">Back</a>
<a ng-hide="addingTrack" ng-click="addingTrack=true;" ui-sref="admin-playlist-manager" class="btn btn-lg btn-primary center-block">Add a track</a>
<!--Search for adding tracks to playlist-->
<div ng-show="addingTrack">
<form name="myForm">
<table>
@@ -54,7 +57,7 @@
<br />
<br />
</div>

<!--List of tracks in playlist-->
<table>
<tr>
<td>Track Id</td>
@@ -68,7 +71,7 @@
<td>{{ track.TrackId }}</td>
<td>{{ track.TrackName }}</td>
<td>{{ track.artist }}</td>
<td>{{ track.Milliseconds }}</td>
<td>{{ track.Milliseconds | formatTime }}</td>
<td>{{ track.UnitPrice | currency }}</td>
<td><a ng-click="deleteTrack(track.TrackId)">Delete</a></td>
</tr>
@@ -16,6 +16,11 @@
<input type="text" name="trackName" id="trackName" class="form-control" ng-model="track.trackName" required />
<span ng-show="form.trackName.$dirty && form.trackName.$error.required" class="help-block">Track name is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.artist.$dirty && form.artist.$error.required }">
<label for="artist">Artist</label>
<input type="text" name="artist" id="artist" class="form-control" ng-model="track.artist" required />
<span ng-show="form.artist.$dirty && form.artist.$error.required" class="help-block">Artist is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.albumTitle.$dirty && form.albumTitle.$error.required }">
<label for="albumTitle">Album Title</label>
<input type="text" name="albumTitle" id="albumTitle" class="form-control" ng-model="track.albumTitle"/>
@@ -50,11 +55,69 @@
<input type="text" name="unitPrice" id="unitPrice" class="form-control" ng-model="track.unitPrice" required />
<span ng-show="form.unitPrice.$dirty && form.unitPrice.$error.required" class="help-block">Unit Price is required</span>
</div>

<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createTrack(track)" class="btn btn-primary">Submit</button>
</div>

</form>
<form ng-show="showAlbumFields">
<div class="form-group" ng-class="{ 'has-error': form.albumName.$dirty && form.albumName.$error.required }">
<label for="albumName">Album name</label>
<input type="text" name="albumName" id="albumName" class="form-control" ng-model="album.albumName" required />
<span ng-show="form.albumName.$dirty && form.albumName.$error.required" class="help-block">Album name is required</span>
</div>
<div class="form-group" ng-class="{ 'has-error': form.artistName.$dirty && form.artistName.$error.required }">
<label for="artistName">Artist name</label>
<input type="text" name="artistName" id="artistName" class="form-control" ng-model="album.artistName" required />
<span ng-show="form.artistName.$dirty && form.artistName.$error.required" class="help-block">Artist name is required</span>
</div>

<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createAlbum(album)" class="btn btn-primary">Submit</button>
</div>

</form>
<form ng-show="showArtistFields">
<div class="form-group" ng-class="{ 'has-error': form.artistName.$dirty && form.artistName.$error.required }">
<label for="artistName">Artist name</label>
<input type="text" name="artistName" id="artistName" class="form-control" ng-model="artist.artistName" required />
<span ng-show="form.artistName.$dirty && form.artistName.$error.required" class="help-block">Artist name is required</span>
</div>

<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createArtist(artist)" class="btn btn-primary">Submit</button>
</div>

</form>
<form ng-show="showGenreFields">
<div class="form-group" ng-class="{ 'has-error': form.genreName.$dirty && form.genreName.$error.required }">
<label for="genreName">Genre name</label>
<input type="text" name="genreName" id="genreName" class="form-control" ng-model="genre.genreName" required />
<span ng-show="form.genreName.$dirty && form.genreName.$error.required" class="help-block">Genre name is required</span>
</div>



<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createGenre(genre.genreName)" class="btn btn-primary">Submit</button>
</div>

</form>
<form ng-show="showMediaTypeFields">
<div class="form-group" ng-class="{ 'has-error': form.mediaTypeName.$dirty && form.mediaTypeName.$error.required }">
<label for="mediaTypeName">MediaType name</label>
<input type="text" name="mediaTypeName" id="mediaTypeName" class="form-control" ng-model="mediaType.mediaTypeName" required />
<span ng-show="form.mediaTypeName.$dirty && form.mediaTypeName.$error.required" class="help-block">Media Type name is required</span>
</div>



<div class="form-actions">
<button type="submit" ng-disabled="form.$invalid || vm.dataLoading" data-ng-click="createMediaType(mediaType.mediaTypeName)" class="btn btn-primary">Submit</button>
</div>

</form>



0 comments on commit 8d7ac36

Please sign in to comment.
You can’t perform that action at this time.