/// <summary> /// Сохранить евенты после сохранения формы /// </summary> /// <param name="package"></param> /// <returns></returns> public ResponseObjectPackage<SaveControlModel> SaveAllEvents(RequestObjectPackage<SaveControlModel> package) { // сохранить евенты if (package.requestData.events != null) { foreach (SaveEvent _event in package.requestData.events) { RequestObjectPackage<EventModel> requestEvent = new RequestObjectPackage<EventModel>() { requestData = new EventModel() { controlID = package.requestData.control.ID, eventTypeID = _event.eventTypeID } }; ResponsePackage respEvent = new DBUtils().RunSqlAction(EventsRepository.Save, requestEvent).GetSelfOrExceptionIfError(); _event.ID = respEvent.GetIdOrExceptionIfError(); if (_event.actions != null) { foreach (SaveAction action in _event.actions) { RequestObjectPackage<ActionModel> requestAction = new RequestObjectPackage<ActionModel>() { requestData = new ActionModel() { eventID = (int)_event.ID, orderNumber = action.orderNumber, actionTypeID = action.actionTypeID } }; ResponsePackage respAction = new DBUtils().RunSqlAction(ActionsRepository.Save, requestAction).GetSelfOrExceptionIfError(); action.ID = respAction.GetIdOrExceptionIfError(); if (action.parameters != null) { foreach (SaveActionParam param in action.parameters) { RequestObjectPackage<ActionParameterModel> requestParam = new RequestObjectPackage<ActionParameterModel>() { requestData = new ActionParameterModel() { actionID = (int)action.ID, actionParameterTypeID = param.actionInParamTypeID, controlID = (int)param.controlID } }; ResponsePackage respParam = new DBUtils().RunSqlAction(ActionParametersRepository.Save, requestParam).GetSelfOrExceptionIfError(); } } } } } } // рекурсия if (package.requestData.items != null) { foreach (SaveControlModel item in package.requestData.items) { RequestObjectPackage<SaveControlModel> propItem = new RequestObjectPackage<SaveControlModel>() { requestData = item }; ResponsePackage saveItemResponse = SaveAllEvents(propItem).GetSelfOrExceptionIfError(); } } return new ResponseObjectPackage<SaveControlModel>() { resultData = package.requestData }; }