Updating two tables inline editing in .Net

Updating two tables inline editing in .Net

MundaringMundaring Posts: 34Questions: 12Answers: 1

Hi,

I am trying with an inline editing to update two fields in different tables, Here is what I have accomplished.

I am updating the first table, but when I try to update the second one I got the problem.

My question is do I need to have different models? because the Key from both tables are different and when the controller receive the information is getting same Key Id for both tables as showed on the image.

I am displaying the information in a datatable but there is just one field editable as a drop down list. When I change it I got the correct information as you can appreciate it on the image attached, but when I received in the controller same Id key is taken for both tables to be updated.

I would like to know how can I send to the controller two different values as a key for each table to be updated if possible.

My Controller

//DataTables        
        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
        public ActionResult DTReviewsManagerHR2()
        {
            var request = HttpContext.Request.Form;
            var x = HttpContext.Request.Params;

            using (var dtDB = new DataTables.Database("sqlserver", conn))
            {
                var response = new Editor(dtDB, "SignOff", "Id")//Application.

                    .Model<VMReviewsToAssing>()                    
                    .Field(new Field("vwReviewsHR.EvaluationDate")
                        .GetFormatter(Format.DateSqlToFormat("dd/MM/yyyy"))
                        .SetFormatter(Format.DateFormatToSql("dd/MM/yyyy"))
                    )
                    .Field(new Field("SignOff.ResponsibleId")
                        .Options("vwHREmployees", "Id", "EmployeeName"/*, q => q.Where("Active", true, "=")*/)
                    )
                    .Field(new Field("SignOffReviewer.Id")
                        .Validator(Validation.None())
                    )
                    .Field(new Field("SignOffReviewer.EmployeeId")
                        .Validator(Validation.None())
                    )                    
                    .LeftJoin("vwReviewsHR", "SignOff.Id", "=", "vwReviewsHR.SignOffId")
                    .LeftJoin("vwHREmployees", "vwReviewsHR.ResponsibleId", "=", "vwHREmployees.Id")                    
                    .LeftJoin("SignOffReviewer", "vwReviewsHR.SignOffReviewerId", "=", "SignOffReviewer.Id")            
                    .Where("vwReviewsHR.Id", "","<>")        
                    .Process(request)
                    .Data();

                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }

My View Model

public class VMReviewsToAssing
    {
        public class vwReviewsHR: EditorModel
        {
            public int Id { get; set; }
            public string EvaluationDate { get; set; }
            public string DepartmentName { get; set; }
            public string EmployeeName { get; set; }
            public string PositionName { get; set; }
            public string ManagerName { get; set; }
            public Nullable<bool> AdHoc { get; set; }
            public Nullable<bool> SuperviseOthers { get; set; }
            public string Reviewer { get; set; }
            public Nullable<byte> CycleId { get; set; }
            public Nullable<short> ResponsibleId { get; set; }
            public Nullable<byte> IsHR { get; set; }
            public Nullable<short> EmployeeId { get; set; }
            public Nullable<int> SignOffId { get; set; }
            public Nullable<int> SignOffReviewerId { get; set; }
        }

        public class vwHREmployees : EditorModel
        {
            public short Id { get; set; }
            public string EmployeeName { get; set; }
        }

        public class SignOff : EditorModel
        {
            public int Id { get; set; }
            public int EvaluationId { get; set; }
            public short ResponsibleId { get; set; }
        }

        public class SignOffReviewer : EditorModel
        {
            public int Id { get; set; }
            public int SignOffId { get; set; }
            public short EmployeeId { get; set; }
        }
    }

My view

 $('#tblToDo').on('click', 'tbody tr:not(.noteditable) td.editableblue', function (e) {
            console.log('SignOffReviewer.Id:' + editor.field('SignOffReviewer.Id').val());
            console.log('SignOffReviewer.EmployeeId:' + editor.field('SignOffReviewer.EmployeeId').val());
            console.log('SignOff.ResponsibleId:' + editor.field('SignOff.ResponsibleId').val());
            
            editor.field('SignOffReviewer.EmployeeId').val(editor.field('SignOff.ResponsibleId').val());
            console.log('New SignOffReviewer.EmployeeId:' + editor.field('SignOffReviewer.EmployeeId').val());

            console.log(this);

            editor.inline(this);/*, {
                onBlur: 'submit'
            });*/
        });

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    You need to include the id of the joined table in the data submitted to the server. You've already correctly got it being read, but if you haven't already you'll need to include SignOffReviewer.Id in the Editor form on the client-side (probably as a hidden field type).

    You'll also need to use:

    editor.inline(this, {
      submit: 'allIfChanged'
    } );
    

    to have Editor submit all of the data from the client-side, not just that which has changed value. The form-options documentation has more details about this.

    Allan

  • MundaringMundaring Posts: 34Questions: 12Answers: 1

    Hi Allan, Sorry for my late answer I already tried allIfChanged but I was getting some other errors asking for other fields. I finally solved calling ajax to execute the uodate in the other table.

This discussion has been closed.