Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How would i implement a track addnew() into my controller? The add new use case Implement the add new use case for the Track entity.
How would i implement a track addnew() into my controller?
The "add new" use case
Implement the "add new" use case for theTrackentity. ItsTrackAddFormViewModelclass will needSelectListproperties for bothAlbumandMediaType. Remember to follow the naming rule forSelectListproperties.
After you write the GET method (for the "add new" use case), scaffold a view. It should look something like the following:
The TrackAddViewModel class will be like the TrackAddFormViewModel class however you must replace the SelectList properties with int properties named
Write the controller POST method next. After a successful "add new" result, redirect to the Details view.
This is what I have in my manager class:
public IEnumerable
{
//validate incoming data
if (newTrack == null) { return null; }
//locate the associated Album and MediaType objs
var album = ds.Albums.Find(newTrack.AlbumId);
var mediaType = ds.MediaTypes.Find(newTrack.MediaTypeId);
//createand configure a new track obj
var addedItem = new Track
{
AlbumId = album.AlbumId,
Album = album,
GenreId = mediaType.MediaTypeId,
//Genre = mediaType,
Name = newTrack.Name,
Composer = newTrack.Composer,
Milliseconds = newTrack.Milliseconds,
Bytes = newTrack.Bytes,
UnitPrice = newTrack.UnitPrice
};
//Add the new object to the data context
ds.Tracks.Add(addedItem);
ds.SaveChanges();
//Return the obj
return mapper.Map
}
Please help on how to implement this!
Playlist Editor Home Albums Artists Media Types Add new track Complete the form, and click the Create button Track name Composer Length (ms) Unit price 0 0.00 Create Tracks Playlists
Step by Step Solution
★★★★★
3.34 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
To implement the add new use case for the Track entity in your controller you can follow these steps ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started