public static void UsingMessageModel(Message msg)
        {

            string[] message_values = 
            {

                 msg.to, 
                 msg.from, 
                 msg.body, 
                 msg.project, 

            };


            string [] column_names = Build.StringArray("_to", "_from", "_body", "_project");

            List<string[]> values = new List<string[]>();

            values.Add(message_values);

            DataAccess.DataAccess.Create(

                "messages",
                column_names,
                values

            );
        }
        public ActionResult GenerateMessage(Message msg)
        {
            if (msg.to == null)
            {

                msg.to = "No recipient specified";

            }

            if (msg.from == null)
            {

                msg.from = "no sender specified";

            }

            if (msg.body == null)
            {

                msg.body = "no text provided";

            }

            if (msg.project == null)
            {

                msg.project = "test";

            }

            InsertToMessageTable.UsingMessageModel(msg);

            return View("Mock", Chat());
        }
 public Chat()
 {
     if (this.message == null)
     {
         this.message = new Message();
     }
 }
        public Chat Chat()
        {
            Chat chat = new Chat();
            List<List<object>> result = DataAccess.DataAccess.Read(Build.StringArray("messages"), Build.StringArray("*"));
            chat.messages = new List<Message>();

            foreach (List<object> row in result)
            {
                Message msg = new Message();
                msg.from = (string)row[1];
                msg.to = (string)row[2];
                msg.body = (string)row[3];
                msg.project = (string)row[4];
                msg.time = (DateTime)row[5];
                chat.messages.Add(msg);
            }

            return chat;
        }
        public ActionResult Search(Search searchableStuff)
        {
            string keyword = searchableStuff.keyword;
            List<string> tablesToSearch = new List<string>();
            if (!(searchableStuff.table==null))
            {
                tablesToSearch.Add(searchableStuff.table);
            }
            Search searchResult = new Search();

            List<List<object>> tablesWillSearch = new List<List<object>>();

            if (tablesToSearch.Count()==0)
            {
                tablesWillSearch = DataAccess.DataAccess.ListTables();
            }
            else
            {
                foreach (string table in tablesToSearch)
                {
                    List<object> list = new List<object> { table };
                    tablesWillSearch.Add(list);
                }
            }

            foreach (List<object> tables in tablesWillSearch)
            {
                if (!(tables[0].ToString().StartsWith("Asp") || tables[0].ToString().StartsWith("__")))
                {
                    List<List<object>> tableResults = TableSearch(tables[0], keyword);
                    foreach (List<object> result in tableResults)
                    {
                        switch (tables[0].ToString())
                        {
                            case "Messages":
                                Message m = new Message();
                                m.id = (int)result[0];
                                m.from = (string)result[1];
                                m.to = (string)result[2];
                                m.body = (string)result[3];
                                m.project = (string)result[4];
                                m.time = (DateTime)result[5];
                                searchResult.messages.Add(m);
                                break;
                            case "Projects":
                                Project p = new Project();
                                p.id = (int)result[0];
                                p.name = (string)result[1];
                                p.description = (string)result[2];
                                break;
                            case "Events":
                                Event e = new Event();
                                e.id = (int)result[0];
                                e.calendarId = (int)result[1];
                                e.title = (string)result[2];
                                e.description = (string)result[3];
                                e.occurencetime = (DateTime)result[4];
                                e.time = (DateTime)result[5];
                                searchResult.events.Add(e);
                                break;
                            case "User":
                                User u = new User();
                                u.id = (int)result[0];
                                break;
                            default:
                                Other o = new Other();
                                o.result = result;
                                o.table = (string)tables[0];
                                searchResult.others.Add(o);
                                break;
                        }
                    }
                }
            }

            return View(searchResult);
        }