예제 #1
0
        public async Task <IActionResult> UpdateFlexFieldObject(string id, [FromBody] T flexFieldObject)
        {
            CheckXssForObject(flexFieldObject);

            T loadedFlexFieldObject = await _objectDbAccess.GetFlexFieldObjectById(id);

            List <string> oldTags = loadedFlexFieldObject.Tags;

            if (oldTags == null)
            {
                oldTags = new List <string>();
            }
            if (flexFieldObject.Tags == null)
            {
                flexFieldObject.Tags = new List <string>();
            }

            if (FlexFieldApiUtil.HasDuplicateFieldNames(flexFieldObject.Fields))
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["DuplicateFieldNameExist"]));
            }

            FlexFieldApiUtil.SetFieldIdsForNewFields(flexFieldObject.Fields);
            FlexFieldApiUtil.SetFieldIdsForNewFieldsInFolders(flexFieldObject.Fields);

            bool nameChanged = loadedFlexFieldObject.Name != flexFieldObject.Name;

            loadedFlexFieldObject.Name   = flexFieldObject.Name;
            loadedFlexFieldObject.Fields = flexFieldObject.Fields;
            loadedFlexFieldObject.Tags   = flexFieldObject.Tags;

            loadedFlexFieldObject = await RunAdditionalUpdates(flexFieldObject, loadedFlexFieldObject);

            await this.SetModifiedData(_userManager, loadedFlexFieldObject);

            await SetNotImplementedFlagOnChange(loadedFlexFieldObject);

            await _objectDbAccess.UpdateFlexFieldObject(loadedFlexFieldObject);

            _logger.LogInformation("Flex field object was updated.");

            await AddNewTags(flexFieldObject.Tags.Except(oldTags, StringComparer.OrdinalIgnoreCase).ToList());
            await RemoveUnusedTags(oldTags.Except(flexFieldObject.Tags, StringComparer.OrdinalIgnoreCase).ToList());

            _logger.LogInformation("Tags were updated.");

            if (nameChanged)
            {
                await RunMarkerUpdates(loadedFlexFieldObject);
            }

            await _timelineService.AddTimelineEntry(ObjectUpdatedEvent, loadedFlexFieldObject.Name, loadedFlexFieldObject.Id);

            return(Ok(loadedFlexFieldObject));
        }
예제 #2
0
        public async Task <IActionResult> CreateFlexFieldObject([FromBody] T flexFieldObject)
        {
            if (string.IsNullOrEmpty(flexFieldObject.Name))
            {
                return(StatusCode((int)HttpStatusCode.BadRequest));
            }

            CheckXssForObject(flexFieldObject);

            if (FlexFieldApiUtil.HasDuplicateFieldNames(flexFieldObject.Fields))
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, _localizer["DuplicateFieldNameExist"]));
            }

            FlexFieldApiUtil.SetFieldIdsForNewFields(flexFieldObject.Fields);
            FlexFieldApiUtil.SetFieldIdsForNewFieldsInFolders(flexFieldObject.Fields);

            if (flexFieldObject.Tags == null)
            {
                flexFieldObject.Tags = new List <string>();
            }

            try
            {
                GoNorthProject project = await _projectDbAccess.GetDefaultProject();

                flexFieldObject.ProjectId = project.Id;

                flexFieldObject = await RunAdditionalUpdates(flexFieldObject, flexFieldObject);

                await this.SetModifiedData(_userManager, flexFieldObject);

                flexFieldObject = await _objectDbAccess.CreateFlexFieldObject(flexFieldObject);
                await AddNewTags(flexFieldObject.Tags);

                await _timelineService.AddTimelineEntry(ObjectCreatedEvent, flexFieldObject.Name, flexFieldObject.Id);

                return(Ok(flexFieldObject));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Could not create flex field object {0}", flexFieldObject.Name);
                return(StatusCode((int)HttpStatusCode.InternalServerError));
            }
        }
예제 #3
0
        /// <summary>
        /// Copies the valid quest properties to a target quest
        /// </summary>
        /// <param name="targetQuest">Target quest to copy to</param>
        /// <param name="sourceQuest">Source quest to copy from</param>
        private void CopyValidQuestProperties(AikaQuest targetQuest, AikaQuest sourceQuest)
        {
            targetQuest.Name        = sourceQuest.Name;
            targetQuest.Description = sourceQuest.Description;
            targetQuest.IsMainQuest = sourceQuest.IsMainQuest;

            targetQuest.Fields = sourceQuest.Fields;

            FlexFieldApiUtil.SetFieldIdsForNewFields(targetQuest.Fields);
            FlexFieldApiUtil.SetFieldIdsForNewFieldsInFolders(targetQuest.Fields);

            targetQuest.Start     = GetStartNodeList(sourceQuest.Start);
            targetQuest.Text      = sourceQuest.Text != null ? sourceQuest.Text : new List <TextNode>();
            targetQuest.Finish    = sourceQuest.Finish != null ? sourceQuest.Finish : new List <AikaFinish>();
            targetQuest.Condition = sourceQuest.Condition != null ? sourceQuest.Condition : new List <ConditionNode>();
            targetQuest.Action    = sourceQuest.Action != null ? sourceQuest.Action : new List <ActionNode>();
            targetQuest.AllDone   = sourceQuest.AllDone != null ? sourceQuest.AllDone : new List <AikaAllDone>();
            targetQuest.Link      = sourceQuest.Link != null ? sourceQuest.Link : new List <NodeLink>();
        }
예제 #4
0
        /// <summary>
        /// Distributes the fields of a template
        /// </summary>
        /// <param name="id">Template Id</param>
        /// <returns>Task</returns>
        protected async Task <IActionResult> BaseDistributeFlexFieldTemplateFields(string id)
        {
            T template = await _templateDbAccess.GetFlexFieldObjectById(id);

            if (template == null)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest));
            }

            List <T> flexFieldObjects = await _objectDbAccess.GetFlexFieldObjectsByTemplate(id);

            foreach (T curObject in flexFieldObjects)
            {
                // Update Additional Configuration
                foreach (FlexField curField in curObject.Fields)
                {
                    FlexField templateField = template.Fields.FirstOrDefault(f => f.Name == curField.Name);
                    if (templateField != null && templateField.AdditionalConfiguration != curField.AdditionalConfiguration)
                    {
                        curField.AdditionalConfiguration = templateField.AdditionalConfiguration;
                    }
                }

                // Add new Fields
                List <FlexField> newFields = template.Fields.Where(f => !curObject.Fields.Any(nf => nf.Name == f.Name)).ToList();
                newFields.ForEach(f => f.CreatedFromTemplate = true);
                if (newFields.Count > 0)
                {
                    curObject.IsImplemented = false;
                }
                curObject.Fields.AddRange(newFields);

                FlexFieldApiUtil.SetFieldIdsForNewFields(curObject.Fields);
                FlexFieldApiUtil.SetFieldIdsForNewFieldsInFolders(curObject.Fields, template);

                await _objectDbAccess.UpdateFlexFieldObject(curObject);
            }

            await _timelineService.AddTimelineEntry(TemplateFieldsDistributedEvent, template.Name, template.Id);

            return(Ok(id));
        }