public void AddEntity <T>(T entity)
        {
            DataRow row = new DataTable().NewRow();

            foreach (PropertyInfo property in entity.GetType().GetProperties())
            {
                row[row.Table.Columns.Add(property.Name)] = entity.GetType().GetProperty(property.Name).GetValue(entity, null);
            }
            database.SendQuery(MySqlQueryConstructor.InsertQuery(entity.GetType().Name, row));
        }
        public List <T> GetEntitiesByPrototype <T>(T prototype, params string[] properties)
        {
            List <T>      entities   = new List <T>();
            List <string> conditions = new List <string>();

            foreach (PropertyInfo property in prototype.GetType().GetProperties())
            {
                switch (property.PropertyType.ToString())
                {
                case "System.Int32": if ((int)property.GetValue(prototype, null) == new int())
                    {
                        continue;
                    }
                    break;

                case "System.String": if ((string)property.GetValue(prototype, null) == null)
                    {
                        continue;
                    }
                    break;

                case "System.TimeSpan": if ((TimeSpan)property.GetValue(prototype, null) == new TimeSpan())
                    {
                        continue;
                    }
                    break;

                case "System.DateTime": if ((DateTime)property.GetValue(prototype, null) == new DateTime())
                    {
                        continue;
                    }
                    break;
                }
                conditions.Add(MySqlQueryConstructor.SimpleCondition(property.Name, "=", property.GetValue(prototype, null)));
            }
            DataTable table = database.GetData(MySqlQueryConstructor.SelectQuery(typeof(T).Name, properties) + MySqlQueryConstructor.WhereQuery(conditions.ToArray()));

            foreach (DataRow row in table.Rows)
            {
                entityBuilder.SetEntity(Activator.CreateInstance <T>());
                foreach (DataColumn column in row.Table.Columns)
                {
                    entityBuilder.SetEntityProperty(column.ColumnName, row[column.ColumnName]);
                }
                entities.Add((T)entityBuilder.BuildEntity());
            }
            return(entities);
        }
        public List <T> GetEntities <T>(params string[] properties)
        {
            List <T>  entities = new List <T>();
            DataTable table    = database.GetData(MySqlQueryConstructor.SelectQuery(typeof(T).Name, properties));

            foreach (DataRow row in table.Rows)
            {
                entityBuilder.SetEntity(Activator.CreateInstance <T>());
                foreach (DataColumn column in row.Table.Columns)
                {
                    entityBuilder.SetEntityProperty(column.ColumnName, row[column.ColumnName]);
                }
                entities.Add((T)entityBuilder.BuildEntity());
            }
            return(entities);
        }
        public void ChangeEntity <T>(T oldEntity, T newEntity)
        {
            Dictionary <string, object> changes = new Dictionary <string, object>();

            foreach (PropertyInfo property in newEntity.GetType().GetProperties())
            {
                switch (property.PropertyType.ToString())
                {
                case "System.Int32": if ((int)property.GetValue(newEntity, null) == new int())
                    {
                        continue;
                    }
                    break;

                case "System.String": if ((string)property.GetValue(newEntity, null) == null)
                    {
                        continue;
                    }
                    break;

                case "System.TimeSpan": if ((TimeSpan)property.GetValue(newEntity, null) == new TimeSpan())
                    {
                        continue;
                    }
                    break;

                case "System.DateTime": if ((DateTime)property.GetValue(newEntity, null) == new DateTime())
                    {
                        continue;
                    }
                    break;
                }
                changes.Add(property.Name, property.GetValue(newEntity, null));
            }
            database.SendQuery(MySqlQueryConstructor.UpdateQuery(oldEntity.GetType().Name,
                                                                 MySqlQueryConstructor.SetQuery(changes)) +
                               MySqlQueryConstructor.WhereQuery(MySqlQueryConstructor.SimpleCondition(oldEntity.GetType().GetProperties()[0].Name,
                                                                                                      "=",
                                                                                                      oldEntity.GetType().GetProperties()[0].GetValue(oldEntity, null))));
        }
        public void RemoveEntity <T>(T entity)
        {
            List <string> conditions = new List <string>();

            foreach (PropertyInfo property in entity.GetType().GetProperties())
            {
                switch (property.PropertyType.ToString())
                {
                case "System.Int32": if ((int)property.GetValue(entity, null) == new int())
                    {
                        continue;
                    }
                    break;

                case "System.String": if ((string)property.GetValue(entity, null) == null)
                    {
                        continue;
                    }
                    break;

                case "System.TimeSpan": if ((TimeSpan)property.GetValue(entity, null) == new TimeSpan())
                    {
                        continue;
                    }
                    break;

                case "System.DateTime": if ((DateTime)property.GetValue(entity, null) == new DateTime())
                    {
                        continue;
                    }
                    break;
                }
                conditions.Add(MySqlQueryConstructor.SimpleCondition(property.Name, "=", property.GetValue(entity, null)));
            }
            database.SendQuery(MySqlQueryConstructor.DeleteQuery(entity.GetType().Name, MySqlQueryConstructor.WhereQuery(conditions.ToArray())));
        }