예제 #1
0
 public ActionResult Create()
 {
     var viewModel = new WeatherViewModel();
     foreach (var name in Enum.GetNames(typeof(PeriodeType)))
     {
         if (!name.Equals("Hourly") && !name.Equals("Weekly"))
         {
             viewModel.PeriodeTypes.Add(new SelectListItem { Text = name, Value = name });
         }
     }
     viewModel.Values = _selectService.GetSelect(new GetSelectRequest { Name = "weather-values" }).Options
         .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Text }).ToList();
     return View(viewModel);
 }
예제 #2
0
 public ActionResult Edit(WeatherViewModel viewModel)
 {
     var request = viewModel.MapTo<SaveWeatherRequest>();
     _weatherService.SaveWeather(request);
     return RedirectToAction("Index");
 }
예제 #3
0
 public ActionResult UpdateWeather(WeatherViewModel viewModel)
 {
     var weather = _weatherService.GetWeather(new GetWeatherRequest
     {
         Date = viewModel.Date,
         ByDate = true
     });
     if (weather.Id == 0)
     {
         var request = viewModel.MapTo<SaveWeatherRequest>();
         var resp = _weatherService.SaveWeather(request);
         return Json(resp);
     }
     else
     {
         var request = viewModel.MapTo<SaveWeatherRequest>();
         request.Id = weather.Id;
         request.Temperature = weather.Temperature;
         request.ValueId = viewModel.ValueId;
         var resp = _weatherService.SaveWeather(request);
         return Json(resp);
     }
 }
예제 #4
0
        public ActionResult Manage()
        {
            var viewModel = new WeatherViewModel();
            var id = string.IsNullOrEmpty(Request.QueryString["WeatherId"]) ? 0 : int.Parse(Request.QueryString["WeatherId"]);
            if (id != 0)
            {
                viewModel = _weatherService.GetWeather(new GetWeatherRequest { Id = id }).MapTo<WeatherViewModel>();
            }
            else {
                viewModel.PeriodeType = string.IsNullOrEmpty(Request.QueryString["PeriodeType"]) ? "Daily"
                    : Request.QueryString["PeriodeType"];
                var periodeQS = !string.IsNullOrEmpty(Request.QueryString["Periode"]) ? Request.QueryString["Periode"] : null;
                switch (viewModel.PeriodeType)
                {
                    case "Monthly":
                        if (!string.IsNullOrEmpty(periodeQS))
                        {
                            viewModel.Date = DateTime.ParseExact("01/" + periodeQS, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        }

                        break;
                    case "Yearly":
                        if (!string.IsNullOrEmpty(periodeQS))
                        {
                            viewModel.Date = DateTime.ParseExact("01/01/" + periodeQS, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                        }

                        break;
                    default:
                        if (!string.IsNullOrEmpty(periodeQS))
                        {
                            viewModel.Date = DateTime.ParseExact(periodeQS, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                        }

                        break;
                }
            }
            foreach (var name in Enum.GetNames(typeof(PeriodeType)))
            {
                if (!name.Equals("Hourly") && !name.Equals("Weekly"))
                {
                    viewModel.PeriodeTypes.Add(new SelectListItem { Text = name, Value = name });
                }
            }
            viewModel.Values = _selectService.GetSelect(new GetSelectRequest { Name = "weather-values" }).Options
                .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Text }).ToList();
            return View(viewModel);
        }
예제 #5
0
파일: HtmlHelpers.cs 프로젝트: fazar/Pear
 public static MvcHtmlString DisplayWeatherList(this HtmlHelper htmlHelper, WeatherViewModel viewModel, int tabIndex)
 {
     var value = "";
     var id = 0;
     var derValueType = "empty";
     if (viewModel != null)
     {
         value = viewModel.ValueId.ToString();
         id = viewModel.Id;
         derValueType = viewModel.DerValueType;
     }
     var selectInput = string.Format("<select class=\"der-value-{0} form-control der-highlight-weather\" tabindex=\"{1}\"  data-id=\"{2}\" >", derValueType, tabIndex, id);
     foreach (var option in viewModel.Values)
     {
         var selected = string.Equals(option.Value, value, StringComparison.InvariantCultureIgnoreCase) ? "selected=\"selected\"" : "";
         selectInput += string.Format("<option {2} value=\"{0}\">{1}</option>", option.Value, option.Text, selected);
     }
     selectInput += "</select>";
     return new MvcHtmlString(selectInput);
 }