Esempio n. 1
0
        /*
         * Prepare your opening times here using the provided HelperServiceRepository class.
         */
        public ActionResult Index()
        {
            HelperServiceRepository helperServiceRepository = new HelperServiceRepository();
            var model = helperServiceRepository.Get();

            return(View(model));
        }
Esempio n. 2
0
 public ActionResult Index()
 {
     try
     {
         IEnumerable <HelperServiceModel> services = new HelperServiceRepository().Get();
         ViewData["Services"] = services;
         return(View("Index", services));
     } catch (Exception ex)
     {
         logger.Error(ex.Message);
     }
     return(View("Index"));
 }
Esempio n. 3
0
        public JsonResult WeatherData(Guid Id)
        {
            //Wouldn't this be better handled on client side? If we had the city or lat/long, we could pass that through direct to openW.
            logger.Info("Calling the weather service.");

            string responseData = string.Empty;

            HelperServiceModel thisService = new HelperServiceRepository().Get(Id);;

            if (thisService == null)
            {
                string message = $"Service with ID: {Id} not found";
                logger.Error(message);
                responseData = new JavaScriptSerializer().Serialize(new { error = message });
                return(Json(responseData, JsonRequestBehavior.AllowGet));
            }

            var request = (HttpWebRequest)WebRequest.Create($"http://api.openweathermap.org/data/2.5/weather?q={thisService.City}&APPID=e016391b92e54bfc19e468e0c7a5b8ec");

            request.Method = "GET";
            var response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                try
                {
                    JsonSerializer serializer = new JsonSerializer();
                    using (Stream dataStream = response.GetResponseStream())
                    {
                        using (var sreader = new StreamReader(dataStream))
                        {
                            responseData = sreader.ReadToEnd();
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    responseData = new JavaScriptSerializer().Serialize(new { error = ex.Message });
                }
            }
            else
            {
                logger.Error("Service not found");
                responseData = new JavaScriptSerializer().Serialize(new { error = "Trouble loading the weather" });
            }

            return(Json(responseData, JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        /*
         * Prepare your opening times here using the provided HelperServiceRepository class.
         */
        public ActionResult Index()
        {
            try
            {
                HelperServiceRepository helperServiceCenter1 = new HelperServiceRepository();

                IEnumerable <HelperServiceModel> helperServiceCenterInfoWithOpeningtimes = helperServiceCenter1.Get();

                foreach (var helpcenter in helperServiceCenterInfoWithOpeningtimes)
                {
                    PrepareOpeningTimes(helpcenter);
                }
                return(View(helperServiceCenterInfoWithOpeningtimes));
            }
            catch (Exception ex)
            {
                Util.Logger("excpetion raised: " + ex.InnerException);
                return(View("Error"));
            }
            finally
            {
                Util.Logger("Time of Access: " + DateTime.Now + "IP address: " + GetIpValue());
            }
        }
Esempio n. 5
0
 public HomeController()
 {
     oHSR = new HelperServiceRepository();
 } // end of constructor
Esempio n. 6
0
 public HomeController()
 {
     helperServiceRepository = new HelperServiceRepository();
 }