public ActionResult AddEditStationLink(AddEditStationLinkViewModel viewModel) { if (!(viewModel.StationId.HasValue)) { var dataTable = CRCDataAccess.GetStationLinkStatus(viewModel.UserId, viewModel.StationId); if (dataTable.Rows.Count != 0) { ModelState.AddModelError("StationId", "This user is already linked to this station."); return(PartialView(viewModel)); // return Json(true); } } //if (viewModel.PrimaryUserInd) //{ // var dataTable = CRCDataAccess.GetStationLinkPrimaryUser(viewModel.StationId); // if (dataTable.Rows.Count != 0) // { // string name = ""; // foreach (System.Data.DataRow dr in dataTable.Rows) // { // name = name + dr["FirstName"].ToString() + " " + dr["MiddleName"].ToString() + " " + dr["LastName"].ToString() + " is the current primary user. Only one user may be designated the primary user for this station."; // } // ModelState.AddModelError("", name); // return PartialView(viewModel); // } //} if (ModelState.IsValid) { if (viewModel.PrimaryUserInd) { viewModel.GridWritePermissionsInd = true; } CRCDataAccess.SaveStationUser(viewModel.StationId.Value, viewModel.UserId, viewModel.PrimaryUserInd, viewModel.GridWritePermissionsInd, CRCUser.UserId); return(Json(true)); } else { return(PartialView(viewModel)); } return(PartialView(viewModel)); }
public ActionResult AddEditStationLink(long?userId, long?stationId) { //status = true; var viewModel = new AddEditStationLinkViewModel(); if (userId.HasValue) { viewModel.UserId = userId.Value; if (stationId.HasValue) { viewModel.StationId = stationId; // status = false; var drStationUser = CRCDataAccess.GetStationUser(stationId.Value, userId.Value); drStationUser.MapTo(viewModel); } } return(PartialView(viewModel)); }