Exemplo n.º 1
0
 // Creates contact with contact object
 public void CreateContact(Contact contact)
 {
     using (WhatsUpDbContext db = new WhatsUpDbContext())
     {
         db.Contacts.Add(contact);
         db.SaveChanges();
     }
 }
Exemplo n.º 2
0
 // Puts message object into the database
 public void SendMessage(Message message)
 {
     using (WhatsUpDbContext db = new WhatsUpDbContext())
     {
         db.Messages.Add(message);
         db.SaveChanges();
     }
 }
Exemplo n.º 3
0
        // Retrieves specific account based on phonenumber string
        public Account GetAccountByPhoneNumber(string phoneNumber)
        {
            Account account = new Account();

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                account = db.Accounts.Where(x => x.PhoneNumber == phoneNumber).SingleOrDefault();
            }
            return(account);
        }
Exemplo n.º 4
0
        // Returns the list of accounts from the database
        public IEnumerable <Account> GetAllAccounts()
        {
            IEnumerable <Account> accounts = new List <Account>();

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                accounts = db.Accounts.ToList();
            }
            return(accounts);
        }
Exemplo n.º 5
0
        // Gets account based on accountId
        public Account GetAccount(int accountId)
        {
            Account account = new Account();

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                account = db.Accounts.Where(x => x.AccountId == accountId).SingleOrDefault();
            }
            return(account);
        }
Exemplo n.º 6
0
        public void CreateAcccount(Account account)
        {
            account.ContactlistId = CreateContactList().ContactListId;

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                db.Accounts.Add(account);
                db.SaveChanges();
            }
        }
Exemplo n.º 7
0
        // Function that checks given phone number if entry already exists in database
        public bool AccountExists(Account account)
        {
            bool accountExists = false;

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                accountExists = db.Accounts.Where(x => x.PhoneNumber == account.PhoneNumber).Any();
            }
            return(accountExists);
        }
Exemplo n.º 8
0
        // Gets a specific contact based on contactlistId and friendId
        public Contact GetContact(int contactlistId, int friendId)
        {
            Contact contact = new Contact();

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                contact = db.Contacts.Where(x => x.ContactListId == contactlistId && x.FriendId == friendId).FirstOrDefault();
            }

            return(contact);
        }
Exemplo n.º 9
0
        // Gets list of contacts that match contactlistId
        public IEnumerable <Contact> GetContactsByContactListId(int contactlistId)
        {
            IEnumerable <Contact> contacts = new List <Contact>();

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                contacts = db.Contacts.Where(x => x.ContactListId == contactlistId).ToList();
            }

            return(contacts);
        }
Exemplo n.º 10
0
        // Gets message list based on chatId
        public IEnumerable <Message> GetMessages(int chatId)
        {
            List <Message> messages = new List <Message>();

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                messages = db.Messages.Where(x => x.ChatId == chatId).ToList();
            }

            return(messages);
        }
Exemplo n.º 11
0
        // Gets a chat object based on chatId
        public Chat GetChat(int chatId)
        {
            Chat chat = new Chat();

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                chat = db.Chats.Where(x => x.ChatId == chatId).FirstOrDefault();
            }

            return(chat);
        }
Exemplo n.º 12
0
 // Creates new chat and gives chat object a chatId
 public Chat CreateChat(Chat chat)
 {
     using (WhatsUpDbContext db = new WhatsUpDbContext())
     {
         Chat chatz = new Chat();
         chatz = db.Chats.Add(chat);
         db.SaveChanges();
         chat.ChatId = chatz.ChatId;
     }
     return(chat);
 }
Exemplo n.º 13
0
        // Returns true or false based on database entries, only true if a phone number and password match
        public bool LogIn(Account account)
        {
            bool login = false;

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                var acc = db.Accounts.SingleOrDefault(x => x.PhoneNumber == account.PhoneNumber);
                login = acc != null && Argon2.Verify(acc.Password, account.Password);
            }
            return(login);
        }
Exemplo n.º 14
0
        public ContactList CreateContactList()
        {
            ContactList contactList = new ContactList();

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                contactList = db.ContactLists.Add(contactList);
                db.SaveChanges();
            }
            return(contactList);
        }
Exemplo n.º 15
0
        // Returns accounts based on contactlistId
        public IEnumerable <Account> GetAccountsByContactListId(int contactlistId)
        {
            List <Account> accounts = new List <Account>();

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                IEnumerable <Contact> contacts = contactRep.GetContactsByContactListId(contactlistId);

                foreach (Contact contact in contacts)
                {
                    Account account = GetAccount(contact.FriendId);
                    accounts.Add(account);
                }
            }

            return(accounts);
        }
Exemplo n.º 16
0
        // Gets chatId based by checking database if entry exists where contactId + accountId match or vice versa
        public int GetChatId(Chat chat)
        {
            int chatId = 0;

            using (WhatsUpDbContext db = new WhatsUpDbContext())
            {
                if (db.Chats.Where(x => x.AccountId == chat.AccountId && x.ContactId == chat.ContactId).Any())
                {
                    chatId = db.Chats.Where(x => x.AccountId == chat.AccountId && x.ContactId == chat.ContactId).FirstOrDefault().ChatId;
                }
                else if (db.Chats.Where(x => x.AccountId == chat.ContactId && x.ContactId == chat.AccountId).Any())
                {
                    chatId = db.Chats.Where(x => x.AccountId == chat.ContactId && x.ContactId == chat.AccountId).FirstOrDefault().ChatId;
                }
            }

            return(chatId);
        }