Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 2
0
 partial void DeleteConversation(Conversation instance);
Ejemplo n.º 3
0
 partial void UpdateConversation(Conversation instance);
Ejemplo n.º 4
0
		private void detach_Conversations1(Conversation entity)
		{
			this.SendPropertyChanging();
			entity.User1 = null;
		}
Ejemplo n.º 5
0
 partial void InsertConversation(Conversation instance);
Ejemplo n.º 6
0
		private void attach_Conversations(Conversation entity)
		{
			this.SendPropertyChanging();
			entity.User = this;
		}