Example #1
0
        /// <summary>
        /// Add new reply (conversation) to database.
        /// </summary>
        /// <param name="senderId">sender's id.</param>
        /// <param name="receiverId">receiver's id.</param>
        /// <param name="text">text of reply.</param>
        /// <param name="time">time.</param>
        /// <returns>true if operations success; otherwise, false.</returns>
        public static bool AddNewReply(int senderId, int receiverId, string text, DateTime time)
        {
            using (var DBcontext = new LinqToSqlDataContext())
            {
                // get conversation id
                var data = from conversation in DBcontext.Conversations
                           where (conversation.user_one.Equals(senderId) &
                                  conversation.user_two.Equals(receiverId)) |
                           (conversation.user_one.Equals(receiverId) &
                            conversation.user_two.Equals(senderId))
                           select conversation.conversation_id;

                int conversationId;

                // conversation exist
                if (data.Any())
                {
                    conversationId = data.First();
                }
                // conversation dont exist
                else
                {
                    // new conversation
                    Conversation conv = new Conversation
                    {
                        user_one = senderId,
                        user_two = receiverId
                    };
                    DBcontext.Conversations.InsertOnSubmit(conv);

                    try
                    {
                        DBcontext.SubmitChanges();
                        conversationId = conv.conversation_id;
                    }
                    catch (Exception e)
                    {
                        log.Error(e);
                        return(false);
                    }
                }

                // new reply
                ConversationReply reply = new ConversationReply
                {
                    reply           = text,
                    conversation_id = conversationId,
                    user_id         = senderId,
                    time            = time
                };
                DBcontext.Conversation_replies.InsertOnSubmit(reply);

                try
                {
                    DBcontext.SubmitChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    log.Error(e);
                    return(false);
                }
            }
        }
		private void detach_Conversation_replies(ConversationReply entity)
		{
			this.SendPropertyChanging();
			entity.Conversation = null;
		}
Example #3
0
        /// <summary>
        /// Add new reply (conversation) to database.
        /// </summary>
        /// <param name="senderId">sender's id.</param>
        /// <param name="receiverId">receiver's id.</param>
        /// <param name="text">text of reply.</param>
        /// <param name="time">time.</param>
        /// <returns>true if operations success; otherwise, false.</returns>
        public static bool AddNewReply(int senderId, int receiverId, string text, DateTime time)
        {
            using (var DBcontext = new LinqToSqlDataContext())
            {
                // get conversation id
                var data = from conversation in DBcontext.Conversations
                           where (conversation.user_one.Equals(senderId) &
                           conversation.user_two.Equals(receiverId)) |
                           (conversation.user_one.Equals(receiverId) &
                           conversation.user_two.Equals(senderId))
                           select conversation.conversation_id;

                int conversationId;

                // conversation exist
                if (data.Any())
                {
                    conversationId = data.First();
                }
                // conversation dont exist
                else
                {
                    // new conversation
                    Conversation conv = new Conversation
                    {
                        user_one = senderId,
                        user_two = receiverId
                    };
                    DBcontext.Conversations.InsertOnSubmit(conv);

                    try
                    {
                        DBcontext.SubmitChanges();
                        conversationId = conv.conversation_id;
                    }
                    catch (Exception e)
                    {
                        log.Error(e);
                        return false;
                    }
                }

                // new reply
                ConversationReply reply = new ConversationReply
                {
                    reply = text,
                    conversation_id = conversationId,
                    user_id = senderId,
                    time = time
                };
                DBcontext.Conversation_replies.InsertOnSubmit(reply);

                try
                {
                    DBcontext.SubmitChanges();
                    return true;
                }
                catch (Exception e)
                {
                    log.Error(e);
                    return false;
                }
            }
        }
 partial void UpdateConversation_reply(ConversationReply instance);
 partial void DeleteConversation_reply(ConversationReply instance);
		private void attach_Conversation_replies(ConversationReply entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}
 partial void InsertConversation_reply(ConversationReply instance);
Example #8
0
 private void detach_Conversation_replies(ConversationReply entity)
 {
     this.SendPropertyChanging();
     entity.Conversation = null;
 }
Example #9
0
 partial void DeleteConversation_reply(ConversationReply instance);
Example #10
0
 partial void UpdateConversation_reply(ConversationReply instance);
Example #11
0
 partial void InsertConversation_reply(ConversationReply instance);
Example #12
0
 private void attach_Conversation_replies(ConversationReply entity)
 {
     this.SendPropertyChanging();
     entity.User = this;
 }