Exemplo n.º 1
0
        public static ChatMessage updateChatMessage(ChatMessageViewModel model)
        {
            var db = new SQLiteConnection(CommonConstant.DBPath);

            ChatMessage chatMessage = getmessagebyid(model.MobiledatabaseId);

            try
            {
                if (chatMessage != null)
                {
                    chatMessage.ChatMessageId = model.ChatMessageId;
                    chatMessage.IsRecieved    = model.IsRecieved;
                    chatMessage.IsRead        = model.IsRead;
                    chatMessage.IsSend        = model.IsSend;
                    chatMessage.MessageTime   = TimeZone.CurrentTimeZone.ToLocalTime(Convert.ToDateTime(model.MessageTime));
                    chatMessage.UserId        = CommonHelper.GetUserId();
                    db.Update(chatMessage);
                    if (model.Attachments.Count > 0)
                    {
                        ChatAttachmentRepository.SaveChatAttachment(model.Attachments, model.ContactId, model.ChatMessageId);
                    }
                }
                db.Commit();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message, ex);
            }
            db.Close();
            return(chatMessage);
        }
Exemplo n.º 2
0
        public static ChatMessage SaveChatMessage(ChatMessageViewModel model, long ChatId)
        {
            var db = new SQLiteConnection(CommonConstant.DBPath);

            ChatMessage chatMessage = null;

            try
            {
                lock (thisLock)
                {
                    if (chatMessage == null)
                    {
                        chatMessage               = new ChatMessage();
                        chatMessage.ContactId     = model.ContactId;
                        chatMessage.ChatId        = ChatId;
                        chatMessage.ChatMessageId = model.ChatMessageId;
                        chatMessage.MessageText   = model.Message;
                        chatMessage.MessageTime   = TimeZone.CurrentTimeZone.ToLocalTime(Convert.ToDateTime(model.MessageTime));
                        chatMessage.IsRead        = model.IsRead;
                        chatMessage.IsRecieved    = model.IsRecieved;
                        chatMessage.IsSend        = model.IsSend;
                        chatMessage.UserId        = CommonHelper.GetUserId();
                        db.Insert(chatMessage);
                        if (model.Attachments.Count > 0)
                        {
                            ChatAttachmentRepository.SaveChatAttachment(model.Attachments, model.ContactId, model.ChatMessageId);
                        }
                    }
                    db.Commit();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message, ex);
            }
            db.Close();
            return(chatMessage);
        }