public DailyExecutionReportViewModel() { NLSList = new List<NLSViewModel>(); Highlights = new List<HighlightViewModel>(); Alert = new AlertViewModel(); Weather = new WeatherViewModel(); HighlightGroups = new List<HighlightGroupViewModel>(); HighlightGroupTemplates = new List<HighlightGroupViewModel>(); }
public RefreshCommand(WeatherViewModel viewModel) { ViewModel = viewModel; }
public async Task <ActionResult> GetWeatherObject(SearchModel model) { if (ModelState.IsValid) { var vm = new WeatherViewModel(); var trip = new Trip() { Location = model.Location, StartDate = model.StartDate, Duration = model.Duration }; var tripId = _tripPackingService.CreateTrip(trip); var historicalWeather = await _weatherClient.GetHistoricalWeather(model.Location, model.StartDate, model.Duration); var cityName = historicalWeather.Select(x => x.Location).Select(x => x.Name).Distinct().FirstOrDefault(); var regionName = historicalWeather.Select(x => x.Location).Select(x => x.Region).Distinct().FirstOrDefault(); vm.Historicals = MapForecast(historicalWeather); vm.CityName = cityName; vm.RegionName = regionName; vm.StartDate = model.StartDate.ToString("d"); vm.EndDate = model.StartDate.AddDays(model.Duration - 1).ToString("d"); if (model.StartDate <= DateTime.Now.AddDays(5)) { TimeSpan interval = model.StartDate - DateTime.Today; var days = model.Duration + interval.Days; if (days > 10) { var forecastWeather10Days = await _weatherClient.GetForecastWeather(model.Location, 10); vm.Forecasts = MapForecast(forecastWeather10Days); } var forecastWeather = await _weatherClient.GetForecastWeather(model.Location, days); vm.Forecasts = MapForecast(forecastWeather); } // the ?: is a ternary operator: this is what it does // if vm.forecasts is not null, then get items based on forcasts; otherwise, get items based on historicals var itemsToPack = GetPackingItems( vm.Forecasts != null ? vm.Forecasts : vm.Historicals, model.Duration, tripId); List <Container> containers = new List <Container>(); containers.Add(new Container(1, "Carry-On", 104M, 20.5M, 15M, 8M)); //samsonite 21" Spinner - 43.5 total containers.Add(new Container(2, "Medium Suitcase", 144.88M, 23M, 17M, 9M)); //samsonite 27" Spinner (27M, 18.5M,9.5M) - 55 total containers.Add(new Container(3, "Large Suitcase", 145.6M, 29.5M, 20.5M, 11M)); //62" (must be 62" and 50 lbs or less) List <Item> itemsToContainer = new List <Item>(); foreach (var item in itemsToPack) { itemsToContainer.Add(new Item(item.Name, item.Height, item.Length, item.Width, Convert.ToInt32(item.Quantity))); } List <int> algorithms = new List <int>(); algorithms.Add((int)AlgorithmType.EB_AFIT); List <ContainerPackingResult> packingResults = new List <ContainerPackingResult>(); var totalItemWeight = itemsToPack.Select(x => x.TotalWeight).Sum(); for (int i = containers.Count - 1; i >= 0; i--) { packingResults = PackingService.Pack(containers[i], itemsToContainer, algorithms); var packResult = packingResults.SelectMany(x => x.AlgorithmPackingResults).SelectMany(x => x.UnpackedItems).Count(); if (packResult == 0) { var containerWeight = packingResults.Select(x => x.Weight).Sum(); var totalWeight = (containerWeight + totalItemWeight) * .0625M; //converts weight in ounces to pounds vm.PackingItems = itemsToPack; vm.ContainerPackingResults = packingResults; vm.TotalWeightInLbs = totalWeight; } } return(View("Result", vm)); } return(RedirectToAction("Index", "Home")); }
public IActionResult Index() { WeatherViewModel weather = _service.GetWeatherAsync().Result; return(View(weather)); }
// Database Init public HomeController(Database database, UserContext context) { _database = database; _context = context; _weatherViewModel = new WeatherViewModel(); }
public TemperatureToFormattedTemperatureConverter() { _weatherViewModel = ServiceLocator.Current.GetInstance <WeatherViewModel>(); }
public async Task Test1Async() { //Mock the forecast service var mockForecastService = new Mock <IForecastsService>(); mockForecastService.Setup(a => a.GetForecastAsync(It.IsAny <double>(), It.IsAny <double>(), It.IsAny <TemperatureUnit>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult( new Forecast { Id = "MockForecast", CurrentTemperature = "900", Description = "It's way too hot", MinTemperature = "800", MaxTemperature = "1000", Name = "Forecast Name", Overview = "Forecast Overview" })); ServiceContainer.Register <IForecastsService>(mockForecastService.Object); //Mock the image service var mockImageService = new Mock <IImageService>(); mockImageService.Setup(a => a.GetImageAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult("Image URL")); ServiceContainer.Register <IImageService>(mockImageService.Object); //Mock geolocation var mockGeolocationService = new Mock <IGeolocationService>(); mockGeolocationService.Setup(a => a.GetLastKnownLocationAsync()) .Returns(Task.FromResult(new Coordinates())); mockGeolocationService.Setup(a => a.GetLocationAsync()) .Returns(Task.FromResult(new Coordinates())); ServiceContainer.Register <IGeolocationService>(mockGeolocationService.Object); //Mock geocoding service var mockGeocodingService = new Mock <IGeocodingService>(); mockGeocodingService.Setup(a => a.GetPlacesAsync(It.IsAny <Coordinates>())) .Returns(Task.FromResult(new List <Place> { new Place { CityName = "MobCAT City" } }.AsEnumerable())); ServiceContainer.Register <IGeocodingService>(mockGeocodingService.Object); //Mock the value cache service var mockValueCacheService = new Mock <IValueCacheService>(); ServiceContainer.Register <IValueCacheService>(mockValueCacheService.Object); //Mock the localization service var mockLocalizationService = new Mock <ILocalizationService>(); mockLocalizationService.Setup(a => a.Translate(It.IsAny <string>())) .Returns <string>(x => x); //Just return what was passed in ServiceContainer.Register <ILocalizationService>(mockLocalizationService.Object); //Init the VM var weatherViewModel = new WeatherViewModel(); await weatherViewModel.InitAsync(); //Get expecteds for asserts var expectedImage = await mockImageService.Object.GetImageAsync(default(string), default(String), default(CancellationToken)); var expectedForecast = await mockForecastService.Object.GetForecastAsync(default(double), default(double), default(TemperatureUnit), default(CancellationToken)); var expectedPlaces = await mockGeocodingService.Object.GetPlacesAsync(default(Coordinates)); var expectedPlaceName = expectedPlaces?.FirstOrDefault()?.CityName; var weatherDescriptionTranslationResourceKey = expectedForecast.Overview.Trim().Replace(" ", "").ToLower(); //Assert Assert.Equal(weatherDescriptionTranslationResourceKey, weatherViewModel.WeatherDescription); Assert.Equal(expectedForecast.CurrentTemperature, weatherViewModel.CurrentTemp); Assert.Equal(expectedForecast.MaxTemperature, weatherViewModel.HighTemp); Assert.Equal(expectedForecast.MinTemperature, weatherViewModel.LowTemp); Assert.Equal(expectedImage, weatherViewModel.WeatherImage); Assert.Equal(expectedPlaceName, weatherViewModel.CityName); }
public ActionResult Index() { WeatherViewModel model = new WeatherViewModel(); List <Festival> fests = new List <Festival> { new Festival { City = "Reading", Date = new DateTime(2019, 08, 24).ToShortDateString(), Name = "Reading", Latitude = "51.724955", Longitude = "-0.350472", Weather = new List <Weather> { new Weather { Year = 2019, WindDirection = Enums.WindDirection.NE, FeelsLikeTemp = 21, Temperature = 20, Humidity = 85, Visibility = Enums.Visibility.Good, WeatherType = Enums.WeatherType.Sunny, WindSpeed = 12 }, new Weather { Year = 2018, WindDirection = Enums.WindDirection.NW, FeelsLikeTemp = 15, Temperature = 20, Humidity = 55, Visibility = Enums.Visibility.Good, WeatherType = Enums.WeatherType.PartlySunny, WindSpeed = 12 }, new Weather { Year = 2017, WindDirection = Enums.WindDirection.SE, FeelsLikeTemp = 10, Temperature = 6, Humidity = 65, Visibility = Enums.Visibility.Poor, WeatherType = Enums.WeatherType.LightRain, WindSpeed = 17 }, new Weather { Year = 2016, WindDirection = Enums.WindDirection.W, FeelsLikeTemp = 15, Temperature = 15, Humidity = 60, Visibility = Enums.Visibility.Okay, WeatherType = Enums.WeatherType.Clear, WindSpeed = 5 }, } }, new Festival { City = "Donington", Date = new DateTime(2019, 06, 24).ToShortDateString(), Name = "Download", Latitude = "51.654786", Longitude = "-0.359475", Weather = new List <Weather> { new Weather { Year = 2019, WindDirection = Enums.WindDirection.NE, FeelsLikeTemp = 3, Temperature = 2, Humidity = 100, Visibility = Enums.Visibility.Poor, WeatherType = Enums.WeatherType.HeavyRain, WindSpeed = 12 }, new Weather { Year = 2018, WindDirection = Enums.WindDirection.NW, FeelsLikeTemp = 15, Temperature = 20, Humidity = 55, Visibility = Enums.Visibility.Good, WeatherType = Enums.WeatherType.PartlySunny, WindSpeed = 12 }, new Weather { Year = 2017, WindDirection = Enums.WindDirection.SE, FeelsLikeTemp = 10, Temperature = 6, Humidity = 65, Visibility = Enums.Visibility.Poor, WeatherType = Enums.WeatherType.Rain, WindSpeed = 17 }, new Weather { Year = 2016, WindDirection = Enums.WindDirection.W, FeelsLikeTemp = 15, Temperature = 15, Humidity = 60, Visibility = Enums.Visibility.Okay, WeatherType = Enums.WeatherType.Clear, WindSpeed = 5 }, } }, new Festival { City = "Glastonbury", Date = new DateTime(2019, 07, 11).ToShortDateString(), Name = "Glastonbury", Latitude = "51.784512", Longitude = "-0.356895", Weather = new List <Weather> { new Weather { Year = 2019, WindDirection = Enums.WindDirection.NE, FeelsLikeTemp = 3, Temperature = 2, Humidity = 100, Visibility = Enums.Visibility.Poor, WeatherType = Enums.WeatherType.HeavyRain, WindSpeed = 12 }, new Weather { Year = 2018, WindDirection = Enums.WindDirection.NW, FeelsLikeTemp = 15, Temperature = 20, Humidity = 55, Visibility = Enums.Visibility.Good, WeatherType = Enums.WeatherType.PartlySunny, WindSpeed = 12 }, new Weather { Year = 2017, WindDirection = Enums.WindDirection.SE, FeelsLikeTemp = 10, Temperature = 6, Humidity = 65, Visibility = Enums.Visibility.Poor, WeatherType = Enums.WeatherType.Rain, WindSpeed = 17 }, new Weather { Year = 2016, WindDirection = Enums.WindDirection.W, FeelsLikeTemp = 15, Temperature = 15, Humidity = 60, Visibility = Enums.Visibility.Okay, WeatherType = Enums.WeatherType.Clear, WindSpeed = 5 }, } }, }; model.Weather = fests; return(View(model)); }
// ---------------------------------------------------------------- // ---------------------------------------------------------------- public SearchCommand(WeatherViewModel viewModel) { ViewModel = viewModel; }
public RefreshCommand(WeatherViewModel vm) { this.VM = vm; }
public ActionResult WeatherDetail(string City) { //Assign API KEY which received from OPENWEATHERMAP.ORG string appId = "2c764384532120a441275cd0bc63bf69"; //API path with CITY parameter and other parameters. string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&units=metric&cnt=1&APPID={1}", City, appId); using (WebClient client = new WebClient()) { string json = string.Empty; RootObject weatherInfo = new RootObject(); try { json = client.DownloadString(url); //Converting to OBJECT from JSON string. weatherInfo = (new System.Web.Script.Serialization.JavaScriptSerializer()).Deserialize <RootObject>(json); } catch (Exception) { return(Json(new { status = "error" })); } //********************// // JSON RECIVED //********************// //{"coord":{ "lon":72.85,"lat":19.01}, //"weather":[{"id":711,"main":"Smoke","description":"smoke","icon":"50d"}], //"base":"stations", //"main":{"temp":31.75,"feels_like":31.51,"temp_min":31,"temp_max":32.22,"pressure":1014,"humidity":43}, //"visibility":2500, //"wind":{"speed":4.1,"deg":140}, //"clouds":{"all":0}, //"dt":1578730750, //"sys":{"type":1,"id":9052,"country":"IN","sunrise":1578707041,"sunset":1578746875}, //"timezone":19800, //"id":1275339, //"name":"Mumbai", //"cod":200} //Special VIEWMODEL design to send only required fields not all fields which received from //www.openweathermap.org api WeatherViewModel rslt = new WeatherViewModel(); rslt.Country = weatherInfo.sys.country; rslt.City = weatherInfo.name; rslt.Lat = Convert.ToString(weatherInfo.coord.lat); rslt.Lon = Convert.ToString(weatherInfo.coord.lon); rslt.Description = weatherInfo.weather[0].description; rslt.Humidity = Convert.ToString(weatherInfo.main.humidity); rslt.Temp = Convert.ToString(weatherInfo.main.temp); rslt.TempFeelsLike = Convert.ToString(weatherInfo.main.feels_like); rslt.TempMax = Convert.ToString(weatherInfo.main.temp_max); rslt.TempMin = Convert.ToString(weatherInfo.main.temp_min); rslt.WeatherIcon = weatherInfo.weather[0].icon; //Converting OBJECT to JSON String var jsonstring = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(rslt); //Return JSON string. return(Json(new { Weather = jsonstring })); } }
public static WeatherViewModel getLocalWeather(String UserIP) { String JSonContent = String.Empty; int DelayHours = 0; //If local server set it to dubai address MaxMind.GeoIP2.Responses.CityResponse city = new MaxMind.GeoIP2.Responses.CityResponse(); var WeatherView = new WeatherViewModel(); WeatherView.Forecast = new List <Forcast>(); String DatabaseLocation = HttpContext.Current.Server.MapPath("/GeoLiteCity/GeoLite2-City.mmdb"); using (var reader = new DatabaseReader(DatabaseLocation)) { // Replace "City" with the appropriate method for your database, e.g., // "Country". try { city = reader.City(UserIP); WeatherView.Country = city.Country.Name; // 'United States' WeatherView.City = city.City.Name; } catch { //do any error processing } }//using(var reader) if (String.IsNullOrEmpty(WeatherView.Country)) { WeatherView.Country = "United Arab Emirates"; } if (String.IsNullOrEmpty(WeatherView.City)) { WeatherView.City = "Dubai"; } do { String CacheFile = getWeatherFile(WeatherView.Country, WeatherView.City, DelayHours); if (!File.Exists(CacheFile)) { JSonContent = DownloadWeatherInfo(WeatherView.Country, WeatherView.City, CacheFile); } else { JSonContent = File.ReadAllText(CacheFile); } DelayHours = DelayHours - 4; } while (JSonContent.Length <= 10); dynamic WeatherInfo = System.Web.Helpers.Json.Decode(JSonContent); if (WeatherInfo != null) { var WeatherNow = WeatherInfo.data.current_condition[0]; WeatherView.ConditionText = WeatherNow.weatherDesc[0].value; WeatherView.ConditionCode = WeatherNow.weatherCode; WeatherView.Speed = WeatherNow.windspeedKmph; WeatherView.ConditionTemperature = Util.toDouble(WeatherNow.temp_C).ToString("0.0"); if (WeatherView.ConditionTemperature == "0.0") { Double Temp = (Util.toDouble(WeatherNow.temp_F) - 32) / 1.8; WeatherView.ConditionTemperature = Temp.ToString("0.0"); } WeatherView.TemperatureUnit = "°C"; WeatherView.Pressure = Util.toDouble(WeatherNow.pressure); WeatherView.Wind = WeatherNow.windspeedKmph; WeatherView.Direction = WeatherNow.winddirDegree; WeatherView.Visibility = Util.toDouble(WeatherNow.visibility); WeatherView.Humidity = WeatherNow.humidity; foreach (var ForcastDay in WeatherInfo.data.weather) { var thisForcast = new Forcast { Code = Util.toInt(ForcastDay.hourly[3].weatherCode), Date = (DateTime.Parse(ForcastDay.date)).ToString("dd MMM"), status = ForcastDay.hourly[3].weatherDesc[0].value, TempHigh = ForcastDay.maxtempC, TempLow = ForcastDay.mintempC }; WeatherView.Forecast.Add(thisForcast); } } //var intAddress = BitConverter.ToInt64(IPAddress.Parse(UserIP).GetAddressBytes(), 0); return(WeatherView); }
public ViewController(IntPtr handle) : base(handle) { weatherViewModel = new WeatherViewModel(); }
public WheaterPage() { InitializeComponent(); vm = WeatherViewModel.INSTANCE ?? new WeatherViewModel(); this.GetCity(); }
public async Task <IActionResult> Index(WeatherViewModel weather) { WeatherViewModel weatherViewModel = await _weatherService.GetTemperature(weather); return(View(weatherViewModel)); }
public async Task <IActionResult> Get() { WeatherViewModel weather = await _service.GetWeatherAsync(); return(Ok(weather)); }
public SearchCommand(WeatherViewModel vm) { WeatherVM = vm; }
public static WeatherViewModel WeatherAdjustment(WeatherViewModel weatherViewModel) { Double dewPoint = weatherViewModel.DewPoint; List <RecipeItem> items = weatherViewModel.Items.ToList(); if (dewPoint <= 20) { foreach (var i in items) { if (KeyWordLists.Liquids.Contains(i.RecipeIngredient.Name.ToLower())) { i.RecipeMeasurement.Value = (i.RecipeMeasurement.Value) + (i.RecipeMeasurement.Value * .10); weatherViewModel.AdjustedLiquid = i.RecipeIngredient.Name; weatherViewModel.AdjustmentMessage = $"was added to {i.RecipeIngredient.Name} weight."; weatherViewModel.AdjustmentPercent = "10 % "; } } } else if (dewPoint >= 21 && dewPoint <= 40) { foreach (var i in items) { if (KeyWordLists.Liquids.Contains(i.RecipeIngredient.Name.ToLower())) { i.RecipeMeasurement.Value = (i.RecipeMeasurement.Value) + (i.RecipeMeasurement.Value * .05); weatherViewModel.AdjustedLiquid = i.RecipeIngredient.Name; weatherViewModel.AdjustmentMessage = $"was added to {i.RecipeIngredient.Name} weight."; weatherViewModel.AdjustmentPercent = "5 % "; } } } else if (dewPoint >= 41 && dewPoint <= 60) { foreach (var i in items) { if (KeyWordLists.Liquids.Contains(i.RecipeIngredient.Name.ToLower())) { i.RecipeMeasurement.Value = i.RecipeMeasurement.Value; weatherViewModel.AdjustmentMessage = "No adjustments made."; } } } else if (dewPoint >= 61 && dewPoint <= 70) { foreach (var i in items) { if (KeyWordLists.Liquids.Contains(i.RecipeIngredient.Name.ToLower())) { i.RecipeMeasurement.Value = (i.RecipeMeasurement.Value) - (i.RecipeMeasurement.Value * .05); weatherViewModel.AdjustedLiquid = i.RecipeIngredient.Name; weatherViewModel.AdjustmentMessage = $"was subtracted from {i.RecipeIngredient.Name} weight."; weatherViewModel.AdjustmentPercent = "5 % "; } } } else if (dewPoint >= 71 && dewPoint <= 80) { foreach (var i in items) { if (KeyWordLists.Liquids.Contains(i.RecipeIngredient.Name.ToLower())) { i.RecipeMeasurement.Value = (i.RecipeMeasurement.Value) - (i.RecipeMeasurement.Value * .10); weatherViewModel.AdjustedLiquid = i.RecipeIngredient.Name; weatherViewModel.AdjustmentMessage = $"was subtracted from {i.RecipeIngredient.Name} weight."; weatherViewModel.AdjustmentPercent = "10 % "; } } } else { foreach (var i in items) { if (KeyWordLists.Liquids.Contains(i.RecipeIngredient.Name.ToLower())) { i.RecipeMeasurement.Value = (i.RecipeMeasurement.Value) - (i.RecipeMeasurement.Value * .15); weatherViewModel.AdjustedLiquid = i.RecipeIngredient.Name; weatherViewModel.AdjustmentMessage = $"was subtracted from {i.RecipeIngredient.Name} weight."; weatherViewModel.AdjustmentPercent = "15 % "; } } } double hydration = Conversions.HydrationLevel(items); List <double> totalWeights = Conversions.TotalWeights(items); WeatherViewModel viewModel = new WeatherViewModel { City = weatherViewModel.City, Temp = weatherViewModel.Temp, Humidity = weatherViewModel.Humidity, DewPoint = weatherViewModel.DewPoint, BreadID = weatherViewModel.BreadID, Bread = weatherViewModel.Bread, Items = items, Hydration = hydration, TotalWeights = totalWeights, AdjustedLiquid = weatherViewModel.AdjustedLiquid, AdjustmentMessage = weatherViewModel.AdjustmentMessage, AdjustmentPercent = weatherViewModel.AdjustmentPercent }; return(viewModel); }
public Weather() { InitializeComponent(); binding = (WeatherViewModel)Content.BindingContext; }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; weatherVM = new WeatherViewModel(); }
public SearchCommand(WeatherViewModel weatherViewModel) { WeatherViewModel = weatherViewModel; }
public CardWeather(WeatherViewModel viewmodel) { InitializeComponent(); BindingContext = vm = viewmodel; }
public void UpdateDisplay(WeatherViewModel model) { lock (renderLock) { if (isRendering) { Console.WriteLine("Already in a rendering loop, bailing out."); return; } isRendering = true; } graphics.Clear(); graphics.Stroke = 1; graphics.DrawRectangle(0, 0, display.Width, display.Height, Color.White, true); DisplayJPG(model.WeatherCode, 5, 5); string date = model.DateTime.ToString("MM/dd/yy"); // $"11/29/20"; graphics.DrawText( x: 128, y: 24, text: date, color: Color.Black); string time = model.DateTime.AddHours(1).ToString("hh:mm"); // $"12:16 AM"; graphics.DrawText( x: 116, y: 66, text: time, color: Color.Black, scaleFactor: GraphicsLibrary.ScaleFactor.X2); string outdoor = $"Outdoor"; graphics.DrawText( x: 134, y: 143, text: outdoor, color: Color.Black); string outdoorTemp = model.OutdoorTemperature.ToString("00°C"); graphics.DrawText( x: 128, y: 178, text: outdoorTemp, color: Color.Black, scaleFactor: GraphicsLibrary.ScaleFactor.X2); string indoor = $"Indoor"; graphics.DrawText( x: 23, y: 143, text: indoor, color: Color.Black); string indoorTemp = model.IndoorTemperature.ToString("00°C"); graphics.DrawText( x: 11, y: 178, text: indoorTemp, color: Color.Black, scaleFactor: GraphicsLibrary.ScaleFactor.X2); graphics.Show(); isRendering = false; }
public ActionResult DisplayWeather(int?month, int?year, int?page) { IQueryable <Weather> weathers = db.Weathers; IQueryable <Weather> emptyWeathers = new List <Weather>().AsQueryable(); WeatherViewModel weatherViewModel = new WeatherViewModel(); weatherViewModel.YearFilter = year; weatherViewModel.MonthFilter = month; Dictionary <int, string> dictionaryToSelectList = new Dictionary <int, string>(); List <int> yearsFromDatabase = (from yearInt in weathers select yearInt.WeatherDateTime.Year).Distinct().ToList(); foreach (int y in yearsFromDatabase) { dictionaryToSelectList.Add(y, $"{y}"); } dictionaryToSelectList.Add(0, "Все года"); if (weathers.Count() == 0) { ViewBag.Message = "В базе отстуствуют данные. Пожалуйста, загрузите данные в базу."; } if (year == 0 && month != 0) { weathers = emptyWeathers; ViewBag.Message = "Пожалуйста, выберите год"; } else if (year != 0 && month != 0) { weathers = weathers.Where(w => w.WeatherDateTime.Year == year && w.WeatherDateTime.Month == month); } else if (year != 0 && month == 0) { weathers = weathers.Where(w => w.WeatherDateTime.Year == year); } List <MonthSelectListModel> monthSelectList = new List <MonthSelectListModel>() { new MonthSelectListModel { MonthId = 0, MonthName = "Все месяца" }, new MonthSelectListModel { MonthId = 1, MonthName = "Январь" }, new MonthSelectListModel { MonthId = 2, MonthName = "Февраль" }, new MonthSelectListModel { MonthId = 3, MonthName = "Март" }, new MonthSelectListModel { MonthId = 4, MonthName = "Апрель" }, new MonthSelectListModel { MonthId = 5, MonthName = "Май" }, new MonthSelectListModel { MonthId = 6, MonthName = "Июнь" }, new MonthSelectListModel { MonthId = 7, MonthName = "Июль" }, new MonthSelectListModel { MonthId = 8, MonthName = "Август" }, new MonthSelectListModel { MonthId = 9, MonthName = "Сентябрь" }, new MonthSelectListModel { MonthId = 10, MonthName = "Октябрь" }, new MonthSelectListModel { MonthId = 11, MonthName = "Ноябрь" }, new MonthSelectListModel { MonthId = 12, MonthName = "Декабрь" }, }; int pageSize = 16; int pageNumber = (page ?? 1); weatherViewModel.Weathers = weathers.OrderBy(w => w.WeatherDateTime).ToPagedList(pageNumber, pageSize); weatherViewModel.Month = new SelectList(monthSelectList, "MonthID", "MonthName"); weatherViewModel.Year = new SelectList(dictionaryToSelectList, "Key", "Value"); return(View(weatherViewModel)); }
public WeatherPage() { InitializeComponent(); Model = new WeatherViewModel(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); var toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); var iconView = FindViewById <ImageView>(Resource.Id.icon); var nameView = FindViewById <TextView>(Resource.Id.name); var temperatureView = FindViewById <TextView>(Resource.Id.temperature); locationProvider = LocationServices.GetFusedLocationProviderClient(this); var provider = new WeatherViewModelProvider(new LocationProvider(locationProvider), new DefaultWeatherProvider()); var iconConverter = new WeatherIconConverter(); viewModel = new WeatherViewModel(provider, iconConverter); viewModel.DataChanged += data => { nameView.Text = data.Name; temperatureView.Text = $"{Convert.ToInt32(data.Temp)}\u2103"; Drawable icon = null; switch (data.IconType) { case WeatherIcon.CLEAR_SKY_DAY: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.d01, null); break; case WeatherIcon.CLEAR_SKY_NIGHT: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.n01, null); break; case WeatherIcon.FEW_CLOUDS_DAY: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.d02, null); break; case WeatherIcon.FEW_CLOUDS_NIGHT: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.n02, null); break; case WeatherIcon.SCATTERED_CLOUDS: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m03, null); break; case WeatherIcon.BROKEN_CLOUDS: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m04, null); break; case WeatherIcon.SHOWER_RAIN: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m09, null); break; case WeatherIcon.RAIN_DAY: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.d10, null); break; case WeatherIcon.RAIN_NIGHT: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.n10, null); break; case WeatherIcon.THUNDERSTORM: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m11, null); break; case WeatherIcon.SNOW: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m13, null); break; case WeatherIcon.MIST: icon = VectorDrawableCompat.Create(Resources, Resource.Drawable.m50, null); break; } iconView.SetImageDrawable(icon); }; }
public ActionResult Result(WeatherViewModel model) { return(View(model)); }
public WeatherViewModelTests() { _providerMock = new Mock <IWeatherProvider>(); _viewModel = new WeatherViewModel(_providerMock.Object); }
public WeatherPage() { InitializeComponent(); BindingContext = new WeatherViewModel(); }
private void weatherButton_Click(object sender, RoutedEventArgs e) { DataContext = new WeatherViewModel(); logger.Info("Button show weather clicked"); }
public MainPage() { DataContext = new WeatherViewModel(); this.InitializeComponent(); }
public WeatherViewModel GetWeatherInfo(string IpAddress) { WeatherViewModel weatherViewModel = null; IPLocationService IPLocationService = new IPLocationService(); string cityName = IPLocationService.getCity(IpAddress); if (string.IsNullOrEmpty(cityName)) { cityName = "深圳"; } try { WeatherService.WeatherWebServiceSoapClient aService = new WeatherService.WeatherWebServiceSoapClient(); if (cityName.Contains("市")) { cityName = cityName.Substring(0, cityName.Length - 1); } string[] wa = aService.getWeatherbyCityName(cityName); if (!string.IsNullOrEmpty(wa[1])) { weatherViewModel = new WeatherViewModel(); weatherViewModel.cityName = wa[1]; weatherViewModel.airTemperature = wa[5]; weatherViewModel.meteorological = wa[6]; return weatherViewModel; } else { return weatherViewModel; } } catch (Exception ex) { Logger.Error("GetWeatherInfo" + ex.Message, ex); return null; } }