//For each object passed into the method's arguments, it will check whether it is null. If it is not null then it further check to see if the object's attribute for holding the average rating is not equal to 0. If is does not equal //then it will assign this data value to the public BookModel object's corresponding data attribute. private void SetAverageRatings(GoodreadsModel goodreadsBookData, GoolgeBooksApi.GoogleBookModel googleBooksBookData, AmazonModel amazonBookData) { if (googleBooksBookData != null) { if (googleBooksBookData.AverageRating != 0) { bookModel.GoogleBooksAverageRating = googleBooksBookData.AverageRating; } } if (goodreadsBookData != null) { if (goodreadsBookData.AverageRating != 0) { bookModel.GoodreadsAverageRating = goodreadsBookData.AverageRating; } } if (amazonBookData != null) { if (amazonBookData.AverageRating != 0) { bookModel.GoodreadsAverageRating = amazonBookData.AverageRating; } } }
//This method by first checking whether both the GoodreadsModel and GoogleBooksModel objects(passed into the method's arguments) is not null. If both are not null then it will check whether the description attribute value //held by each object actually contains a description. If both objects hold information relating to the description then it will check the description held by the GoodreadsModel object is longer than the description held by //the GoogleBookModel object. If it is longer than summarise the description held by the GoodreadsModel object and assign the summarised description to the public BookMode object's data attribute which holds the description. //If it is not longer than summarise the description held by the GoogleBookModel object and assign the summarised description to the public BookMode object's data attribute which holds the description. //However, if one or both objects do not contain a description then it will check whether the description held by the GoodreadsModel is null or empty. If it is not then it will summarise that description and assign the summarised //description to the public BookMode object's data attribute which holds the description. If it is null or empty then it check whether the description held by the GoogleBooksModel is null or empty. If it is not then it will summarise that description and assign the summarised //description to the public BookMode object's data attribute which holds the description. //The second outer else statement is to deal with cases where the GoodreadsModel and/or GoogleBookModel objects is null. If this else statement is satisfied then it will check if the GoogleBooksModel object is null //and if it is not null then it will check whether the description held by the GoogleBookModel object is null or empty. It it's not null or empty then this description will be summarised and the summarised description will be assigned //to the public BookModel object's data attribute that holds the description. If the GoogleBookModel object is null then it will check if the GoodreadsModel object is null //and if it is not null then it will check whether the description held by the GoodreadsModel object is null or empty. It it's not null or empty then this description will be summarised and the summarised description will be assigned //to the public BookModel object's data attribute that holds the description. private void SetDescription(GoodreadsModel goodreadsBookData, GoolgeBooksApi.GoogleBookModel googleBooksBookData) { string summarisedBookDescription; if (goodreadsBookData != null && googleBooksBookData != null) { if (goodreadsBookData.Description.Length > 0 && googleBooksBookData.Description.Length > 0) { if (goodreadsBookData.Description.Length > googleBooksBookData.Description.Length) { summarisedBookDescription = SummariseDescription(goodreadsBookData.Description); bookModel.Description = summarisedBookDescription; } else { summarisedBookDescription = SummariseDescription(googleBooksBookData.Description); bookModel.Description = summarisedBookDescription; } } else { if (!String.IsNullOrEmpty(goodreadsBookData.Description)) { summarisedBookDescription = SummariseDescription(goodreadsBookData.Description); bookModel.Description = summarisedBookDescription; } else if (!String.IsNullOrEmpty(googleBooksBookData.Description)) { summarisedBookDescription = SummariseDescription(googleBooksBookData.Description); bookModel.Description = summarisedBookDescription; } } } else { if (googleBooksBookData != null) { if (!String.IsNullOrEmpty(googleBooksBookData.Description)) { summarisedBookDescription = SummariseDescription(googleBooksBookData.Description); bookModel.Description = summarisedBookDescription; } } else if (goodreadsBookData != null) { if (!String.IsNullOrEmpty(goodreadsBookData.Description)) { summarisedBookDescription = SummariseDescription(goodreadsBookData.Description); bookModel.Description = summarisedBookDescription; } } } }