// GET: WeatherStations/Create public ActionResult Create() { WeatherStationViewModel vm = new WeatherStationViewModel(); vm.Farms = this.LoadFarms(); return(View("~/Views/Weather/WeatherStations/Create.cshtml", vm)); }
// GET: WeatherStations/Details/5 public ActionResult Details(long?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } WeatherStation ws = db.WeatherStations.Find(id); if (ws == null) { return(HttpNotFound()); } WeatherStationViewModel vm = new WeatherStationViewModel(); vm.WeatherStationId = ws.WeatherStationId; vm.Farms = this.GetFarmListBy(ws); vm.FarmsNotRelated = this.GetFarmNotRelatedListBy(ws); vm.DateOfInstallation = ws.DateOfInstallation; vm.DateOfService = ws.DateOfService; vm.Enabled = ws.Enabled; vm.GiveET = ws.GiveET; vm.Model = ws.Model; vm.Name = ws.Name; vm.Latitude = ws.Position.Latitude; vm.Longitude = ws.Position.Longitude; vm.StationType = ws.StationType; vm.UpdateTime = ws.UpdateTime; vm.WeatherDataType = ws.WeatherDataType; vm.WebAddress = ws.WebAddress; vm.WirelessTransmission = ws.WirelessTransmission; return(View("~/Views/Weather/WeatherStations/Details.cshtml", vm)); }
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()); }