public ActionResult ManageAPSectorNew( int apsectorid, int apid, int sectornumber, string sectorvalue, string serialnumber ) { APSectorViewModel model = new APSectorViewModel(); model.APSectorId = apsectorid; model.APId = apid; model.SectorNumber = sectornumber; model.SectorValue = sectorvalue; model.SerialNumber = serialnumber; if (model.APSectorId == 0) { //insert result = _APBAL.AddAPSector(model, true); model.APSectorId = Convert.ToInt32(result.Values); } else { //update result = _APBAL.UpdateAPSector(model, true); } var sa = new JsonSerializerSettings(); // return Json(new { Result = true, APID = model.APID }, JsonRequestBehavior.AllowGet); return(Json(new { Result = true, APSectorId = model.APSectorId }, sa)); }
public List <APSectorViewModel> GetAPSectorByOutdoorAPID(int?apID) { DBOperations dbOps = new DBOperations(); List <APSectorViewModel> objs = new List <APSectorViewModel>(); try { NpgsqlParameter[] aParams = new NpgsqlParameter[1]; aParams[0] = new NpgsqlParameter("_outdoorapid", NpgsqlTypes.NpgsqlDbType.Integer); aParams[0].Value = apID; dbOps.ExecuteReader(AppConstants.usp_GetAPSectorByOutdoorAPID, aParams); if (!(dbOps.DataReader == null)) { using (dbOps.DataReader) { while (dbOps.DataReader.Read()) { APSectorViewModel obj = new APSectorViewModel { APSectorId = Helper.HandleDBNull <Int32>(dbOps.DataReader[0]), APId = Helper.HandleDBNull <Int32>(dbOps.DataReader[1]), SectorNumber = Helper.HandleDBNull <Int32>(dbOps.DataReader[2]), SectorValue = Helper.HandleDBNull <String>(dbOps.DataReader[3]), SerialNumber = Helper.HandleDBNull <String>(dbOps.DataReader[4]) }; objs.Add(obj); } } } return(objs); } catch (Exception Ex) { throw Ex; } }
public Result UpdateAPSector(APSectorViewModel model, bool isOutdoor = false) { Result result = new Result(); DBOperations dbOps = new DBOperations(); try { NpgsqlParameter[] aParams; if (!isOutdoor) { aParams = new NpgsqlParameter[6]; } else { aParams = new NpgsqlParameter[8]; } aParams[0] = new NpgsqlParameter("APID", NpgsqlTypes.NpgsqlDbType.Integer); aParams[0].Value = model.APId; aParams[1] = new NpgsqlParameter("SectorNumber", NpgsqlTypes.NpgsqlDbType.Integer); aParams[1].Value = model.SectorNumber; aParams[2] = new NpgsqlParameter("SectorValue", NpgsqlTypes.NpgsqlDbType.Varchar); aParams[2].Value = model.SectorValue; aParams[3] = new NpgsqlParameter("SerialNo", NpgsqlTypes.NpgsqlDbType.Varchar); aParams[3].Value = model.SerialNumber; aParams[4] = new NpgsqlParameter(AppConstants.LastModifiedOn, NpgsqlTypes.NpgsqlDbType.Timestamp); aParams[4].Value = DateTime.Now; aParams[5] = new NpgsqlParameter(AppConstants.LastModifiedBy, NpgsqlTypes.NpgsqlDbType.Integer); aParams[5].Value = 0; aParams[6] = new NpgsqlParameter("IsActive", NpgsqlTypes.NpgsqlDbType.Boolean); aParams[6].Value = true; int i = 7; if (!isOutdoor) { //aParams[7] = new NpgsqlParameter("FloorID", NpgsqlTypes.NpgsqlDbType.Integer); //aParams[7].Value = model.FloorID; //i = 8; } aParams[i] = new NpgsqlParameter("APSectorId", NpgsqlTypes.NpgsqlDbType.Integer); aParams[i].Value = model.APSectorId; int res = 0; if (!isOutdoor) { res = dbOps.ExecuteNonQuery(AppConstants.QueryConstants.UpdateAPSector, aParams); } else { res = dbOps.ExecuteNonQuery(AppConstants.QueryConstants.UpdateAPSector, aParams); } if (res > 0) { result.Status = Status.Success; } else { result.Status = Status.Failure; } } catch (Exception Ex) { dbOps.Abort(); result.Status = Status.Failure; } return(result); }
//public Result AddAPSector(APSectorViewModel model, bool isOutdoor = false) //{ // Result result = new Result(); // DBOperations dbOps = new DBOperations(); // try // { // NpgsqlParameter[] aParams; // if (!isOutdoor) // { // aParams = new NpgsqlParameter[6]; // } // else // { // aParams = new NpgsqlParameter[5]; // } // aParams[0] = new NpgsqlParameter("APID", NpgsqlTypes.NpgsqlDbType.Integer); // aParams[0].Value = model.APId; // aParams[1] = new NpgsqlParameter("SectorNumber", NpgsqlTypes.NpgsqlDbType.Integer); // aParams[1].Value = model.SectorNumber; // aParams[2] = new NpgsqlParameter("SectorValue", NpgsqlTypes.NpgsqlDbType.Varchar); // aParams[2].Value = model.SectorValue; // aParams[3] = new NpgsqlParameter("SerialNo", NpgsqlTypes.NpgsqlDbType.Varchar); // aParams[3].Value = model.SerialNumber; // aParams[4] = new NpgsqlParameter(AppConstants.CreatedBy, NpgsqlTypes.NpgsqlDbType.Integer); // aParams[4].Value = 0; // //if (!isOutdoor) // //{ // // aParams[5] = new NpgsqlParameter("FloorID", NpgsqlTypes.NpgsqlDbType.Integer); // // aParams[5].Value = model.FloorID; // //} // int res = 0; // if (!isOutdoor) // { // res = (int)dbOps.ExecuteNonQuery(AppConstants.QueryConstants.AddAP, aParams); // } // else // { // res = dbOps.ExecuteNonQuery(AppConstants.QueryConstants.AddAPSector, aParams); // } // if (res > 0) // { // result.Status = Status.Success; // } // else // { // result.Status = Status.Failure; // } // } // catch (Exception Ex) // { // dbOps.Abort(); // result.Status = Status.Failure; // } // return result; //} public Result AddAPSector(APSectorViewModel model, bool isOutdoor = false) { Result result = new Result(); DBOperations dbOps = new DBOperations(); try { NpgsqlParameter[] aParams; if (!isOutdoor) { aParams = new NpgsqlParameter[6]; } else { aParams = new NpgsqlParameter[5]; } aParams[0] = new NpgsqlParameter("APID", NpgsqlTypes.NpgsqlDbType.Integer); aParams[0].Value = model.APId; aParams[1] = new NpgsqlParameter("SectorNumber", NpgsqlTypes.NpgsqlDbType.Integer); aParams[1].Value = model.SectorNumber; aParams[2] = new NpgsqlParameter("SectorValue", NpgsqlTypes.NpgsqlDbType.Varchar); aParams[2].Value = model.SectorValue; aParams[3] = new NpgsqlParameter("SerialNo", NpgsqlTypes.NpgsqlDbType.Varchar); aParams[3].Value = model.SerialNumber; aParams[4] = new NpgsqlParameter(AppConstants.CreatedBy, NpgsqlTypes.NpgsqlDbType.Integer); aParams[4].Value = 0; //if (!isOutdoor) //{ // aParams[5] = new NpgsqlParameter("FloorID", NpgsqlTypes.NpgsqlDbType.Integer); // aParams[5].Value = model.FloorID; //} int res = 0; if (!isOutdoor) { res = (int)dbOps.ExecuteNonQuery(AppConstants.QueryConstants.AddAPSector, aParams); } else { res = dbOps.ExecuteNonQuery(AppConstants.QueryConstants.AddAPSector, aParams); } if (res > 0) { result.Status = Status.Success; } else { result.Status = Status.Failure; } } catch (Exception Ex) { dbOps.Abort(); result.Status = Status.Failure; } return(result); }