public JsonResult SaveSentenseInDatabase(PCMPresentenceDetailsViewModel vm) { int Id = Convert.ToInt32(vm.Sentence_Id);// pass the right //get current username string loginName = User.Identity.Name; Session["LoginName"] = loginName; var currentUser = (User)Session["CurrentUser"]; var userProvince = -1; var userId = 0; if (currentUser != null) { userId = currentUser.User_Id; if (currentUser.Employees.Any()) { userProvince = currentUser.Employees.First().apl_Service_Office.apl_Local_Municipality.District.Province_Id; } if (currentUser.apl_Social_Worker.Any()) { userProvince = currentUser.apl_Social_Worker.First().apl_Service_Office.apl_Local_Municipality.District.Province_Id; } } var result = false; int caseid = Convert.ToInt32(Session["IntakeassId"]); PCMPresentenceModel Model = new PCMPresentenceModel(); try { if (vm.Sentence_Id > 0) { Model.UpdateSentenseDetails(vm, Id, userId); result = true; } else { Model.CreateSentenseDeatils(vm, caseid, userId); result = true; } } catch (Exception ex) { throw ex; } return(Json(result, JsonRequestBehavior.AllowGet)); }