private VmArchiveResult CascadeDeleteOrganization(IUnitOfWorkWritable unitOfWork, Guid?id, bool checkDelete = false) { var psDeleted = typesCache.Get <PublishingStatusType>(PublishingStatus.Deleted.ToString()); var psOldPublished = typesCache.Get <PublishingStatusType>(PublishingStatus.OldPublished.ToString()); var organizationRep = unitOfWork.CreateRepository <IOrganizationVersionedRepository>(); var organizationUserMapRep = unitOfWork.CreateRepository <IUserOrganizationRepository>(); var userMaps = organizationUserMapRep.All(); var organizationIsUsed = organizationRep.All() .Where(x => x.Id == id) .Any( i => userMaps.Any(k => k.OrganizationId == i.UnificRootId)); if (organizationIsUsed) { throw new OrganizationNotDeleteInUserUseException(); } var organization = organizationRep.All().SingleOrDefault(x => x.Id == id); if (checkDelete) { var organizations = organizationRep.All().Where(x => x.Id == id); var result = new VmArchiveResult { Id = organization.Id, PublishingStatusId = organization.PublishingStatusId, ChannelsConnected = organizations.Any(i => i.UnificRoot.OrganizationServiceChannelsVersioned.Any(j => j.PublishingStatusId != psDeleted && j.PublishingStatusId != psOldPublished)), SubOrganizationsConnected = organizations.Any(i => i.UnificRoot.Children.Any(j => j.PublishingStatusId != psDeleted && j.PublishingStatusId != psOldPublished)), ServicesConnected = organizations.Any(i => i.UnificRoot.OrganizationServices.Any(j => j.ServiceVersioned.PublishingStatusId != psDeleted && j.ServiceVersioned.PublishingStatusId != psOldPublished)) || organizations.Any(i => i.UnificRoot.ServiceProducerOrganizations.Any(j => j.ServiceProducer.ServiceVersioned.PublishingStatusId != psDeleted && j.ServiceProducer.ServiceVersioned.PublishingStatusId != psOldPublished)) || organizations.Any(i => i.UnificRoot.OrganizationServicesVersioned.Any(j => j.PublishingStatusId != psDeleted && j.PublishingStatusId != psOldPublished)) }; if (result.AnyConnected) { return(result); } } else { CommonService.ChangeEntityToDeleted <OrganizationVersioned>(unitOfWork, organization.Id); ArchiveConnectedChannels(unitOfWork, organization.UnificRootId); ArchiveConnectedServices(unitOfWork, organization.UnificRootId); ArchiveSubOrganizations(unitOfWork, organization.UnificRootId); } return(new VmArchiveResult { Id = organization.Id, PublishingStatusId = organization.PublishingStatusId }); }
private ServiceVersioned DeleteService(IUnitOfWorkWritable unitOfWork, Guid?serviceId) { return(CommonService.ChangeEntityToDeleted <ServiceVersioned>(unitOfWork, serviceId.Value)); }