コード例 #1
0
ファイル: Notifications.cs プロジェクト: m3hrad/CityCrowd
        public void notificationAdd(int UserId, int NotificationType, Int64 itemId)
        {
            SqlConnection sqlConn        = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
            SqlCommand    sqlCmd         = new SqlCommand("sp_notificationAdd", sqlConn);
            Int64         notificationId = 0;

            //try
            //{
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value           = UserId;
            sqlCmd.Parameters.Add("@NotificationType", SqlDbType.Int).Value = NotificationType;
            sqlCmd.Parameters.Add("@ItemId", SqlDbType.BigInt).Value        = itemId;

            sqlConn.Open();
            notificationId = Convert.ToInt64(sqlCmd.ExecuteScalar());
            //}
            //catch (Exception ex)
            //{

            //}
            //finally
            //{
            sqlConn.Close();
            sqlCmd.Dispose();
            sqlConn.Dispose();
            //}

            Classes.Signal s = new Classes.Signal();
            s.usernotificationsNumber(UserId);

            var context = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();

            // text, notificationType, notificationid,notificationLink
            context.Clients.Group(UserId.ToString()).receiveNotification(notificationText(NotificationType, itemId),
                                                                         NotificationType,
                                                                         notificationId,
                                                                         notificationLink(NotificationType, itemId));

            //context.Clients.Group(UserId.ToString()).setDone("hi!");


            //context.Clients.All.setDone("hi!");
        }
コード例 #2
0
ファイル: Messages.cs プロジェクト: m3hrad/CityCrowd
        public int addMessage(int userId, int receiverId, string message)
        {
            int status = 0;

            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
            SqlCommand    sqlCmd  = new SqlCommand("sp_messagesSendAdd", sqlConn);

            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.Parameters.Add("@SenderId", SqlDbType.Int).Value     = userId;
            sqlCmd.Parameters.Add("@ReceiverId", SqlDbType.Int).Value   = receiverId;
            sqlCmd.Parameters.Add("@Message", SqlDbType.NVarChar).Value = message;
            if (message.Length < 100)
            {
                sqlCmd.Parameters.Add("@Brief", SqlDbType.NVarChar).Value = message;
            }
            else
            {
                sqlCmd.Parameters.Add("@Brief", SqlDbType.NVarChar).Value = message.Substring(0, 100);
            }

            //try
            //{
            sqlConn.Open();
            sqlCmd.ExecuteNonQuery();
            status = 1;
            //}
            //catch (Exception ex)
            //{

            //}
            //finally
            //{
            sqlConn.Close();
            sqlConn.Dispose();
            //}

            Classes.Signal s = new Classes.Signal();
            s.usernotificationsNumber(receiverId);

            return(status);
        }
