Exemple #1
0
        public async Task CreateChat(Guid userGuid, Guid creatorGuid)
        {
            using (var context = new MessengerContext())
            {
                Guid    dbChatGuid = Guid.NewGuid();
                Db.Chat dbChat     = new Db.Chat
                {
                    Guid = dbChatGuid
                };

                context.Chat.Add(dbChat);

                Db.Party party1 = new Db.Party
                {
                    ChatGuid = dbChatGuid,
                    UserGuid = creatorGuid,
                };

                Db.Party party2 = new Db.Party
                {
                    ChatGuid = dbChatGuid,
                    UserGuid = userGuid,
                };

                context.Party.Add(party1);
                context.Party.Add(party2);

                await context.SaveChangesAsync();
            }
        }
Exemple #2
0
        public async Task CreateGroupChat(string chatName, Guid creatorGuid, List <Guid> userGuids)
        {
            using (var context = new MessengerContext())
            {
                var dbChatGuid = Guid.NewGuid();
                var dbChat     = new Db.Chat();
                dbChat.UserGuid = creatorGuid;
                dbChat.Name     = chatName;
                dbChat.Guid     = dbChatGuid;
                context.Chat.Add(dbChat);

                foreach (var userGuid in userGuids)
                {
                    var dbParty = new Db.Party();
                    dbParty.UserGuid = userGuid;
                    dbParty.ChatGuid = dbChatGuid;
                    context.Party.Add(dbParty);
                }

                var dbSelfParty = new Db.Party();
                dbSelfParty.UserGuid = creatorGuid;
                dbSelfParty.ChatGuid = dbChatGuid;
                context.Party.Add(dbSelfParty);

                await context.SaveChangesAsync();
            }
        }