Example #1
0
    // ______________________________________
    //
    // 1. LOAD DATA.
    // ______________________________________
    //


    public static News_Entry Parse_Single_Data(string news_entry_data)
    {
        News_Entry news_entry = new News_Entry();

        string[] data = Utils.Split(news_entry_data, '#');

        for (int x = 0; x < data.Length; x++)
        {
            data[x] = Encryption.Decrypt(data[x]);
        }

        news_entry.Id            = uint.Parse(data[0]);
        news_entry.Title         = data[1];
        news_entry.Details       = data[2];
        news_entry.Creation_time = Utils.Get_DateTime(data[3]);

        foreach (string element in Utils.Split(data[4], '|'))
        {
            news_entry.Imgs.Add(element);
        }

        news_entry.Author_Id = uint.Parse(data[5]);
        news_entry.Privacy   = Utils.Parse_Privacy(data[6]);
        news_entry.Seen      = User.User_Info.News_Data.Exists(a => a == news_entry.Id);

        return(news_entry);
    }
    public void Save()
    {
        List <string> field_names = new List <string>()
        {
            "REQUEST_TYPE",
        };

        List <string> field_values = new List <string>()
        {
            "",
            Data.Id.ToString(),
            Encryption.Encrypt(Data.Title),
            Encryption.Encrypt(Data.Details),
            Data.Author_Id.ToString(),
            Data.Privacy.ToString()
        };

        if (Data.GetType().Equals(typeof(Poll)))
        {
            Poll data = (Poll)Data;
            field_names.AddRange(new List <string>()
            {
                "poll_id",
                "poll_name",
                "poll_details",
                "poll_author_id",
                "poll_privacy",
                "poll_date_creation",
                "poll_date_deadline",
                "poll_options"
            });

            field_values[0] = "set_poll";
            field_values.AddRange(new List <string>()
            {
                Utils.Get_String_SQL(data.Creation_Time),
                Utils.Get_String_SQL(data.Date_Deadline),
                Utils.List_To_String(data.Vote_Types)
            });
        }

        else if (Data.GetType().Equals(typeof(Calendar_Event)))
        {
            Calendar_Event data = (Calendar_Event)Data;
            field_names.AddRange(new List <string>()
            {
                "event_id",
                "event_name",
                "event_details",
                "event_author_id",
                "event_privacy",
                "event_location_event",
                "event_location_meeting",
                "event_date_event",
                "event_date_meeting",
                "event_date_deadline",
                "event_transportation",
                "event_cash",
                "event_food"
            });

            field_values[0] = "set_event";
            field_values.AddRange(new List <string>()
            {
                Encryption.Encrypt(data.Location_Event),
                Encryption.Encrypt(data.Location_Meeting),
                Utils.Get_String_SQL(data.Date_Event),
                Utils.Get_String_SQL(data.Date_Meeting),
                Utils.Get_String_SQL(data.Date_Deadline),
                Encryption.Encrypt(data.Transportation),
                Encryption.Encrypt(data.Cash),
                Encryption.Encrypt(data.Food)
            });
        }

        else if (Data.GetType().Equals(typeof(News_Entry)))
        {
            News_Entry data = (News_Entry)Data;
            field_names.AddRange(new List <string>()
            {
                "news_id",
                "news_name",
                "news_details",
                "news_author_id",
                "news_privacy",
                "news_date_creation",
                "news_images"
            });

            field_values[0] = "set_news";
            field_values.AddRange(new List <string>()
            {
                Utils.Get_String_SQL(data.Creation_time),
                Encryption.Encrypt(Utils.List_To_String(data.Imgs))
            });
        }

        else
        {
            return;
        }

        Database_Handler.Selected_Data = Data;

        if (Data.Id == 0)
        {
            Database_Handler.Data_List_Add(Data.Database_Handler_Type(), Data);
        }

        Http_Client.Send_Post(
            field_names.ToArray(),
            field_values.ToArray(),
            Handle_Save_Response
            );

        Save_Button.interactable = false;
    }