public static void sendMessage(Messages UpdatedMessage)
        {
            using (var db = new LanguageExchangeModel())
            {
                var message = db.Messages.Where(m => m.MessageId == UpdatedMessage.MessageId).FirstOrDefault();
                if (message == null)
                {
                    return;
                }
                var originalMessage = message;
                message.MessageHeader = UpdatedMessage.MessageHeader;
                message.MessageContent = UpdatedMessage.MessageContent;
                message.MessageTimeStamp = DateTime.Now;

                db.Entry(originalMessage).CurrentValues.SetValues(message);
                db.SaveChanges();
            }
        }
        public static IEnumerable<Messages> ShowInboxMessages (string email)
        {
            var db = new LanguageExchangeModel();
            var user = db.UserAccounts.Where(u => u.UserEmail == email).FirstOrDefault();
            var userId = user.UserIdNumber;
            var inbox = db.EmailInboxes.Where(i => i.UserId == userId).FirstOrDefault();
            if (inbox == null)
            {
                inbox = new EmailInbox();
                inbox.UserId = userId;
                
            }
            var messages = inbox.Messages.Where(m => m.InboxId2 == userId);
            if (messages == null)
            {
                var message = new Messages();
                message.InboxId1 = 1;
                message.InboxId2 = userId;
                message.MessageHeader = "Welcome to Xchange!";
                message.MessageContent = "Welcome to Xchange! We're glad you're here. Fill out your profile details and search for other language learners to get started.";
                message.MessageTimeStamp = DateTime.Now;
                message.MessageTo = user.UserFirstName;
                message.MessageFrom = "Xchange Team";

                inbox.Messages.Add(message);
                
                db.Messages.Add(message);

                db.SaveChanges();
            }
            var sortedMessages = messages.OrderByDescending(x => x.MessageTimeStamp);

            return sortedMessages;
        }
        public static void CreateMessage(int id, string email, Messages UpdatedMessage)
        {
            var db = new LanguageExchangeModel();

            var userFrom = db.UserAccounts.Where(u => u.UserEmail == email).FirstOrDefault();
            var userFromId = userFrom.UserIdNumber;
            var userTo = db.UserAccounts.Where(u => u.UserIdNumber == id).FirstOrDefault();
            var userToId = userTo.UserIdNumber;
            var user2email = userTo.UserEmail;
            var inboxFrom = db.EmailInboxes.Where(i => i.UserId == userFromId).FirstOrDefault();
            if (inboxFrom == null)
            {
                inboxFrom = new EmailInbox();
                inboxFrom.UserId = userFromId;
                db.EmailInboxes.Add(inboxFrom);
                db.SaveChanges();
            }
            var inboxTo = db.EmailInboxes.Where(i => i.UserId == userToId).FirstOrDefault();
            if (inboxTo == null)
            {
                inboxTo = new EmailInbox();
                inboxTo.UserId = userToId;
                db.EmailInboxes.Add(inboxTo);
                db.SaveChanges();
            }
            var message = new Messages();
            message.InboxId1 = userFromId;
            message.InboxId2 = userToId;
            var userFromPrefs = db.UserPreferences.Where(p => p.UserId == userFromId).FirstOrDefault();
            if (userFromPrefs == null)
            {
                message.MessageFrom = userFrom.UserFirstName;
            }
            message.MessageFrom = userFromPrefs.UserPreferencesName;
            var userToPrefs = db.UserPreferences.Where(p => p.UserId == userToId).FirstOrDefault();
            if (userToPrefs == null)
            {
                message.MessageTo = userTo.UserFirstName;
            }
            message.MessageTo = userToPrefs.UserPreferencesName;
            message.MessageHeader = UpdatedMessage.MessageHeader;
            message.MessageContent = UpdatedMessage.MessageContent;
            message.MessageTimeStamp = DateTime.Now;
         
            inboxFrom.Messages.Add(message);
            inboxTo.Messages.Add(message);
            db.Messages.Add(message);

            SystemEmail("You have a new message on Xchange (http://languagexchange.azurewebsites.net/). Login to view.", user2email);

            db.SaveChanges();

            
        }