/// <author>Per Mortensen</author> /// <summary> /// Determines whether the publisher account with the supplied credentials are authorized /// to change the media item's metadata. /// </summary> /// <param name="mediaId"> /// The id of the media item to be changed. /// </param> /// <param name="credentials"> /// The credentials of the publisher account. /// </param> /// <param name="db"> /// The database context to retrieve data from. /// </param> /// <param name="service"> /// The service on which the ValidateCredentials should be called. /// </param> /// <returns> /// true if the publisher can change the media, false otherwise. /// </returns> public static bool IsPublisherAuthorized(int mediaId, AccountCredentials credentials, DatabaseDataContext db, RentItService service) { try { service.ValidateCredentials(credentials); } catch (Exception) { return false; } if (!db.Medias.Exists(m => m.id == mediaId && m.active)) return false; // if the media with the specified id was not found Media media = (from m in db.Medias where m.id == mediaId && m.active select m).Single(); // find out whether this publisher is authorized to delete this media if (db.Publisher_accounts.Exists(p => p.user_name.Equals(credentials.UserName) && p.publisher_id == media.publisher_id)) return true; // if this publisher does not have permission to update the media return false; }
/// <author>Kenneth Søhrmann</author> /// <summary> /// Converts a list of media-instances from the database to an instance of /// MediaItems with all data of the various media items submitted. /// </summary> /// <param name="mediaList"> /// The collection of media-instances to be converted to a MediaItems- /// instance. /// </param> /// <param name="service"> /// The service on which the GetXxxInfo methods should be called. /// </param> /// <returns> /// A MediaItems-instance holding all metadata of all the medias submitted. /// </returns> public static MediaItems CompileMedias(IQueryable<RentItDatabase.Media> mediaList, RentItService service) { var bookInfos = new List<BookInfo>(); var movieInfos = new List<MovieInfo>(); var songInfos = new List<SongInfo>(); var albumInfos = new List<AlbumInfo>(); foreach (RentItDatabase.Media media in mediaList) { switch (MediaTypeOfValue(media.Media_type.name)) { case MediaType.Book: bookInfos.Add(service.GetBookInfo(media.id)); break; case MediaType.Movie: movieInfos.Add(service.GetMovieInfo(media.id)); break; case MediaType.Song: songInfos.Add(GetSongInfo(media.id)); break; case MediaType.Album: albumInfos.Add(service.GetAlbumInfo(media.id)); break; } } return new MediaItems(bookInfos, movieInfos, albumInfos, songInfos); }