public static AudioBook GetNewAudioBook(ApplicationContext db, AudioBookInputViewModel inputModel) { AudioBook book = new AudioBook { BookName = inputModel.BookName, Author = inputModel.Author, ReadingTime = inputModel.ReadingTime, ContentFilePath = inputModel.ContentFilePath, CoverFilePath = inputModel.CoverFilePath, Description = inputModel.Description }; ICollection <Genre> genres = GetGenresList(db, inputModel.GenresList); foreach (Genre g in genres) { book.Genres.Add(g); } SubscriptionType type = db.SubscriptionTypes.FirstOrDefault(s => s.Name == inputModel.SubscriptionType); if (type == null) { return(null); } book.SubscriptionType = type; return(book); }
public static AudioBook GetUpdatedAudioBook(ApplicationContext db, AudioBookInputViewModel inputModel) { AudioBook book = db.AudioBooks.Find(inputModel.Id); if (book == null) { return(null); } book.BookName = inputModel.BookName; book.Author = inputModel.Author; book.ReadingTime = inputModel.ReadingTime; book.ContentFilePath = inputModel.ContentFilePath; book.CoverFilePath = inputModel.CoverFilePath; book.Description = inputModel.Description; book.Genres.Clear(); ICollection <Genre> genres = GetGenresList(db, inputModel.GenresList); foreach (Genre g in genres) { book.Genres.Add(g); } SubscriptionType type = db.SubscriptionTypes.FirstOrDefault(s => s.Name == inputModel.SubscriptionType); if (type == null) { return(null); } book.SubscriptionType = type; return(book); }
public static AudioBookInputViewModel GetAudioBookInputViewModel(AudioBook book) { AudioBookInputViewModel inputModel = new AudioBookInputViewModel { Id = book.BookId, BookName = book.BookName, Author = book.Author, ReadingTime = book.ReadingTime, SubscriptionType = book.SubscriptionType.Name, ContentFilePath = book.ContentFilePath, CoverFilePath = book.CoverFilePath, Description = book.Description }; inputModel.GenresList = GetGenresString(book.Genres); return(inputModel); }