Ejemplo n.º 1
0
        public static GroupChat AddChat(this ChatDBContext db, String ChatName, String CreatorId)
        {
            GroupChat gc = new GroupChat();

            gc.ChatName   = ChatName;
            gc.CreateTime = DateTime.Now;

            Chats_Participants cp = new Chats_Participants();

            cp.AddTime = gc.CreateTime;
            cp.UserId  = CreatorId;

            gc.Participants.Add(cp);

            db.Chats.Add(gc);

            int temp = db.SaveChanges();

            if (temp == 2)
            {
                return(gc);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static GroupChat AddParticipant(this ChatDBContext db, int ChatId, string ParticipantId, string InvitatorId)
        {
            Chats_Participants cp = db.Chats_Participants.Where(x => x.ChatId == ChatId && x.UserId == ParticipantId).SingleOrDefault();

            if (cp == null)
            {
                cp             = new Chats_Participants();
                cp.InvitatorId = InvitatorId;
                cp.UserId      = ParticipantId;
                cp.ChatId      = ChatId;
                cp.AddTime     = DateTime.Now;

                db.Chats_Participants.Add(cp);
                int res = db.SaveChanges();

                if (res == 1)
                {
                    return(cp.Chat);
                }
            }
            return(null);
        }