예제 #1
0
        public CreateFieldDefinitionStatus AddReferenceField(int id, string name, bool required, int targetFieldDefinitionID)
        {
            FormDefinition form = Get(id);

            if (form == null)
            {
                return(CreateFieldDefinitionStatus.NoSuchFormDefinition);
            }

            if (String.IsNullOrEmpty(name))
            {
                return(CreateFieldDefinitionStatus.InvalidName);
            }

            FieldDefinition targetField = FieldRepository.Get(targetFieldDefinitionID);

            if (targetField == null)
            {
                return(CreateFieldDefinitionStatus.NoSuchTargetFieldDefinition);
            }

            FormDefinition targetForm = Get(targetField.FormDefinitionID);

            if (targetForm == null)
            {
                return(CreateFieldDefinitionStatus.NoSuchTargetFormDefinition);
            }

            if (!ProjectService.CanUserManage(form.ProjectID))
            {
                return(CreateFieldDefinitionStatus.PermissionDenied);
            }

            form.Fields.Add(new FieldDefinition
            {
                Name                    = name,
                PublicIdentifier        = HashHelper.ComputePublicIdentifier(typeof(FieldDefinition).Name, name),
                FieldType               = FieldType.ReferenceField,
                Required                = required,
                FormDefinitionID        = id,
                ReferenceFormID         = targetForm.ID,
                ReferenceDisplayFieldID = targetFieldDefinitionID
            });
            FormRepository.Update(form);
            ActivityService.FieldDefinitionCreated(form.Fields.Max(f => f.ID));
            return(CreateFieldDefinitionStatus.Created);
        }
예제 #2
0
        public CreateFormDefinitionStatus CreateForm(string name, int formType, bool publicContent, int projectID)
        {
            if (GetList(projectID).Count() == Validator.MaxUserProjects)
            {
                return(CreateFormDefinitionStatus.FormCountExceeded);
            }

            if (!Validator.CheckName(name))
            {
                return(CreateFormDefinitionStatus.InvalidName);
            }

            if (!Validator.CheckFormType(formType))
            {
                return(CreateFormDefinitionStatus.InvalidFormType);
            }

            Project project = ProjectService.Get(projectID);

            if (project == null)
            {
                return(CreateFormDefinitionStatus.NoSuchProject);
            }

            if (!ProjectService.CanUserManage(projectID))
            {
                return(CreateFormDefinitionStatus.PermissionDenied);
            }

            FormDefinition form = new FormDefinition
            {
                Name             = name,
                FormType         = formType,
                PublicContent    = publicContent,
                ProjectID        = projectID,
                PublicIdentifier = HashHelper.ComputePublicIdentifier(typeof(FormDefinition).Name, name),
                Created          = DateTime.Now
            };

            FormRepository.Insert(form);
            ActivityService.FormDefinitionCreated(form.ID);
            return(CreateFormDefinitionStatus.Created);
        }
예제 #3
0
        public UpdateProjectStatus UpdateProject(int id, string name, string description)
        {
            if (!Validator.CheckName(name))
            {
                return(UpdateProjectStatus.InvalidName);
            }

            Project project = Get(id);

            if (project == null)
            {
                return(UpdateProjectStatus.NoSuchProject);
            }

            project.Name        = name;
            project.Description = description;
            Repository.Update(project);
            ActivityService.ProjectUpdated(project.ID);
            return(UpdateProjectStatus.Updated);
        }
예제 #4
0
        public CreateProjectStatus CreateProject(string name, string description)
        {
            if (!Validator.CheckName(name))
            {
                return(CreateProjectStatus.InvalidName);
            }

            if (GetList().Count() == Validator.MaxUserProjects)
            {
                return(CreateProjectStatus.ProjectCountExceeded);
            }

            Project project = new Project
            {
                Name        = name,
                Description = description,
                OwnerUserID = UserContext.AccountID,
                Created     = DateTime.Now
            };

            Repository.Insert(project);
            ActivityService.ProjectCreated(project.ID);
            return(CreateProjectStatus.Created);
        }
예제 #5
0
        public CreateFieldDefinitionStatus AddField(int id, string name, int fieldType, bool required)
        {
            FormDefinition form = Get(id);

            if (form == null)
            {
                return(CreateFieldDefinitionStatus.NoSuchFormDefinition);
            }

            if (!Validator.CheckFieldType(fieldType, form.FormType) && fieldType != FieldType.ReferenceField)
            {
                return(CreateFieldDefinitionStatus.InvalidFieldType);
            }

            if (String.IsNullOrEmpty(name))
            {
                return(CreateFieldDefinitionStatus.InvalidName);
            }

            if (!ProjectService.CanUserManage(form.ProjectID))
            {
                return(CreateFieldDefinitionStatus.PermissionDenied);
            }

            form.Fields.Add(new FieldDefinition
            {
                Name             = name,
                PublicIdentifier = HashHelper.ComputePublicIdentifier(typeof(FieldDefinition).Name, name),
                FieldType        = fieldType,
                Required         = required,
                FormDefinitionID = id
            });
            FormRepository.Update(form);
            ActivityService.FieldDefinitionCreated(form.Fields.Max(f => f.ID));
            return(CreateFieldDefinitionStatus.Created);
        }