public void Add(string values)
        {
            var newResponsibilityModel = new ResponsibilityBusinessModel();

            JsonConvert.PopulateObject(values, newResponsibilityModel);
            if (newResponsibilityModel.ResponsibilityDefinition != null)
            {
                var newResponsibility = new Responsibility();
                newResponsibility.ResponsibilityDefinition = newResponsibilityModel.ResponsibilityDefinition;
                newResponsibility.IsMandatory   = newResponsibilityModel.IsMandatory;
                newResponsibility.Title         = newResponsibilityModel.Title;
                newResponsibility.PriorityOrder = newResponsibilityModel.PriorityOrder;
                _drcUnitOfWork.ResponsibilityRepository.Add(newResponsibility);


                var drcCardResponsibility = new DrcCardResponsibility();
                drcCardResponsibility.Responsibility = newResponsibility;
                drcCardResponsibility.DrcCard        = _drcUnitOfWork.DrcCardRepository.GetById(newResponsibilityModel.DrcCardId);
                _drcUnitOfWork.DrcCardResponsibilityRepository.Add(drcCardResponsibility);

                DrcCardResponsibility drcCardResponsibilityWithShadow;
                if (newResponsibilityModel.ShadowCardIds != null)
                {
                    foreach (var collaborationCardId in newResponsibilityModel.ShadowCardIds)
                    {
                        drcCardResponsibilityWithShadow = new DrcCardResponsibility();
                        drcCardResponsibilityWithShadow.Responsibility          = newResponsibility;
                        drcCardResponsibilityWithShadow.DrcCard                 = _drcUnitOfWork.DrcCardRepository.GetById(collaborationCardId);
                        drcCardResponsibilityWithShadow.IsRelationCollaboration = true;
                        _drcUnitOfWork.DrcCardResponsibilityRepository.Add(drcCardResponsibilityWithShadow);
                        _drcUnitOfWork.Complete();
                    }
                }

                _drcUnitOfWork.Complete();
            }
            else
            {
                //do nothing
            }
        }
Ejemplo n.º 2
0
        private IEnumerable <PropertyDeclarationSyntax> documentPropertiesWithAllAttributes(IEnumerable <Field> drcCardFields)
        {
            List <PropertyDeclarationSyntax> properties = new List <PropertyDeclarationSyntax>();


            foreach (var field in drcCardFields)
            {
                if (!field.AttributeName.Contains("."))
                {
                    if (field.Type == FieldType.ComplexTypeElement || field.Type == FieldType.DetailElement ||
                        field.Type == FieldType.DynamicField || field.Type == FieldType.Enum)
                    {
                        var fieldbase = _documentGenerator.generateDocumentDexmoPropertiesDeclarationWithAttributes(field);

                        properties.Add(fieldbase);
                    }
                    else if (field.Type == FieldType.RelationElement)
                    {
                        var mainProperty = _documentGenerator.generateDocumentRelationPropertyDeclarationWithAttributes(field);
                        //this is string key of relation element
                        properties.Add(mainProperty);

                        //there is a bridge table for relation documents
                        var documentFieldRelation = _drcUnitOfWork.DrcCardFieldRepository.GetFieldCollaborationByFieldId(field.Id);
                        if (documentFieldRelation != null)
                        {
                            var relatedDocumentName          = _drcUnitOfWork.DrcCardRepository.getDrcCardName(documentFieldRelation.DrcCardId);
                            var camelCaseRelatedDocumentName = camelCaseDocumentName(relatedDocumentName);

                            var relationKey = _documentGenerator.generateDocumentRelationForeignKeyPropertyDeclaration(field, camelCaseRelatedDocumentName);

                            properties.Add(relationKey);
                        }
                    }
                    else
                    {
                        var fieldbase = _documentGenerator.generateDocumentPropertiesDeclarationWithAttributes(field);
                        properties.Add(fieldbase);
                    }
                }
            }

            _drcUnitOfWork.Complete();
            return(properties);
        }
        public void Add(DrcCardBusinessModel businessModeldrcCard)
        {
            var drcCard = _mapper.Map <DrcCard>(businessModeldrcCard);

            drcCard.DrcCardName = "New Document";

            string[] commanRoleBag = new[] { "Create", "Read", "Update", "Delete" };
            for (int i = 0; i < commanRoleBag.Length; i++)
            {
                var authorization = new Authorization();
                authorization.DrcCard       = drcCard;
                authorization.OperationName = commanRoleBag[i];
                _drcUnitOfWork.AuthorizationRepository.Add(authorization);
            }

            _drcUnitOfWork.DrcCardRepository.Add(drcCard);
            _drcUnitOfWork.Complete();
        }
