Example #1
0
        public async Task <IActionResult> GetResourceDetails(string name, string type)
        {
            name = Instance.Sanitize(name);
            type = Instance.Sanitize(type);
            var resources = await topicsResourcesBusinessLogic.GetResourceDetailAsync(name, type);

            if (resources == null)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(Ok(resources));
        }
Example #2
0
        public async Task <object> CreateGuidedAssistantResource(string resourceTitle, CuratedTemplate curatedTemplate, string curatedExperienceId)
        {
            var resourceDetails = await topicsResourcesBusinessLogic.GetResourceDetailAsync(resourceTitle, Constants.GuidedAssistant);

            List <GuidedAssistant> resources = JsonUtilities.DeserializeDynamicObject <List <GuidedAssistant> >(resourceDetails);
            Int64 maxVersion = default(Int64);

            foreach (var resource in resources)
            {
                var resourceDetail = JsonUtilities.DeserializeDynamicObject <GuidedAssistant>(resource);
                if (resourceDetail.Version == default(Int64))
                {
                    resourceDetail.Version = IncrementVersion(default(Int64));
                }
                if (maxVersion.CompareTo(resourceDetail.Version) < 0)
                {
                    maxVersion = resourceDetail.Version;
                }
                resourceDetail.IsActive = false;

                await backendDatabaseService.UpdateItemAsync(resourceDetail.ResourceId.ToString(),
                                                             JObject.FromObject(resourceDetail), cosmosDbSettings.ResourcesCollectionId);
            }

            var topicDetails = await topicsResourcesBusinessLogic.GetTopicDetailsAsync(resourceTitle);

            List <Topic> topics = JsonUtilities.DeserializeDynamicObject <List <Topic> >(topicDetails);

            if (topics.Count > 0)
            {
                var             guidedAssistantResource = new GuidedAssistant();
                List <TopicTag> topicTags = new List <TopicTag>();
                List <Location> locations = new List <Location>();

                foreach (var topic in topics)
                {
                    topicTags.Add(new TopicTag {
                        TopicTags = topic.Id
                    });
                    foreach (var location in topic.Location)
                    {
                        locations.Add(location);
                    }
                }

                guidedAssistantResource.ResourceId          = Guid.NewGuid();
                guidedAssistantResource.Name                = curatedTemplate.Name;
                guidedAssistantResource.Description         = curatedTemplate.Description;
                guidedAssistantResource.TopicTags           = topicTags;
                guidedAssistantResource.Location            = locations;
                guidedAssistantResource.Version             = IncrementVersion(maxVersion);
                guidedAssistantResource.IsActive            = true;
                guidedAssistantResource.ResourceType        = Constants.GuidedAssistant;
                guidedAssistantResource.CuratedExperienceId = curatedExperienceId;

                await backendDatabaseService.CreateItemAsync(guidedAssistantResource, cosmosDbSettings.ResourcesCollectionId);

                return(adminSettings.SuccessMessage + " New Curated Experience ID " + curatedExperienceId);
            }
            return(string.Format(CultureInfo.InvariantCulture, adminSettings.MissingTopicMessage, resourceTitle));
        }