Пример #1
0
        private List <System.Web.Mvc.SelectListItem> LoadWeatherStations(long?weatherStationId = null, WeatherStation weatherStation = null)
        {
            WeatherStationConfiguration wsc = new WeatherStationConfiguration();

            List <WeatherStation> weatherStations       = wsc.GetAllWeatherStations();
            List <System.Web.Mvc.SelectListItem> result = new List <SelectListItem>();

            foreach (var item in weatherStations)
            {
                bool isSelected = false;
                if (weatherStation != null && weatherStationId.HasValue)
                {
                    isSelected = (weatherStation.WeatherStationId == weatherStationId);
                }

                SelectListItem sl = new SelectListItem()
                {
                    Value    = item.WeatherStationId.ToString(),
                    Text     = item.Name,
                    Selected = isSelected
                };

                result.Add(sl);
            }

            return(result);
        }
Пример #2
0
        public ActionResult Create([Bind(Include = "WeatherStationId,Name,Model,DateOfInstallation,DateOfService,UpdateTime,WirelessTransmission,GiveET,WeatherDataType, Enabled, Latitude, Longitude, FarmIdSelected")] WeatherStationViewModel wsm)
        {
            var a = wsm.FarmId;

            if (ModelState.IsValid)
            {
                WeatherStation ws = new WeatherStation();

                long lPositionId = GetPositionId(wsm.Latitude, wsm.Longitude);
                //Not exist position to farm
                if (lPositionId == 0)
                {
                    Position lPosition = new Position();
                    lPosition.Latitude  = wsm.Latitude;
                    lPosition.Longitude = wsm.Longitude;
                    lPosition.Name      = wsm.Name + " - Estación meteorológica";
                    ws.Position         = lPosition;
                }
                else
                {
                    ws.PositionId = lPositionId;
                }
                ws.DateOfInstallation = wsm.DateOfInstallation;
                ws.DateOfService      = wsm.DateOfService;
                ws.Enabled            = wsm.Enabled;
                ws.GiveET             = wsm.GiveET;
                ws.Model                = wsm.Model;
                ws.Name                 = wsm.Name;
                ws.StationType          = wsm.StationType;
                ws.UpdateTime           = wsm.UpdateTime;
                ws.WeatherDataType      = wsm.WeatherDataType;
                ws.WebAddress           = wsm.WebAddress;
                ws.WirelessTransmission = wsm.WirelessTransmission;

                db.WeatherStations.Add(ws);
                db.SaveChanges();

                WeatherStationConfiguration wsc = new WeatherStationConfiguration();
                long lastWeatherStationId       = wsc.GetMaxWeatherStationId();

                //Save Relation whit Farm
                if (wsm.FarmIdSelected != null)
                {
                    string[] farmIds = wsm.FarmIdSelected.Split('|');
                    foreach (var farmId in farmIds)
                    {
                        Farm lFarm = db.Farms.Find(int.Parse(farmId));
                        lFarm.WeatherStationId = lastWeatherStationId;
                        db.Entry(lFarm).State  = EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }
            return(Redirect("/WeatherStations"));
            // return View("~/Views/Weather/WeatherStations/Index.cshtml", db.WeatherStations.ToList());
        }
Пример #3
0
        public ActionResult DeleteConfirmed(long id)
        {
            WeatherStationConfiguration wsc = new WeatherStationConfiguration();
            WeatherStation ws = db.WeatherStations.Find(id);

            wsc.Disable(ws);
            db.SaveChanges();
            return(Redirect("/WeatherStations"));
            // return View("~/Views/Weather/WeatherStations/Index.cshtml", db.WeatherStations.ToList());
        }
Пример #4
0
        private List <System.Web.Mvc.SelectListItem> LoadWeatherStation(long?weatherStationId = null, Farm farm = null)
        {
            WeatherStationConfiguration          rc = new WeatherStationConfiguration();
            List <WeatherStation>                weatherStationConfiguration = rc.GetAllWeatherStations();
            List <System.Web.Mvc.SelectListItem> result = new List <SelectListItem>();

            foreach (var item in weatherStationConfiguration)
            {
                bool isSelected = false;

                SelectListItem sl = new SelectListItem()
                {
                    Value    = item.WeatherStationId.ToString(),
                    Text     = item.Name,
                    Selected = isSelected
                };

                result.Add(sl);
            }

            return(result);
        }