Ejemplo n.º 4
0
        public void CloneSourceVersionToNewVersion(SubdomainVersion subdomainVersion)
        {
            var sourceId = (int)subdomainVersion.SourceVersionId;

            var sourceVersionCards = _drcUnitOfWork.DrcCardRepository.getAllCardsBySubdomainVersion(sourceId);


            IList <SourceNewDrcCardMap> sourceNewDrcCardMaps = new List <SourceNewDrcCardMap>();

            foreach (var sourceVersionCard in sourceVersionCards)
            {
                SourceNewDrcCardMap sourceNewDrcCardMap = new SourceNewDrcCardMap();
                sourceNewDrcCardMap.SourceCardId = sourceVersionCard.Id;

                DrcCard newDrcCard = new DrcCard();
                newDrcCard    = sourceVersionCard;
                newDrcCard.Id = 0;
                newDrcCard.SubdomainVersionId = 0;
                newDrcCard.SubdomainVersion   = subdomainVersion;
                _drcUnitOfWork.DrcCardRepository.Add(newDrcCard);
                _drcUnitOfWork.Complete();
                sourceNewDrcCardMap.NewCardId = newDrcCard.Id;
                sourceNewDrcCardMaps.Add(sourceNewDrcCardMap);
            }

            foreach (var sourceNewDrcCardMap in sourceNewDrcCardMaps)
            {
                var newDrcCard = _drcUnitOfWork.DrcCardRepository.GetById(sourceNewDrcCardMap.NewCardId);
                var sourceCardResponsibilities =
                    _drcUnitOfWork.DrcCardResponsibilityRepository.GetDrcCardResponsibilitiesByDrcCardId(
                        sourceNewDrcCardMap.SourceCardId);

                foreach (var sourceDrcCardResponsibility in sourceCardResponsibilities)
                {
                    Responsibility newResponsibility = new Responsibility();
                    newResponsibility =
                        _drcUnitOfWork.ResponsibilityRepository.GetByIdWithoutTracking(sourceDrcCardResponsibility
                                                                                       .ResponsibilityId);
                    var sourceResponsibilityCollaborations = _drcUnitOfWork.DrcCardResponsibilityRepository.GetResponsibilityCollaborationsByResponsibilityId(newResponsibility.Id);
                    newResponsibility.Id = 0;
                    _drcUnitOfWork.ResponsibilityRepository.Add(newResponsibility);

                    DrcCardResponsibility newDrcCardResponsibility = new DrcCardResponsibility();
                    newDrcCardResponsibility.DrcCard                 = newDrcCard;
                    newDrcCardResponsibility.Responsibility          = newResponsibility;
                    newDrcCardResponsibility.IsRelationCollaboration = false;
                    _drcUnitOfWork.DrcCardResponsibilityRepository.Add(newDrcCardResponsibility);

                    foreach (var sourceResponsibilityCollaboration in sourceResponsibilityCollaborations)
                    {
                        int newDrcCardId = sourceNewDrcCardMaps
                                           .Where(c => c.SourceCardId == sourceResponsibilityCollaboration.DrcCardId)
                                           .Select(c => c.NewCardId).Single();
                        DrcCardResponsibility newResponsibilityCollaboration = new DrcCardResponsibility();
                        newResponsibilityCollaboration.DrcCardId               = newDrcCardId;
                        newResponsibilityCollaboration.Responsibility          = newResponsibility;
                        newResponsibilityCollaboration.IsRelationCollaboration =
                            sourceResponsibilityCollaboration.IsRelationCollaboration;
                        _drcUnitOfWork.DrcCardResponsibilityRepository.Add(newResponsibilityCollaboration);
                        _drcUnitOfWork.Complete();
                    }
                    _drcUnitOfWork.Complete();
                }

                var sourceCardFields = _drcUnitOfWork.DrcCardFieldRepository
                                       .GetDrcCardFieldsByDrcCardId(sourceNewDrcCardMap.SourceCardId);

                foreach (var sourceCardField in sourceCardFields)
                {
                    Field newField = new Field();
                    newField = _drcUnitOfWork.FieldRepository.GetByIdWithoutTracking(sourceCardField.FieldId);
                    var sourceFieldCollaboration =
                        _drcUnitOfWork.DrcCardFieldRepository.GetFieldCollaborationByFieldId(newField.Id);
                    newField.Id = 0;
                    _drcUnitOfWork.FieldRepository.Add(newField);

                    DrcCardField newDrcCardField = new DrcCardField();
                    newDrcCardField.DrcCard = newDrcCard;
                    newDrcCardField.Field   = newField;
                    newDrcCardField.IsRelationCollaboration = false;
                    _drcUnitOfWork.DrcCardFieldRepository.Add(newDrcCardField);

                    if (sourceFieldCollaboration != null)
                    {
                        int newCollaborationDrcCardId = sourceNewDrcCardMaps
                                                        .Where(c => c.SourceCardId == sourceFieldCollaboration.DrcCardId)
                                                        .Select(c => c.NewCardId).Single();

                        DrcCardField newDrcCardFieldCollaboration = new DrcCardField();
                        newDrcCardFieldCollaboration.DrcCardId = newCollaborationDrcCardId;
                        newDrcCardFieldCollaboration.Field     = newField;
                        newDrcCardFieldCollaboration.IsRelationCollaboration = true;
                        _drcUnitOfWork.DrcCardFieldRepository.Add(newDrcCardFieldCollaboration);
                        _drcUnitOfWork.Complete();
                    }
                    _drcUnitOfWork.Complete();
                }

                var sourceCardAuthorizations = _drcUnitOfWork.AuthorizationRepository.GetAuthorizationsByDrcCardId(sourceNewDrcCardMap.SourceCardId);

                foreach (var sourceCardAuthorization in sourceCardAuthorizations)
                {
                    Authorization newAuthorization = new Authorization();
                    newAuthorization = _drcUnitOfWork.AuthorizationRepository.GetByIdWithoutTracking(sourceCardAuthorization.Id);
                    var oldAuthorizationRoles = _drcUnitOfWork.AuthorizationRoleRepository.GetAuthorizationRolesByAuthorizationId(newAuthorization.Id);
                    newAuthorization.Id        = 0;
                    newAuthorization.DrcCardId = 0;
                    newAuthorization.DrcCard   = newDrcCard;
                    _drcUnitOfWork.AuthorizationRepository.Add(newAuthorization);

                    foreach (var oldAuthorizationRole in oldAuthorizationRoles)
                    {
                        AuthorizationRole authorizationRole = new AuthorizationRole();
                        authorizationRole.AuthorizationId = newAuthorization.Id;
                        authorizationRole.RoleId          = oldAuthorizationRole.RoleId;
                        _drcUnitOfWork.AuthorizationRoleRepository.Add(authorizationRole);
                        _drcUnitOfWork.Complete();
                    }
                }
                _drcUnitOfWork.Complete();
            }
        }
        public void Add(string values)
        {
            var newFieldBusinessModel = new FieldBusinessModel();

            JsonConvert.PopulateObject(values, newFieldBusinessModel);


            Field field = _mapper.Map <Field>(newFieldBusinessModel);

            switch (field.Type)
            {
            case FieldType.String:
                field.Nullable        = false;
                field.MeasurementType = null;
                field.ItemName        = null;
                field.MaxValue        = null;
                field.MaxValue        = null;
                field.EnumValues      = null;
                newFieldBusinessModel.CollaborationId = null;
                _drcUnitOfWork.FieldRepository.Add(field);
                break;

            case FieldType.Integer:
            case FieldType.Byte:
            case FieldType.Double:
            case FieldType.Decimal:
            case FieldType.Long:
                field.CreditCard        = false;
                field.RegularExpression = null;
                field.MeasurementType   = null;
                field.ItemName          = null;
                field.MaxLength         = null;
                field.MinLength         = null;
                field.EnumValues        = null;
                newFieldBusinessModel.CollaborationId = null;
                _drcUnitOfWork.FieldRepository.Add(field);
                break;


            case FieldType.Bool:
                field.CreditCard        = false;
                field.Unique            = false;
                field.RegularExpression = null;
                field.MeasurementType   = null;
                field.ItemName          = null;
                field.MaxValue          = null;
                field.MaxValue          = null;
                field.MaxLength         = null;
                field.MinLength         = null;
                field.EnumValues        = null;
                newFieldBusinessModel.CollaborationId = null;
                _drcUnitOfWork.FieldRepository.Add(field);
                break;

            case FieldType.Enum:

                field.CreditCard        = false;
                field.RegularExpression = null;
                field.MeasurementType   = null;
                field.MaxValue          = null;
                field.MaxValue          = null;
                field.MaxLength         = null;
                field.MinLength         = null;
                newFieldBusinessModel.CollaborationId = null;
                _drcUnitOfWork.FieldRepository.Add(field);
                break;

            case FieldType.Time:
            case FieldType.DateTime:
            case FieldType.DateOnly:
                field.CreditCard        = false;
                field.RegularExpression = null;
                field.MeasurementType   = null;
                field.ItemName          = null;
                field.MaxValue          = null;
                field.MaxValue          = null;
                field.MaxLength         = null;
                field.MinLength         = null;
                field.EnumValues        = null;
                newFieldBusinessModel.CollaborationId = null;
                _drcUnitOfWork.FieldRepository.Add(field);
                break;

            case FieldType.RelationElement:
                field.Nullable          = false;
                field.CreditCard        = false;
                field.RegularExpression = null;
                field.MeasurementType   = null;
                field.ItemName          = null;
                field.MaxValue          = null;
                field.MaxValue          = null;
                field.MaxLength         = null;
                field.MinLength         = null;
                field.EnumValues        = null;
                field.DefaultValue      = null;
                _drcUnitOfWork.FieldRepository.Add(field);
                break;

            case FieldType.ComplexTypeElement:
            case FieldType.DynamicField:
            case FieldType.DetailElement:
                field.Nullable          = false;
                field.CreditCard        = false;
                field.Unique            = false;
                field.RegularExpression = null;
                field.MeasurementType   = null;
                field.MaxValue          = null;
                field.MaxValue          = null;
                field.MaxLength         = null;
                field.MinLength         = null;
                field.EnumValues        = null;
                field.DefaultValue      = null;
                newFieldBusinessModel.CollaborationId = null;
                _drcUnitOfWork.FieldRepository.Add(field);
                break;

            case FieldType.Measurement:
                field.CreditCard        = false;
                field.Unique            = false;
                field.RegularExpression = null;
                field.ItemName          = null;
                field.MaxValue          = null;
                field.MaxValue          = null;
                field.MaxLength         = null;
                field.MinLength         = null;
                field.EnumValues        = null;
                field.Nullable          = false;
                newFieldBusinessModel.CollaborationId = null;
                _drcUnitOfWork.FieldRepository.Add(field);
                break;
            }



            DrcCardField newDrcCardFieldCollaboration = new DrcCardField();

            newDrcCardFieldCollaboration.DrcCard = _drcUnitOfWork.DrcCardRepository.GetById(newFieldBusinessModel.DrcCardId);
            newDrcCardFieldCollaboration.Field   = field;
            _drcUnitOfWork.DrcCardFieldRepository.Add(newDrcCardFieldCollaboration);

            if (newFieldBusinessModel.CollaborationId != null)
            {
                DrcCardField newFieldCollaboration = new DrcCardField();
                newFieldCollaboration.DrcCardId = (int)newFieldBusinessModel.CollaborationId;
                newFieldCollaboration.FieldId   = field.Id;
                newFieldCollaboration.IsRelationCollaboration = true;
                _drcUnitOfWork.DrcCardFieldRepository.Add(newFieldCollaboration);
            }


            _drcUnitOfWork.Complete();
        }