Hi I need help on my assignment Add methods to the Manager class that handle the use
Question:
Hi I need help on my assignment
Add methods to the Manager class that handle the use cases - In the Manager class, add the methods that support the use cases: AlbumGetAll - Sort the results by album title. ArtistGetAll - Sort the results by artist name. MediaTypeGetAll - Sort the results by media type name. TrackGetAllWithDetail - Sort the tracks by track name. TrackAdd PlaylistGetAll - Sort the playlists by playlist name. PlaylistGetById PlaylistEditTracks
- For the "get all" use cases, you must use a LINQ query expression to sort the results as noted above. - For the "add new" Track use case, you must validate the incoming data by locating/fetching the objects that will be associated to the new Track object.
- A new track has two associated objects, Album and MediaType. You must fetch (validate) both and configure them on the new Track object before saving.
My code:
public class Manager { // Reference to the data context private DataContext ds = new DataContext();
// AutoMapper instance public IMapper mapper;
public Manager() { // Configure the AutoMapper components var config = new MapperConfiguration(cfg => { // Define the mappings below, for example... // cfg.CreateMap(); // cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); cfg.CreateMap(); });
mapper = config.CreateMapper();
ds.Configuration.ProxyCreationEnabled = false; ds.Configuration.LazyLoadingEnabled = false; }
// Add your methods below and call them from controllers. Ensure that your methods accept // and deliver ONLY view model objects and collections. When working with collections, the // return type is almost always IEnumerable.
public IEnumerable AlbumsGetAll() { var getAlbums = ds.Albums .OrderBy(a => a.Title) .ToList();
return mapper.Map>(getAlbums); }
public IEnumerable ArtistsGetAll() { var getArtists = ds.Artists .OrderBy(a => a.Name) .ToList();
return mapper.Map>(getArtists); }
public IEnumerable MediaTypeGetAll() { var getMediaType = ds.MediaTypes .OrderBy(a => a.Name) .ToList();
return mapper.Map>(getMediaType); }
public IEnumerable TrackGetAllWithDetail()//TODO do i have this? (int? id) { var getTracks = ds.Tracks .Include("Album.Artist") .Include("MediaType") .OrderBy(a => a.Name) .ToList(); //.SingleOrDefault(i => i.TrackId== id);
return mapper.Map>(getTracks); }
//add function TrackAdd public TrackAdd
public IEnumerable PlaylistGetAll() { var getPlaylists = ds.Playlists .OrderBy(a => a.Name) .ToList();
return mapper.Map>(getPlaylists); }
public IEnumerable PlaylistGetById(int? id) { var playlistsid = ds.Playlists .SingleOrDefault(i => i.PlaylistId== id);
return mapper.Map> (playlistsid); }
public IEnumerable PlaylistEditTracks() { var playedit = ds.Playlists .OrderBy(a => a.Name) .ToList();
return mapper.Map> (playedit); } }
What am I doing wrong?
Database Systems Design Implementation and Management
ISBN: 978-1337627900
13th edition
Authors: Carlos Coronel, Steven Morris