public List<HickGroups> GetGroups(long currentuserid)
        {
            try
            {
                List<HickGroups> objgroupColl = new List<HickGroups>();
                string constr = ConfigurationManager.ConnectionStrings["HickConnectionString"].ConnectionString.ToString();
                StringBuilder sb = new StringBuilder();


                //sb.Append(@"select * from hick_groups where id in (select Distinct id  from hick_groups where created_by={0}) ");
                //sb.Append(@"OR id in (select Distinct group_id  from hick_group_users where user_id={0}) ; ");
                //string query = sb.ToString();
                //query = string.Format(query, currentuserid);
                using (SqlConnection conn = new SqlConnection(constr))
                {
                    conn.ConnectionString = constr;
                    conn.Open();

                    using (SqlCommand command = new SqlCommand("sp_hick_FetchGroupsForCurUsr", conn))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@UsrId", currentuserid);

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    HickGroups objgrp = new HickGroups();
                                    objgrp.Id = Convert.ToInt32(reader["id"]);
                                    objgroupColl.Add(objgrp);
                                }

                            }
                        }
                    }
                    if (objgroupColl.Count > 0)
                    {
                        for (int i = 0; i < objgroupColl.Count; i++)
                        {
                            long groupid = objgroupColl[i].Id;
                            //sb = new StringBuilder();
                            //sb.AppendLine("SELECT * FROM hick_group_users AS GU");
                            //sb.AppendLine("INNER JOIN Hick_Users AS U ON GU.user_id=U.ID");
                            //sb.AppendLine("WHERE GU.group_id=" + objgroupColl[i].Id + "");
                            using (SqlCommand command = new SqlCommand("sp_hick_FetchUsersOfGroup", conn))
                            {
                                command.CommandType = CommandType.StoredProcedure;
                                command.Parameters.AddWithValue("@GroupId", objgroupColl[i].Id);

                                using (SqlDataReader reader = command.ExecuteReader())
                                {
                                    if (reader.HasRows)
                                    {
                                        objgroupColl[i].GroupUsersColl = new List<HickGroupUsers>();
                                        while (reader.Read())
                                        {
                                            HickGroupUsers objgrpuser = new HickGroupUsers();
                                            objgrpuser.GroupId = Convert.ToInt32(reader["group_id"]);
                                            objgrpuser.UserId = Convert.ToInt32(reader["user_id"]);

                                            objgrpuser.FullName = Convert.ToString(ecd.DecryptData((reader["Firstname"]).ToString(), ecd.GetEncryptType())) + " " + Convert.ToString(ecd.DecryptData((reader["Lastname"]).ToString(), ecd.GetEncryptType()));

                                            if (objgrpuser.UserId == currentuserid && reader["message_status"] != DBNull.Value && Convert.ToInt32(reader["message_status"]) == (int)ReadStatus.UnRead)
                                            {
                                                objgroupColl[i].IsUnreadMessage = true;
                                            }
                                            objgroupColl[i].GroupUsersColl.Add(objgrpuser);
                                        }

                                    }
                                }
                            }
                            sb = null;
                            //sb = new StringBuilder();
                            //sb.AppendLine("select * from Hick_user_Conversation UC");
                            //sb.AppendLine("INNER JOIN Hick_VideoConversation_Log CL on UC.ID=CL.ConversationId");
                            //sb.AppendLine("where UC.group_id=" + groupid + " and UC.ConversationDate=CONVERT(date, @date)");
                            //sb.AppendLine("and CL.Status=" + (int)ReadStatus.CallInitiated + "");
                            using (SqlCommand command = new SqlCommand("sp_hick_FetchVideoCallStatus", conn))
                            {
                                command.CommandType = CommandType.StoredProcedure;

                                command.Parameters.AddWithValue("@groupId", groupid);
                                command.Parameters.AddWithValue("@status", (int)ReadStatus.CallInitiated);
                                command.Parameters.AddWithValue("@date", DateTime.UtcNow);
                                using (SqlDataReader reader = command.ExecuteReader())
                                {
                                    if (reader.HasRows)
                                    {
                                        while (reader.Read())
                                        {
                                            if (currentuserid != Convert.ToInt32(reader["PeerId"]))
                                            {
                                                objgroupColl[i].IncomingCall = true;
                                            }

                                        }
                                    }
                                }
                            }
                        }
                    }
                }


                return objgroupColl;
            }
            catch (Exception)
            {

                throw;
            }
        }
        private HickGroups GetGroupByUniqueId(string uniqueId)
        {
            HickGroups group = null;
            string constr = ConfigurationManager.ConnectionStrings["HickConnectionString"].ConnectionString.ToString();
            using (SqlConnection conn = new SqlConnection(constr))
            {

                conn.Open();
                //string query = @"SELECT  * FROM hick_groups WHERE group_unique_key='{0}'";
                //query = string.Format(query, uniqueId);

                using (SqlCommand command = new SqlCommand("sp_hick_GetGroupByUniqueId", conn))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@UniqueId", uniqueId);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                group = new HickGroups();
                                group.Id = Convert.ToInt32(reader["id"]);
                                return group;
                            }
                        }
                    }
                }
            }
            return group;

        }