private static WaracleCakeList UnsortedDuplicateList() { //Create test cake list which is unsorted and contains duplicates var unsortedDuplicateList = new WaracleCakeList(); unsortedDuplicateList.Cakes.Add(new WaracleCake("Test Cake 3", "This is a test cake 3", "")); unsortedDuplicateList.Cakes.Add(new WaracleCake("Test Cake 1", "This is a test cake 1", "")); unsortedDuplicateList.Cakes.Add(new WaracleCake("Test Cake 5", "This is a test cake 5", "")); unsortedDuplicateList.Cakes.Add(new WaracleCake("Test Cake 4", "This is a test cake 4", "")); unsortedDuplicateList.Cakes.Add(new WaracleCake("Test Cake 4", "This is a test cake 4", "")); unsortedDuplicateList.Cakes.Add(new WaracleCake("Test Cake 2", "This is a test cake 2", "")); unsortedDuplicateList.Cakes.Add(new WaracleCake("Test Cake 1", "This is a test cake 1", "")); unsortedDuplicateList.Cakes.Add(new WaracleCake("Test Cake 4", "This is a test cake 4", "")); unsortedDuplicateList.Cakes.Add(new WaracleCake("Test Cake 3", "This is a test cake 3", "")); return(unsortedDuplicateList); }
/// <returns><c>WaracleCakeList</c> which will be have duplicates removed, sorted by title, first letter of title and description upper cased</returns> public static async Task <WaracleCakeList> GetCakeList() { var waracleCakeList = new WaracleCakeList(); var networkHelper = ServiceLocator.Current.GetInstance <INetworkHelper>(); var isNetworkAvailable = networkHelper.CheckNetworkStatus(out var networkMessage); try { if (!isNetworkAvailable) { throw new Exception(networkMessage); } var dl = ServiceLocator.Current.GetInstance <IDownloadCakeList>(); var cakeList = await dl.GetCakeList(); if (cakeList == null || cakeList.Count == 0) { throw new Exception("Error retrieving cake list, please try again"); } //Create list from REST API response data //1) Removes any duplicate entries //2) Sorts the list by title //3) Uppercase fist letter of title and desc waracleCakeList.AddRangeWithSort(cakeList); } catch (Exception ex) { //Display appropriate message to user if cake list retrieval failed //The error message is stored in the cake list object waracleCakeList.ErrorMessage = ex.Message; } return(waracleCakeList); }
public async void DownLoadCakeList(Action done = null) { // Record call back function _doneFunc = done; // If we are already loading just return if (Loading) { return; } // If we have already loaded the data just call the callback function and return if (Loaded) { _doneFunc(); return; } // We are loading now Loading = true; try { DownlodedCakeList = await CakesHelper.GetCakeList(); Loaded = true; Loading = false; // if there is a callback function call it. _doneFunc?.Invoke(); } catch (Exception ex) { ErrorMessage = ex.Message; } }