/// <summary> /// return whether or not the specified named group is already a child of this group /// </summary> /// <param name="childname"></param> /// <returns></returns> public AssetGroup IsChildGroup(string childname) { // First get a list of our current children LocationsDAO lwDataAccess = new LocationsDAO(); AssetGroupList listChildren = new AssetGroupList(lwDataAccess.GetGroups(this), _groupType); return(listChildren.FindGroup(childname)); }
/// <summary> /// Delete the current location from the database /// </summary> public bool Delete() { LocationsDAO lwDataAccess = new LocationsDAO(); // As locations are hierarchical we cannot just delete a location without first deleting ALL // children and we cannot do that if any of our descendants are still being referenced // Get a list of all of our children AssetGroupList children = new AssetGroupList(lwDataAccess.GetGroups(this), GroupType); // Loop through each child and try and delete them first before we delete ourselves - this actually // causes recursion through this deletion function as children may have children and so on... foreach (AssetGroup childGroup in children) { if (!childGroup.Delete()) { return(false); } } // Only now can we delete ourselves as all of our children have been handled. if (lwDataAccess.GroupDelete(this) != 0) { return(false); } // ...and audit the deletion AuditTrailEntry ate = new AuditTrailEntry(); ate.Date = DateTime.Now; ate.Class = AuditTrailEntry.CLASS.location; ate.Type = AuditTrailEntry.TYPE.deleted; ate.Key = _name; ate.AssetID = 0; ate.AssetName = ""; ate.Username = System.Environment.UserName; new AuditTrailDAO().AuditTrailAdd(ate); return(true); }