public async Task <ResultObject> GetDeviceDetails(int userId, int deviceId) { try { using (var sqlcon = new NpgsqlConnection("Server = localhost; Username = postgres; Password = sa; Database = elocare_new;")) { sqlcon.Open(); using (NpgsqlDataAdapter dap = new NpgsqlDataAdapter("fn_ro_registeredroomitems", sqlcon)) { DataSet dsRegisteredroomitems = new DataSet(); dap.SelectCommand.CommandType = CommandType.StoredProcedure; dap.SelectCommand.Parameters.Add(new NpgsqlParameter("@rid", deviceId)); dap.Fill(dsRegisteredroomitems); List <CustomItemVM> CustomItem = new List <CustomItemVM>(); if (dsRegisteredroomitems.Tables.Count > 0) { _result[ResultKey.Success] = true; _result[ResultKey.Message] = Message.Success; foreach (DataRow x in dsRegisteredroomitems.Tables[0].Rows) { CustomItemVM objCP = new CustomItemVM(); objCP.ItemId = Convert.ToInt32(x["riid"]); objCP.ItemName = Convert.ToString(x["riname"]); objCP.IsActive = Convert.ToByte(x["activeObj"]); CustomItem.Add(objCP); } _result[ResultKey.CustomItemList] = CustomItem; } else { _result[ResultKey.Success] = true; _result[ResultKey.Message] = Message.Success; _result[ResultKey.CustomItemList] = CustomItem; } } using (NpgsqlDataAdapter dap = new NpgsqlDataAdapter("fn_GetDeviceInformation", sqlcon)) { DataSet dsDeviceInformation = new DataSet(); dap.SelectCommand.CommandType = CommandType.StoredProcedure; dap.SelectCommand.Parameters.Add(new NpgsqlParameter("@uid", userId)); dap.SelectCommand.Parameters.Add(new NpgsqlParameter("@did", deviceId)); dap.Fill(dsDeviceInformation); List <DeviceInformationVM> DeviceInformationList = new List <DeviceInformationVM>(); if (dsDeviceInformation.Tables.Count > 0) { _result[ResultKey.Success] = true; _result[ResultKey.Message] = Message.Success; foreach (DataRow x in dsDeviceInformation.Tables[0].Rows) { DeviceInformationVM objCP = new DeviceInformationVM(); objCP.UserId = Convert.ToInt32(x["UserId"]); objCP.ItemId = Convert.ToInt32(x["ItemId"]); objCP.Item = Convert.ToString(x["Item"]); objCP.Axis = Convert.ToString(x["Axis"]); objCP.IsRegistered = Convert.ToByte(x["IsRegistered"]); objCP.Updated_Date = Convert.ToDateTime(x["Updated_Date"]); objCP.LastUpdatedUser = Convert.ToString(x["LastUpdatedUser"]); objCP.IsActive = Convert.ToByte(x["IsActive"]); DeviceInformationList.Add(objCP); } _result[ResultKey.RegistrationDetails] = DeviceInformationList; using (NpgsqlDataAdapter sda = new NpgsqlDataAdapter("fn_GetDeviceLastUpdatedDetails", sqlcon)) { DataSet dsDeviceDetails = new DataSet(); sda.SelectCommand.CommandType = CommandType.StoredProcedure; sda.SelectCommand.Parameters.Add(new NpgsqlParameter("@did", deviceId)); sda.Fill(dsDeviceDetails); if (dsDeviceDetails.Tables.Count > 0) { foreach (DataRow dr in dsDeviceDetails.Tables[0].Rows) { List <DeviceLastUpdatedDetailsVM> DeviceLastUpdatedDetails = new List <DeviceLastUpdatedDetailsVM>(); foreach (DataRow x in dsDeviceDetails.Tables[0].Rows) { DeviceLastUpdatedDetailsVM objCP = new DeviceLastUpdatedDetailsVM(); objCP.LastUpdatedUser = Convert.ToString(dr["LastUpdatedUser"]); objCP.Updated_Date = Convert.ToDateTime(dr["Updated_Date"]).ToString("dd MMM yyyy"); objCP.DeviceId = Convert.ToInt32(dr["DeviceId"]); objCP.DeviceName = Convert.ToString(dr["DeviceName"]); DeviceLastUpdatedDetails.Add(objCP); } _result[ResultKey.LastUpdatedInfo] = DeviceLastUpdatedDetails; } } } using (NpgsqlDataAdapter sda = new NpgsqlDataAdapter("fn_defaultdevicesettings", sqlcon)) { DataSet dsDeviceSetting = new DataSet(); sda.SelectCommand.CommandType = CommandType.StoredProcedure; sda.SelectCommand.Parameters.AddWithValue("@rid", deviceId); sda.Fill(dsDeviceSetting); if (dsDeviceSetting.Tables.Count > 0) { _result[ResultKey.Success] = true; _result[ResultKey.Message] = Message.Success; List <DeviceSettingVM> DeviceSettings = new List <DeviceSettingVM>(); foreach (DataRow x in dsDeviceSetting.Tables[0].Rows) { DeviceSettingVM objCP = new DeviceSettingVM(); objCP.DeviceId = Convert.ToInt32(x["masterdeviceid"]); objCP.DeviceName = Convert.ToString(x["name"]); objCP.IsActive = Convert.ToByte(x["isactive"]); objCP.RadorCoverageArea = x["rcavalue"] != DBNull.Value ? Convert.ToInt32(x["rcavalue"]) : 0; objCP.RadorCoverageStatus = x["rcastate"] != DBNull.Value ? Convert.ToByte(x["rcastate"]) : Convert.ToByte(0); objCP.RadorSensitivityLevel = x["rslvalue"] != DBNull.Value ? Convert.ToInt32(x["rslvalue"]) : 0; objCP.RadorSensitivityStatus = x["rslstate"] != DBNull.Value ? Convert.ToByte(x["rslstate"]) : Convert.ToByte(0); objCP.BeepStatus = x["beepstate"] != DBNull.Value ? Convert.ToByte(x["beepstate"]) : Convert.ToByte(0); objCP.RadorLEDIndicatorStatus = x["ledstate"] != DBNull.Value ? Convert.ToByte(x["ledstate"]) : Convert.ToByte(0); objCP.IPAddress = Convert.ToString(x["ipaddress"]); // objCP.SoftwareVersion = Convert.ToString(x["SoftwareVersion"]); objCP.SoftwareVersion = "1.1.10"; DeviceSettings.Add(objCP); } _result[ResultKey.DeviceSettingDetails] = DeviceSettings; } } } else { _result[ResultKey.Success] = true; _result[ResultKey.Message] = Message.Success; _result[ResultKey.DeviceSettingDetails] = DeviceInformationList; } } sqlcon.Close(); } return(_result); } catch (Exception ex) { _result[ResultKey.Success] = false; _result[ResultKey.Message] = ex.Message; throw ex; } }
public async Task <ResultObject> GetCustomItemlist(int userId, int roomid) { try { using (var sqlcon = new NpgsqlConnection("Server = localhost; Username = postgres; Password = sa; Database = elocare;")) { sqlcon.Open(); using (NpgsqlDataAdapter dap = new NpgsqlDataAdapter("fn_ro_registeredroomitems", sqlcon)) { DataSet dsRegisteredroomitems = new DataSet(); dap.SelectCommand.CommandType = CommandType.StoredProcedure; dap.SelectCommand.Parameters.Add(new NpgsqlParameter("@rid", roomid)); dap.Fill(dsRegisteredroomitems); List <CustomItemVM> CustomItem = new List <CustomItemVM>(); if (dsRegisteredroomitems.Tables.Count > 0) { _result[ResultKey.Success] = true; _result[ResultKey.Message] = Message.Success; foreach (DataRow x in dsRegisteredroomitems.Tables[0].Rows) { CustomItemVM objCP = new CustomItemVM(); objCP.ItemId = Convert.ToInt32(x["riid"]); objCP.ItemName = Convert.ToString(x["riname"]); objCP.IsActive = Convert.ToByte(x["activeObj"]); CustomItem.Add(objCP); } _result[ResultKey.CustomItemList] = CustomItem; } else { _result[ResultKey.Success] = true; _result[ResultKey.Message] = Message.Success; _result[ResultKey.CustomItemList] = CustomItem; } } sqlcon.Close(); } //using (var sqlConnection = new SqlConnection(ConnectionString)) //{ // await sqlConnection.OpenAsync(); // using (SqlDataAdapter dap = new SqlDataAdapter("sp_GetCustomItemList", sqlConnection)) // { // DataSet dsCustomItem = new DataSet(); // dap.SelectCommand.CommandType = CommandType.StoredProcedure; // dap.SelectCommand.Parameters.AddWithValue("@UserId", userId); // dap.SelectCommand.Parameters.AddWithValue("@deviceId", deviceId); // dap.Fill(dsCustomItem); // List<CustomItemVM> CustomItem = new List<CustomItemVM>(); // if (dsCustomItem.Tables[0].Rows.Count > 0) // { // _result[ResultKey.Success] = true; // _result[ResultKey.Message] = Message.Success; // foreach (DataRow x in dsCustomItem.Tables[0].Rows) // { // CustomItemVM objCP = new CustomItemVM(); // objCP.ItemId = Convert.ToInt32(x["ItemId"]); // objCP.ItemName = Convert.ToString(x["ItemName"]); // objCP.IsActive = Convert.ToByte(x["IsActive"]); // //objCP.iscustom = Convert.ToByte(x["iscustom"]); // //objCP.IsRegistered = Convert.ToByte(x["RegStatus"]); // //objCP.RegistrationId = x["RegistrationId"] != DBNull.Value ? Convert.ToInt32(x["RegistrationId"]) : (int?)null; // CustomItem.Add(objCP); // } // _result[ResultKey.CustomItemList] = CustomItem; // } // else // { // _result[ResultKey.Success] = true; // _result[ResultKey.Message] = Message.Success; // _result[ResultKey.CustomItemList] = CustomItem; // } // } // sqlConnection.Close(); //} return(_result); } catch (Exception ex) { _result[ResultKey.Success] = false; _result[ResultKey.Message] = ex.Message; throw ex; } }