Example #1
0
        public static async Task <CategoryResponse> GetCategoriesAsync(string token)
        {
            var url = WebApiUrl.GetConnectionStringForCategories(token);
            var categoryResponse = await RestSharpImp.CallApiGenericGetMethod(new CategoryRequestResponseInfo(), url);

            return(categoryResponse);
        }
Example #2
0
        public static async Task <List <Subscribers> > GetSubscribersAsync(string token)
        {
            var url = WebApiUrl.GetConnectionStringForSubscribers(token);
            var subscribersResponse = await RestSharpImp.CallApiGenericGetMethod(new SubscribersRequestResponseInfo(), url);

            return(subscribersResponse.data.Select(x => new Subscribers {
                Id = x.id, MagazineIds = x.magazineIds
            }).ToList());
        }
Example #3
0
        public static async Task <AnswerResponse> PostAnswerToAPIAsync(List <string> Ids, string token)
        {
            var url           = WebApiUrl.GetConnectionStringForAnswer(token);
            var answerRequest = new AnswerRequest()
            {
                subscribers = Ids
            };
            var payload  = new AnswerRequestResponseInfo(answerRequest);
            var response = await RestSharpImp.CallApiGenericPostMethod(payload, url);

            return(response);
        }
Example #4
0
        public static async Task MyAsyncFunc()
        {
            var url           = WebApiUrl.GetConnectionStringForToken();
            var tokenResponse = await RestSharpImp.CallApiGenericGetMethod(new TokenRequestResponseInfo(), url);

            if (!tokenResponse.Success)
            {
                return;
            }
            var token = tokenResponse.Token;
            var magazineIdsByCategories = GetMagazineIdsByCategoriesAsync(await GetCategoriesAsync(token), token);              // we get categories with associated magazine lists
            var Ids            = GetIdsSubscribedEachCategory(await GetSubscribersAsync(token), await magazineIdsByCategories); // Ids of customers who subscribed for atleast one magazine of each category
            var answerResponse = await PostAnswerToAPIAsync(Ids, token);                                                        // sends the response to api

            PrintPropertiesOfAnswerObject(answerResponse);
        }
Example #5
0
        public static async Task <List <MagazineIdsByCategory> > GetMagazineIdsByCategoriesAsync(CategoryResponse categories, string token)
        {
            var magazineIdsByCategories = new List <MagazineIdsByCategory>();

            foreach (var category in categories.Data)
            {
                var url = WebApiUrl.GetConnectionStringForMagazines(token, category);
                var magazineResponse = await RestSharpImp.CallApiGenericGetMethod(new MagazineRequestResponseInfo(), url);

                var magazineIdByCategory = magazineResponse.Data.GroupBy(x => x.Category).
                                           Select(x => new MagazineIdsByCategory
                {
                    Name = x.Key,
                    Ids  = x.Select(z => z.Id).ToList()
                }).FirstOrDefault();

                magazineIdsByCategories.Add(magazineIdByCategory);
            }
            return(magazineIdsByCategories);
        }