Prasad Bhagat

Prasad Bhagat

  • 1.6k
  • 516
  • 206.3k

what is the return type for this method ?

Sep 16 2015 2:33 AM
Dear all ,
 
i have a two web methods and one is getting list of values and other one is deleting  a record and fetching list of data from first method so please suggest me what is the return type here please ..
 
 
in my proc...
CREATE  PROCEDURE [dbo].[DeleteFriend]
@FriendNumber VARCHAR(Max),
@DeviceId VARCHAR(Max)
AS
BEGIN
BEGIN TRY
DELETE FROM Friends
WHERE DeviceId = @DeviceId AND FriendNumber = @FriendNumber
DECLARE @Number VARCHAR(Max)
DECLARE @FriendDeviceId VARCHAR(Max)
SELECT @FriendDeviceId = DeviceId
FROM dbo.DeviceMaster
WHERE Number = @FriendNumber
SELECT @Number = Number FROM dbo.DeviceMaster WHERE DeviceId = @DeviceId
DELETE FROM Friends
WHERE DeviceId = @FriendDeviceId AND FriendNumber = @Number
EXEC GetFriendsList @DeviceId
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS STATUSMSG, -1 AS STATUSIND
END CATCH
END
 
 
COMING TO MYSERVICE METHODS...
 
public List<Friends> GetFriendsList(string DeviceId)
{
List<Friends> listFriend = new List<Friends>();
SqlCommand cmd = null;
SqlDataReader reader = null;
Friends friend = new Friends();
try
{
cmd = new SqlCommand("GetFriendsList", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@DeviceId", DeviceId);
conn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
friend = new Friends();
friend.friendNumber = reader["FriendNumber"].ToString();
friend.name = reader["Name"].ToString();
friend.deviceId = reader["DeviceId"].ToString();
friend.isCheckedIn = reader["IsCheckedIn"].ToString();
friend.status = reader["STATUSMSG"].ToString();
friend.statuind = Convert.ToInt32(reader["STATUSIND"].ToString());
listFriend.Add(friend);
}
if (listFriend.Count == 0)
{
friend.status = "Record Not Found";
friend.statuind = -1;
listFriend.Add(friend);
}
conn.Close();
}
catch (Exception ex)
{
friend.status = ex.Message.ToString();
friend.statuind = -1;
}
return listFriend.ToList();
}
 
 
AND SECOND METHOD IS...
 
public void DeleteFriend(string DeviceId, string FriendNumber)
{
ResultSet resultSet = new ResultSet();
SqlCommand cmd = null;
SqlDataAdapter da = null;
DataSet ds = new DataSet();
try
{
cmd = new SqlCommand("DeleteFriend", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@DeviceId", DeviceId);
cmd.Parameters.AddWithValue("@FriendNumber", FriendNumber);
conn.Open();
da = new SqlDataAdapter(cmd);
da.Fill(ds);
cmd.ExecuteNonQuery();
conn.Close();
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
resultSet.STATUSMSG = ds.Tables[0].Rows[0]["STATUSMSG"].ToString();
resultSet.STATUSIND = Convert.ToInt32(ds.Tables[0].Rows[0]["STATUSIND"].ToString());
}
else
{
GetFriendsList(DeviceId);
}
}
else
{
resultSet.STATUSMSG = "Error";
resultSet.STATUSIND = -1;
}
}
catch (Exception ex)
{
resultSet.STATUSMSG = ex.Message.ToString();
resultSet.STATUSIND = -1;
}
finally
{
ds = null;
da = null;
cmd = null;
}
}
 
PLEASE HELP AM TOTALLY CONFUSED HOW CAN I RETURN IF DELETED I NEED TO DISPLY LIST IF NOT DELETED NEED TO DISPLY ERROR MESSAGE PLEASE HELP ME... 
 
 

Answers (3)