public ActionResult DeviceSettings(string DeviceId) { DeviceSettingsViewModel model = new DeviceSettingsViewModel(); model.DeviceList = new List<SelectListItem>(); // Get list of devices DataTable dt = Data.GetData(DataBase.Api, CommandType.StoredProcedure, "Api_GetDeviceList"); if (dt != null || dt.Rows.Count > 0) { model.DeviceList = dt.AsEnumerable().Select(m => new SelectListItem() { Value = Convert.ToString(m["DeviceId"]), Text = Convert.ToString(m["DeviceId"]) }).ToList(); } //ViewData["DeviceId"] = model.DeviceList; if (string.IsNullOrWhiteSpace(DeviceId) && model.DeviceList.Count > 0) { DeviceId = model.DeviceList.First().Value; } // Get device configuration dt = null; dt = new DataTable(); List<SqlParameter> parameters = new List<SqlParameter>(); parameters.Add(new SqlParameter("DeviceId", DeviceId)); dt = Data.GetData(DataBase.Api, CommandType.StoredProcedure, "Master_GetDeviceSettings", parameters.ToArray()); if (dt != null || dt.Rows.Count > 0) { var tModel = dt.AsEnumerable().Select(m => new DeviceSettingsViewModel() { DeviceId = Convert.ToString(m["IMEINo"]), Odometer = Convert.ToInt32(m["Odometer"]), }).FirstOrDefault(); if (tModel != null) { model.DeviceId = tModel.DeviceId; model.Odometer = tModel.Odometer; } } model = model ?? new DeviceSettingsViewModel(); return View(model); }
public ActionResult DeviceSettings(DeviceSettingsViewModel model) { List<SqlParameter> parameters = new List<SqlParameter>(); parameters.Add(new SqlParameter("DeviceId", model.DeviceId)); parameters.Add(new SqlParameter("Odometer", model.Odometer)); try { Data.StoreData_ExecuteNonQuery(DataBase.Api, CommandType.StoredProcedure, "Master_SaveDeviceSettings", parameters.ToArray()); TempData["Result"] = true; } catch (Exception ex) { TempData["Result"] = false; } //return DeviceSettings(model.DeviceId); return RedirectToAction("DeviceSettings", new { DeviceId = model.DeviceId }); }