public ListOfDVDResponse GetByTitle(string title) { ListOfDVDResponse response = new ListOfDVDResponse(); List <DVD> dvdList = _dvdRepo.GetByTitle(title); response.DVDs = new List <DVDView>(); foreach (DVD dvd in dvdList) { DVDView listByTitle = new DVDView(); listByTitle.dvdId = dvd.dvdId; listByTitle.title = dvd.title; listByTitle.director = dvd.director.directorName; listByTitle.rating = dvd.rating.ratingName; listByTitle.realeaseYear = dvd.releaseYear; listByTitle.notes = dvd.notes; response.DVDs.Add(listByTitle); } if (dvdList == null) { response.Success = false; response.Message = "There are no DVDs with this title."; } else { response.Success = true; } return(response); }
public ListOfDVDResponse GetAll() { ListOfDVDResponse response = new ListOfDVDResponse(); List <DVD> dvdList = _dvdRepo.GetAll(); response.DVDs = new List <DVDView>(); foreach (DVD dvd in dvdList) { DVDView dvdView = new DVDView(dvd); response.DVDs.Add(dvdView); } if (dvdList == null || dvdList.Count == 0) { response.Success = false; response.Message = "There are no DVDs to be listed."; } else { response.Success = true; } return(response); }
public DVDResponse EditDVD(DVDView dvd, string director, string notes, string rating, int releaseYear, string title) { DVDResponse response = new DVDResponse(); DVD dvdToEdit = _dvdRepo.GetById(dvd.dvdId); Director newDirector = _dvdRepo.NewDirector(director); if (newDirector.directorName == null) { _dvdRepo.AddDirector(director); newDirector = _dvdRepo.NewDirector(director); } if (dvdToEdit.directorId != newDirector.directorId) { dvdToEdit.director = newDirector; } Rating newRating = _dvdRepo.NewRating(rating); if (newRating.ratingName == null) { _dvdRepo.AddRating(rating); newRating = _dvdRepo.NewRating(rating); } if (dvdToEdit.ratingId != newRating.ratingId) { dvdToEdit.rating = newRating; } if (notes == null) { dvd.notes = ""; } if (title == null || title == "") { response.Success = false; response.Message = "You must enter a DVD title."; } if (rating == null || rating == "") { response.Success = false; response.Message = "You must enter a rating."; } else { response.Success = true; dvdToEdit.title = title; dvdToEdit.releaseYear = releaseYear; dvdToEdit.notes = notes; _dvdRepo.Edit(dvdToEdit, dvdToEdit.dvdId); var editedDVD = new DVDView(dvdToEdit); response.DVDView = editedDVD; } return(response); }
public IHttpActionResult NewDVD(DVDView dvd) { DVDResponse create = manager.NewDVD(dvd.title, dvd.director, dvd.rating, dvd.realeaseYear, dvd.notes); if (create.DVDView == null) { return(NotFound()); } return(Ok(create.DVDView)); }
public IHttpActionResult EditDVD(DVDView dvd) { DVDResponse update = manager.EditDVD(dvd, dvd.director, dvd.notes, dvd.rating, dvd.realeaseYear, dvd.title); if (update.DVDView == null) { return(NotFound()); } return(Ok(update.DVDView)); }
public IHttpActionResult GetById(int id) { DVDResponse found = manager.GetById(id); var dvdById = new DVDView(found.DVD); if (found.DVD == null) { return(NotFound()); } return(Ok(dvdById)); }
public DVDResponse NewDVD(string title, string director, string rating, int releaseYear, string notes) { DVDResponse response = new DVDResponse(); DVD dvd = new DVD(); Director newDirector = _dvdRepo.NewDirector(director); Rating newRating = _dvdRepo.NewRating(rating); if (newDirector.directorName == null) { _dvdRepo.AddDirector(director); newDirector = _dvdRepo.NewDirector(director); } if (newRating.ratingName == null) { _dvdRepo.AddRating(rating); newRating = _dvdRepo.NewRating(rating); } if (notes == null) { dvd.notes = ""; } if (title == null || title == "") { response.Success = false; response.Message = "You must enter a DVD title."; } if (rating == null || rating == "") { response.Success = false; response.Message = "You must enter a rating."; } else { response.Success = true; dvd.title = title; dvd.director = newDirector; dvd.rating = newRating; dvd.releaseYear = releaseYear; dvd.notes = notes; var newDVD = new DVDView(dvd); newDVD.dvdId = _dvdRepo.NewDVD(dvd); response.DVDView = newDVD; } return(response); }
public IHttpActionResult showDVDDetails(DVDView dvd) { DVDResponse response = manager.EditDVD(dvd, dvd.director, dvd.notes, dvd.rating, dvd.realeaseYear, dvd.title); return(Ok(response.DVDView)); }