How would i implement a track addnew() into my controller? The add new use case Implement the
Fantastic news! We've Found the answer you've been seeking!
Question:
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!
Related Book For
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall
Posted Date: