Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi guys,
I am trying to make a muti step jquery form for uploading resume,
and i send data to db by json and using Linq to Entity,
I have 4 tables:
1- Basic info
2- education info
3- work experience and
4- skills

when user click on submit button i need to add edu and work and skill info into another tables but i need the generated userid to insert into those tables as foreign keys,
dont know how to get id and how to pass it as parameters into those tables:

its my json code:
XML
<script>
        windows.onload = function () {
            $.getFormObject = function (selector) {

                var obj = {};
                var propArr = $(selector).serializeArray();

                $.each(propArr, function (i, p) {
                    obj[p.name] = p.value;
                });

                return obj;

            };

        };
   </script>
<script>
  //  window.onload =
    $(function () {
        $('#btnSubmit').on('click', function () {
            var formObj = $.getFormObject('#msform');
            formObj.Id = 0;

            var dataToSend = { resume: formObj };

            $.ajax({
                url: '/Resume.aspx/AddBaseResume',
                contentType: 'application/json',
                dataType: 'json',
                type: 'post',
                data: JSON.stringify(dataToSend),
                success: function (id) {

                    var $messageContainer = $('.message-container');
                    $messageContainer.html('');
                    $('<div class="alert alert-success" />')
                        .html('Your ID is: ' + id.d)
                        .hide()
                        .fadeIn()
                        .appendTo($messageContainer);

                    //reloadGrid();
                },
                error: function () {

                    var $messageContainer = $('.message-container');
                    $messageContainer.html('');
                    $('<div class="alert alert-danger" />')
                        .html('Oops! Can not add you right now! :(')
                        .hide()
                        .fadeIn()
                        .appendTo($messageContainer);
                }
            });;


        });
    });
  </script>



and its my webmethod:
C#
[WebMethod]
        public static string AddBaseResume(tblResume resume)
        {
            var db = new SHDBEntities1();
            db.tblResumes.Add(resume);
            db.SaveChanges();
            return resume.Id.ToString();
        }

        [WebMethod]
        public static string AddEducation(tblEducation edu)
        {
            var db = new SHDBEntities1();
            db.tblEducations.Add(edu);
            db.SaveChanges();
            return edu.Id.ToString();
        }


thanks in advance for any help or suggestion!
Posted

1 solution

You should be handling the entire relational database inserts in one call with Transaction blocks and not with two different set of WebMethods. What if there's some exception , How will you rollback your changes.

I see a design flaw.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900