private static void SaveGrades(IEnumerable <CourseGrade> courseGrades)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(SettingsHelper.GetSetting("ApiUri"));

            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            foreach (var studentGrades in courseGrades.GroupBy(c => c.StudentId))
            {
                var toSave = studentGrades.Select(s => new CourseGradeForApi {
                    CourseId = s.CourseId, Grade = s.Grade
                }).ToArray();
                var jsonObject = JsonConvert.SerializeObject(toSave);
                var content    = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
                var response   = client.PutAsync($"api/student/{studentGrades.Key}", content).Result;

                if (!response.IsSuccessStatusCode)
                {
                    Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                    throw new Exception("Something bad happened");
                }
            }
        }
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        public static void Main()
        {
            var config = new JobHostConfiguration();

            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }

            ServiceBusConfiguration serviceBusConfiguration = new ServiceBusConfiguration {
                ConnectionString = SettingsHelper.GetSetting("Microsoft.ServiceBus.ConnectionString")
            };

            serviceBusConfiguration.MessageOptions.AutoRenewTimeout = TimeSpan.FromMinutes(5);

            config.UseServiceBus(serviceBusConfiguration);

            var host = new JobHost(config);

            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
        private static Student GetStudentInformation(int studentId)
        {
            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(SettingsHelper.GetSetting("ApiUri"));

            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = client.GetAsync($"api/student?id={studentId}").Result;

            if (response.IsSuccessStatusCode)
            {
                var dataObjects = response.GetBodyFromJsonAsync <Student>().Result;
                return(dataObjects);
            }
            else
            {
                Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
            }

            return(null);
        }