Ejemplo n.º 1
0
        public void CreateMsg(string text,
                              Guid?chatID,
                              Guid userID,
                              string username)
        {
            DateTime datetimenow = TimeZoneManager.DateTimeNow;

            using (Searchwar_netEntities db = new Searchwar_netEntities())
            {
                SW_chat chate = null;

                if (!chatID.HasValue)
                {
                    chate               = new SW_chat();
                    chate.ChatId        = Guid.NewGuid();
                    chate.ChatDateAdded = datetimenow;
                    chate.ChatDateEdit  = datetimenow;
                    chate.ChatIsClosed  = false;

                    db.SW_chat.AddObject(chate);
                    db.SaveChanges();
                }
                else
                {
                    chate = db.SW_chat.SingleOrDefault(c => c.ChatId == chatID);
                    chate.ChatDateEdit = datetimenow;
                    chate.ChatIsClosed = false;
                }

                if (chate != null)
                {
                    SW_ChatPerson createPerson = db.SW_ChatPersons.SingleOrDefault(p => p.ChatPersonId == userID);

                    if (createPerson == null)
                    {
                        createPerson = new SW_ChatPerson();
                        createPerson.ChatPersonId   = userID;
                        createPerson.ChatPersonName = Membership.GetUser(userID) != null?Membership.GetUser(userID).UserName : username;

                        createPerson.ChatPersonDateAdded = datetimenow;
                        createPerson.ChatPersonDateEdit  = datetimenow;

                        db.SW_ChatPersons.AddObject(createPerson);
                        db.SaveChanges();
                    }

                    SW_ChatMessage createText = new SW_ChatMessage();
                    createText.ChatId           = chatID.Value;
                    createText.ChatMsgId        = Guid.NewGuid();
                    createText.ChatPersonId     = createPerson.ChatPersonId;
                    createText.ChatMsgText      = text;
                    createText.ChatMsgDateAdded = datetimenow;

                    db.SW_ChatMessages.AddObject(createText);
                    db.SaveChanges();
                }
            }
        }
Ejemplo n.º 2
0
        public void OpenChat(Guid chatID)
        {
            DateTime datetimenow     = TimeZoneManager.DateTimeNow;
            Searchwar_netEntities db = new Searchwar_netEntities();

            SW_chat chatobj = db.SW_chat.SingleOrDefault(c => c.ChatId == chatID);

            if (chatobj != null)
            {
                chatobj.ChatIsClosed = false;
                chatobj.ChatDateEdit = datetimenow;
            }

            db.SaveChanges();
        }
Ejemplo n.º 3
0
        public void CloseChat(Guid chatID, int minutes)
        {
            DateTime datetimenow     = TimeZoneManager.DateTimeNow;
            Searchwar_netEntities db = new Searchwar_netEntities();

            SW_chat chatobj = db.SW_chat.SingleOrDefault(c => c.ChatId == chatID);

            if (chatobj != null)
            {
                if (chatobj.ChatDateEdit < datetimenow.AddMinutes(-minutes))
                {
                    chatobj.ChatIsClosed = true;
                    chatobj.ChatDateEdit = datetimenow;
                }
            }

            db.SaveChanges();
        }