2

I'm currently working on a school project that requires a scheduling calendar as it's core function. However, I downloaded a third party java script calendar from the net and edit the java script codes accordingly to my project requirements.

But as a noob in asp.net, I do not know how to save the javascript object into my SQL server. Is there a guide or a website where I can learn how to do it ? Below is a set of my java script, so how do I use JSON with this code?

$(document).ready(function () {


    /* initialize the external events
    -----------------------------------------------c ------------------*/

    $('#external-events div.external-event2').each(function () {

        // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
        // it doesn't need to have a start or end
        var eventObject = {
            title: $.trim($(this).text()) // use the element's text as the event title
        };

        // store the Event Object in the DOM element so we can get to it later
        $(this).data('eventObject', eventObject);

        // make the event draggable using jQuery UI
        $(this).draggable({
            zIndex: 999,
            revert: true,      // will cause the event to go back to its
            revertDuration: 0  //  original position after the drag
        });






    });







    /* initialize the external events
    -----------------------------------------------c ------------------*/

    $('#external-events div.external-event').each(function () {

        // create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
        // it doesn't need to have a start or end
        var eventObject = {
            title: $.trim($(this).text()) // use the element's text as the event title
        };

        // store the Event Object in the DOM element so we can get to it later
        $(this).data('eventObject', eventObject);

        // make the event draggable using jQuery UI
        $(this).draggable({
            zIndex: 999,
            revert: true,      // will cause the event to go back to its
            revertDuration: 0  //  original position after the drag
        });






    });


    /* initialize the calendar
    -----------------------------------------------------------------*/

    var calendar = $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },

        selectable: true,
        selectHelper: true,
        select: function (start, end, allDay) {
            var title = prompt('Event Title:');
            if (title) {
                calendar.fullCalendar('renderEvent',
                    {
                        title: title,
                        start: start,
                        end: end,
                        allDay: allDay
                    },
                    true // make the event "stick"
                );
            }
            // calendar.fullCalendar('unselect');
        },




        eventClick: function (calEvent, jsEvent, view) {


            var title = prompt('Rename Event Title:');

            calEvent.title = title;
            // copiedEventObject.title = title;
            alert('Altered Event : ' + calEvent.title);


            // change the border color just for fun
            $(this).css('border-color', 'red');

        },







        editable: true,
        droppable: true, // this allows things to be dropped onto the calendar !!!
        drop: function (date, allDay) { // this function is called when something is dropped

            // retrieve the dropped element's stored Event Object
            var originalEventObject = $(this).data('eventObject');


            // we need to copy it, so that multiple events don't have a reference to the same object
            var copiedEventObject = $.extend({}, originalEventObject);

            // assign it the date that was reported
            copiedEventObject.start = date;
            copiedEventObject.allDay = allDay;
            //    copiedEventObject.title = 'abc';     //<<<Change the title



            // render the event on the calendar
            // the last `true` argument determines if the event "sticks" (http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
            $('#calendar').fullCalendar('renderEvent', copiedEventObject, true);

            // is the "remove after drop" checkbox checked?
            if ($('#drop-remove').is(':checked')) {
                // if so, remove the element from the "Draggable Events" list
                $(this).remove();
            }

        }
    });


});

2 Answers 2

3

Convert your object JSON a String with JSON.stringify(object), and save it in the database, then when you access the data and recover this String, you send the client and to parse a JSON object with JSON.parse (string)

Sign up to request clarification or add additional context in comments.

2 Comments

but how do i convert this object with json?
exactly what data you need to store in the database?
0

You can simply use JSON.stringify() and store it in the DB. Also make sure you compress the data which will save you lot of space.

let data = { 'applicationId': '123456', 'digest': JSON.stringify(digest) };
const ps = new sql.PreparedStatement(pool);
ps.input('applicationId', sql.VarChar);
ps.input('digest', sql.NVarChar); // When storing the actual data we compress it and store it. 

await ps.prepare(`INSERT INTO ${DIGEST_TABLE} VALUES (@applicationId, COMPRESS(@digest))`);
await ps.execute(data)

Then when you are reading you can decompress it and read the data.

SELECT CAST(DECOMPRESS(digest) AS NVARCHAR(MAX)) AS digest FROM SOME_TABLE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.