コード例 #3
0
ファイル: Requests.cs プロジェクト: m3hrad/CityCrowd
        public int requestSend(int userId, Int64 eventId, string message)
        {
            int totalStatus = 0;

            Classes.Events ev = new Classes.Events();
            if (ev.isUserOwner(userId, eventId))
            {
                totalStatus = -1;
            }
            else if (ev.isUserParticipant(userId, eventId))
            {
                //cancel participation
                SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                SqlCommand    sqlCmd  = new SqlCommand("sp_eventCancelParticipation", sqlConn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@EventId", SqlDbType.BigInt).Value = eventId;
                sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value     = userId;

                try
                {
                    sqlConn.Open();
                    sqlCmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    sqlConn.Close();
                    sqlCmd.Dispose();
                    sqlConn.Dispose();
                }

                Classes.Events e       = new Classes.Events();
                int            ownerId = e.getOwnerIdByEventId(eventId);

                Classes.Notifications n = new Classes.Notifications();
                n.notificationAdd(ownerId, 7, Convert.ToInt64(userId));

                totalStatus = 1;
            }
            else
            {
                int status = checkRequest(userId, eventId);

                if (status == 0)
                {
                    //send request
                    SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                    SqlCommand    sqlCmd  = new SqlCommand("sp_eventRequestAdd", sqlConn);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.Add("@EventId", SqlDbType.BigInt).Value   = eventId;
                    sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value       = userId;
                    sqlCmd.Parameters.Add("@Message", SqlDbType.NVarChar).Value = message;

                    try
                    {
                        sqlConn.Open();
                        sqlCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        sqlConn.Close();
                        sqlCmd.Dispose();
                        sqlConn.Dispose();
                    }

                    Classes.Events e1       = new Classes.Events();
                    int            personId = e1.getOwnerIdByEventId(eventId);
                    Classes.Signal s        = new Classes.Signal();
                    s.usernotificationsNumber(personId);

                    totalStatus = 3;
                }
                else if (status == 1)
                {
                    //cancel request
                    SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                    SqlCommand    sqlCmd  = new SqlCommand("sp_eventRequestDelete", sqlConn);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.Add("@EventId", SqlDbType.BigInt).Value = eventId;
                    sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value     = userId;

                    try
                    {
                        sqlConn.Open();
                        sqlCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        sqlConn.Close();
                        sqlCmd.Dispose();
                        sqlConn.Dispose();
                    }

                    Classes.Events e1       = new Classes.Events();
                    int            personId = e1.getOwnerIdByEventId(eventId);
                    Classes.Signal s        = new Classes.Signal();
                    s.usernotificationsNumber(personId);

                    totalStatus = 2;
                }
            }

            return(totalStatus);
        }
コード例 #4
0
ファイル: Requests.cs プロジェクト: m3hrad/CityCrowd
        public int requestSend(int userId, Int64 eventId, string message)
        {
            int totalStatus = 0;

            Classes.Events ev = new Classes.Events();
            if (ev.isUserOwner(userId, eventId))
            {
                totalStatus = -1;
            }
            else if (ev.isUserParticipant(userId, eventId))
            {
                //cancel participation
                SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                SqlCommand sqlCmd = new SqlCommand("sp_eventCancelParticipation", sqlConn);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@EventId", SqlDbType.BigInt).Value = eventId;
                sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = userId;

                try
                {
                    sqlConn.Open();
                    sqlCmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {

                }
                finally
                {
                    sqlConn.Close();
                    sqlCmd.Dispose();
                    sqlConn.Dispose();
                }

                Classes.Events e = new Classes.Events();
                int ownerId = e.getOwnerIdByEventId(eventId);

                Classes.Notifications n = new Classes.Notifications();
                n.notificationAdd(ownerId, 7, Convert.ToInt64(userId));

                totalStatus = 1;
            }
            else
            {
                int status = checkRequest(userId, eventId);

                if (status == 0)
                {
                    //send request
                    SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                    SqlCommand sqlCmd = new SqlCommand("sp_eventRequestAdd", sqlConn);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.Add("@EventId", SqlDbType.BigInt).Value = eventId;
                    sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = userId;
                    sqlCmd.Parameters.Add("@Message", SqlDbType.NVarChar).Value = message;

                    try
                    {
                        sqlConn.Open();
                        sqlCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {

                    }
                    finally
                    {
                        sqlConn.Close();
                        sqlCmd.Dispose();
                        sqlConn.Dispose();
                    }

                    Classes.Events e1 = new Classes.Events();
                    int personId = e1.getOwnerIdByEventId(eventId);
                    Classes.Signal s = new Classes.Signal();
                    s.usernotificationsNumber(personId);

                    totalStatus = 3;
                }
                else if (status == 1)
                {
                    //cancel request
                    SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
                    SqlCommand sqlCmd = new SqlCommand("sp_eventRequestDelete", sqlConn);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.Add("@EventId", SqlDbType.BigInt).Value = eventId;
                    sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = userId;

                    try
                    {
                        sqlConn.Open();
                        sqlCmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {

                    }
                    finally
                    {
                        sqlConn.Close();
                        sqlCmd.Dispose();
                        sqlConn.Dispose();
                    }

                    Classes.Events e1 = new Classes.Events();
                    int personId = e1.getOwnerIdByEventId(eventId);
                    Classes.Signal s = new Classes.Signal();
                    s.usernotificationsNumber(personId);

                    totalStatus = 2;
                }
            }

            return totalStatus;
        }
コード例 #5
0
ファイル: Messages.cs プロジェクト: m3hrad/CityCrowd
        public int addMessage(int userId, int receiverId, string message)
        {
            int status = 0;

            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
            SqlCommand sqlCmd = new SqlCommand("sp_messagesSendAdd", sqlConn);
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.Parameters.Add("@SenderId", SqlDbType.Int).Value = userId;
            sqlCmd.Parameters.Add("@ReceiverId", SqlDbType.Int).Value = receiverId;
            sqlCmd.Parameters.Add("@Message", SqlDbType.NVarChar).Value = message;
            if (message.Length < 100)
            {
                sqlCmd.Parameters.Add("@Brief", SqlDbType.NVarChar).Value = message;
            }
            else
            {
                sqlCmd.Parameters.Add("@Brief", SqlDbType.NVarChar).Value = message.Substring(0, 100);
            }

            //try
            //{
                sqlConn.Open();
                sqlCmd.ExecuteNonQuery();
                status = 1;
            //}
            //catch (Exception ex)
            //{

            //}
            //finally
            //{
                sqlConn.Close();
                sqlConn.Dispose();
            //}

            Classes.Signal s = new Classes.Signal();
            s.usernotificationsNumber(receiverId);

            return status;
        }
コード例 #6
0
ファイル: Notifications.cs プロジェクト: m3hrad/CityCrowd
        public void notificationAdd(int UserId, int NotificationType, Int64 itemId)
        {
            SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString"].ConnectionString);
            SqlCommand sqlCmd = new SqlCommand("sp_notificationAdd", sqlConn);
            Int64 notificationId = 0;
            //try
            //{
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@UserId", SqlDbType.Int).Value = UserId;
                sqlCmd.Parameters.Add("@NotificationType", SqlDbType.Int).Value = NotificationType;
                sqlCmd.Parameters.Add("@ItemId", SqlDbType.BigInt).Value = itemId;

                sqlConn.Open();
                notificationId = Convert.ToInt64(sqlCmd.ExecuteScalar());
            //}
            //catch (Exception ex)
            //{

            //}
            //finally
            //{
                sqlConn.Close();
                sqlCmd.Dispose();
                sqlConn.Dispose();
            //}

            Classes.Signal s = new Classes.Signal();
            s.usernotificationsNumber(UserId);

            var context = GlobalHost.ConnectionManager.GetHubContext<ChatHub>();
            // text, notificationType, notificationid,notificationLink
            context.Clients.Group(UserId.ToString()).receiveNotification(notificationText(NotificationType, itemId),
                NotificationType,
                notificationId,
                notificationLink(NotificationType, itemId));
            
            //context.Clients.Group(UserId.ToString()).setDone("hi!");


            //context.Clients.All.setDone("hi!");
        }