Answered step by step
Verified Expert Solution
Link Copied!

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:


image

 

Next, edit the view. Add the item-selection elements for the Album and MediaType. It is suggested that you use a DropDownList HTML Helper for the Album (make its size 10, so that it renders as a ListBox). Pre-select the first album. 

 

Use a radio button group for the MediaType and ensure you render it as a horizontal radio button group. Pre-select the "MPEG audio file" option. 

 

It should look something like the following. Notice all controls have been styled using BootStrap, even the radio buttons. Also, notice the track name is focused on page load.

image
TrackAddViewModel and the controller POST method

The TrackAddViewModel class will be like the TrackAddFormViewModel class however you must replace the SelectList properties with int properties named Id. Make them "required" by adding [Range...] data annotations.

 

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 TrackAdd(Track newTrack)
       {
           //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>(addedItem);
       }

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems analysis and design

Authors: kenneth e. kendall, julie e. kendall

8th Edition

135094909, 013608916X, 9780135094907, 978-0136089162

More Books

Students also viewed these Programming questions

Question

What are changeable data?

Answered: 1 week ago