public void Add(string values)
        {
            var newSubdomain = new Subdomain();
            JsonConvert.PopulateObject(values, newSubdomain);
           
            _subdomainUnitOfWork.SubdomainRepository.Add(newSubdomain);
            _subdomainUnitOfWork.Complete();


            var globalRoles = _subdomainUnitOfWork.RoleRepository.getGlobalRoles();
            if (!globalRoles.Any())
            {
                var role = new Role();
                role.RoleName = "Admin";
                role.IsGlobal = true;
                _subdomainUnitOfWork.RoleRepository.Add(role);
                _subdomainUnitOfWork.Complete();
            }

       

        }
Beispiel #2
0
        public async Task <bool> Add(string values)
        {
            var newSubdomainVersionBModel = new SubdomainVersionBusinessModel();

            JsonConvert.PopulateObject(values, newSubdomainVersionBModel);

            var subdomainVersionModel = _mapper.Map <SubdomainVersion>(newSubdomainVersionBModel);

            if (subdomainVersionModel.SourceVersionId != null)
            {
                var sourceId = (int)subdomainVersionModel.SourceVersionId;
                var sourceSubdomainVersion =
                    _subdomainUnitOfWork.SubdomainVersionRepository.GetVersionWithReferencesById(sourceId);
                if (sourceSubdomainVersion.EditLock)
                {
                    return(false);
                }
                else
                {
                    sourceSubdomainVersion.EditLock = true;

                    if (subdomainVersionModel.DexmoVersion == null)
                    {
                        if (sourceSubdomainVersion.DexmoVersion != null)
                        {
                            subdomainVersionModel.DexmoVersion = sourceSubdomainVersion.DexmoVersion;
                        }
                    }

                    foreach (var sourceReference in sourceSubdomainVersion.ReferencedSubdomainVersions)
                    {
                        var newReference = new SubdomainVersionReference();
                        newReference.SubdomainVersion    = subdomainVersionModel;
                        newReference.ReferencedVersionId = sourceReference.ReferencedVersionId;
                        subdomainVersionModel.ReferencedSubdomainVersions.Add(newReference);
                    }

                    var sourceSubdomainVersionRoles = _subdomainUnitOfWork.SubdomainVersionRoleRepository.GetAllVersionRolesBySubdomainVersionId(sourceId);

                    foreach (var sourceSubVersionRole in sourceSubdomainVersionRoles)
                    {
                        var newSubdomainVersionRole = new SubdomainVersionRole();
                        newSubdomainVersionRole.SubdomainVersion = subdomainVersionModel;
                        newSubdomainVersionRole.RoleId           = sourceSubVersionRole.RoleId;
                        _subdomainUnitOfWork.SubdomainVersionRoleRepository.Add(newSubdomainVersionRole);
                    }
                }
            }

            if (newSubdomainVersionBModel.ReferencedVersionIds != null)
            {
                foreach (var referenceId in newSubdomainVersionBModel.ReferencedVersionIds)
                {
                    var newReference = new SubdomainVersionReference();
                    newReference.SubdomainVersion    = subdomainVersionModel;
                    newReference.ReferencedVersionId = referenceId;
                    subdomainVersionModel.ReferencedSubdomainVersions.Add(newReference);
                }
            }


            _subdomainUnitOfWork.SubdomainVersionRepository.Add(subdomainVersionModel);
            _subdomainUnitOfWork.Complete();

            if (subdomainVersionModel.SourceVersionId != null)
            {
                CloneSourceVersionToNewVersion(subdomainVersionModel);
            }

            return(true);
        }