public void AddNodeOrganizationLoactionWarehouse(ref OperationResult pobjOperationResult, NodeOrganizationLoactionWarehouseList pobjNodeOrgLocationWarehouse, List <nodeorganizationlocationwarehouseprofileDto> pobjWarehouseList, List <string> ClientSession) { //mon.IsActive = true; nodeorganizationprofile objNodeorganizationprofile = new nodeorganizationprofile(); nodeorganizationlocationprofile objNodeorganizationlocationprofile = new nodeorganizationlocationprofile(); try { SigesoftEntitiesModel dbContext = new SigesoftEntitiesModel(); OperationResult objOperationResult5 = new OperationResult(); if (pobjWarehouseList != null) { if (IsWarehouseAssignedToNode(ref objOperationResult5, pobjWarehouseList)) { pobjOperationResult = objOperationResult5; return; } } var objEntitySource = (from a in dbContext.nodeorganizationlocationprofile join c in dbContext.nodeorganizationlocationprofile on a.i_NodeId equals c.i_NodeId where a.i_NodeId == pobjNodeOrgLocationWarehouse.i_NodeId && a.v_OrganizationId == pobjNodeOrgLocationWarehouse.v_OrganizationId && c.v_LocationId == pobjNodeOrgLocationWarehouse.v_LocationId select a).FirstOrDefault(); if (objEntitySource != null) { // Actualizar registro (dar de alta al registro ya existente "no volver a insertar") OperationResult objOperationResult2 = new OperationResult(); UpdateNodeOrganizationChangeStatusAll(ref objOperationResult2, pobjNodeOrgLocationWarehouse.i_NodeId, pobjNodeOrgLocationWarehouse.v_OrganizationId, pobjNodeOrgLocationWarehouse.v_LocationId, 0, ClientSession); pobjOperationResult = objOperationResult2; } else { var query = (from a in dbContext.nodeorganizationlocationprofile where a.i_NodeId == pobjNodeOrgLocationWarehouse.i_NodeId && a.v_OrganizationId == pobjNodeOrgLocationWarehouse.v_OrganizationId select a).FirstOrDefault(); // Grabar nuevo if (query == null) { #region Nodeorganization // Grabar nodo / empresa objNodeorganizationprofile.d_InsertDate = DateTime.Now; objNodeorganizationprofile.i_InsertUserId = Int32.Parse(ClientSession[2]); objNodeorganizationprofile.i_IsDeleted = 0; objNodeorganizationprofile.i_NodeId = pobjNodeOrgLocationWarehouse.i_NodeId; objNodeorganizationprofile.v_OrganizationId = pobjNodeOrgLocationWarehouse.v_OrganizationId; dbContext.AddTonodeorganizationprofile(objNodeorganizationprofile); dbContext.SaveChanges(); #endregion #region Nodeorganizationlocation // Grabar nodo / empresa / sede objNodeorganizationlocationprofile.d_InsertDate = DateTime.Now; objNodeorganizationlocationprofile.i_InsertUserId = Int32.Parse(ClientSession[2]); objNodeorganizationlocationprofile.i_IsDeleted = 0; objNodeorganizationlocationprofile.i_NodeId = pobjNodeOrgLocationWarehouse.i_NodeId; objNodeorganizationlocationprofile.v_OrganizationId = pobjNodeOrgLocationWarehouse.v_OrganizationId; objNodeorganizationlocationprofile.v_LocationId = pobjNodeOrgLocationWarehouse.v_LocationId; dbContext.AddTonodeorganizationlocationprofile(objNodeorganizationlocationprofile); dbContext.SaveChanges(); #endregion #region Add Warehouse // Graba almacenes OperationResult objOperationResult1 = new OperationResult(); if (pobjWarehouseList != null) { AddWarehouse(ref objOperationResult1, pobjWarehouseList, ClientSession); } #endregion } else { #region Nodeorganizationlocation // Grabar nodo / empresa / sede objNodeorganizationlocationprofile.d_InsertDate = DateTime.Now; objNodeorganizationlocationprofile.i_InsertUserId = Int32.Parse(ClientSession[2]); objNodeorganizationlocationprofile.i_IsDeleted = 0; objNodeorganizationlocationprofile.i_NodeId = pobjNodeOrgLocationWarehouse.i_NodeId; objNodeorganizationlocationprofile.v_OrganizationId = pobjNodeOrgLocationWarehouse.v_OrganizationId; objNodeorganizationlocationprofile.v_LocationId = pobjNodeOrgLocationWarehouse.v_LocationId; dbContext.AddTonodeorganizationlocationprofile(objNodeorganizationlocationprofile); dbContext.SaveChanges(); #endregion #region Add Warehouse // Graba almacenes OperationResult objOperationResult1 = new OperationResult(); if (pobjWarehouseList != null) { AddWarehouse(ref objOperationResult1, pobjWarehouseList, ClientSession); } #endregion } } pobjOperationResult.Success = 1; // Llenar entidad Log LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.CREACION, "EMPRESA / SEDE / ALMACÉN", "v_OrganizationId=" + objNodeorganizationprofile.v_OrganizationId, Success.Ok, null); } catch (Exception ex) { pobjOperationResult.Success = 0; pobjOperationResult.ExceptionMessage = Common.Utils.ExceptionFormatter(ex); // Llenar entidad Log LogBL.SaveLog(ClientSession[0], ClientSession[1], ClientSession[2], LogEventType.CREACION, "EMPRESA / SEDE / ALMACÉN", "v_OrganizationId=" + objNodeorganizationprofile.v_OrganizationId, Success.Failed, pobjOperationResult.ExceptionMessage); } }