private void AddingOrUpdateStartNodes(IEntity entity, IEnumerable <UserStartNodeDto> current, UserStartNodeDto.StartNodeTypeValue startNodeType, int[] entityStartIds) { var assignedIds = current.Where(x => x.StartNodeType == (int)startNodeType).Select(x => x.StartNode).ToArray(); //remove the ones not assigned to the entity var toDelete = assignedIds.Except(entityStartIds).ToArray(); if (toDelete.Length > 0) { Database.Delete <UserStartNodeDto>("WHERE UserId = @UserId AND startNode IN (@startNodes)", new { UserId = entity.Id, startNodes = toDelete }); } //add the ones not currently in the db var toAdd = entityStartIds.Except(assignedIds).ToArray(); foreach (var i in toAdd) { var dto = new UserStartNodeDto { StartNode = i, StartNodeType = (int)startNodeType, UserId = entity.Id }; Database.Insert(dto); } }
private void AddOrUpdateStartNode(UserStartNodeDto startNode) { //this can be null since we are left joining if (startNode == null || startNode.Id == default(int)) { return; } //add the current (new) start node - this is a hashset so it will only allow unique rows so no need to check for existence _currentUser.UserStartNodeDtos.Add(startNode); }
internal UserDto Map(UserDto user, UserGroupDto group, UserGroup2AppDto section, UserStartNodeDto startNode) { // Terminating call. Since we can return null from this function // we need to be ready for PetaPoco to callback later with null // parameters if (user == null) { return(_currentUser); } // Is this the same User as the current one we're processing if (_currentUser != null && _currentUser.Id == user.Id) { AddOrUpdateGroup(group, section); AddOrUpdateStartNode(startNode); // Return null to indicate we're not done with this object yet return(null); } // This is a different user to the current one, or this is the // first time through and we don't have one yet // Save the current user var prev = _currentUser; // Setup the new current user _currentUser = user; _currentUser.UserGroupDtos = new List <UserGroupDto>(); _currentUser.UserStartNodeDtos = new HashSet <UserStartNodeDto>(); AddOrUpdateGroup(group, section); AddOrUpdateStartNode(startNode); // Return the now populated previous user (or null if first time through) return(prev); }