示例#1
0
        private async Task CreateTopicAsync()
        {
            try
            {
                Console.Write("Enter a topic name: ");
                var topicName = Console.ReadLine();

                Console.Write("Enter attribute name: ");
                var attributeName = Console.ReadLine();

                Console.Write("Enter attribute value: ");
                var attributeValue = Console.ReadLine();

                await _topicService.CreateTopicAsync(
                    topicName,
                    new Dictionary <string, string>()
                {
                    { attributeName, attributeValue }
                });
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ErrorForegroundColor;
                Console.WriteLine(e);
                Console.ForegroundColor = ForegroundColor;
            }
        }
        public async Task <ActionResult <ResponseTopicDto> > CreateTopicAsync(Guid boardId, [FromBody] RequestTopicDto topic, [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!MediaTypeHeaderValue.TryParse(mediaType, out MediaTypeHeaderValue parsedMediaType))
            {
                return(BadRequest());
            }

            var topicDto = await _topicService.CreateTopicAsync(boardId, topic);

            if (topicDto == null)
            {
                return(NotFound());
            }

            var includeLinks = parsedMediaType.SubTypeWithoutSuffix.EndsWith("hateoas", StringComparison.InvariantCultureIgnoreCase);

            if (includeLinks)
            {
                IEnumerable <LinkDto> links = new List <LinkDto>();
                links = CreateTopicLinks(topicDto.BoardId, topicDto.Id);
                var topicWithLinks = _mapper.Map <ResponseTopicLinksDto>(topicDto);
                topicWithLinks.Links = links;

                return(Ok(topicWithLinks));
            }

            return(CreatedAtRoute("GetTopic", new { boardId = topicDto.BoardId, topicId = topicDto.Id }, topicDto));
        }
示例#3
0
        private async Task CreateTopicAsync()
        {
            try
            {
                Console.Write("Enter a topic name: ");
                var topicName = Console.ReadLine() ?? string.Empty;

                Console.Write("Enter attribute name: ");
                var attributeName = Console.ReadLine() ?? string.Empty;

                Console.Write("Enter attribute value: ");
                var attributeValue = Console.ReadLine() ?? string.Empty;

                var attributes = string.IsNullOrWhiteSpace(attributeName) || string.IsNullOrWhiteSpace(attributeValue)
                    ? null
                    : new Dictionary <string, string>()
                {
                    { attributeName, attributeValue }
                };

                var topicArn = await _topicService.CreateTopicAsync(topicName, attributes);

                Console.WriteLine($"\nTopicARN: {topicArn}");
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ErrorForegroundColor;
                Console.WriteLine(e);
                Console.ForegroundColor = ForegroundColor;
            }
        }
示例#4
0
        public async Task CreateTopicAsync_AddsItemToDatabase()
        {
            var numberOfItemsInDatabase = await _context.Topics.CountAsync();

            await _service.CreateTopicAsync(new TopicDto()
            {
                Id          = 10, Name = "TopicNameTest01", Questions = new List <QuestionDto>(), SubjectId = 1,
                SubjectName = "SubjName"
            });

            _context.Topics.CountAsync().Result.Should().Be(numberOfItemsInDatabase + 1);
        }
        public async Task <IActionResult> Create(TopicDto topicDto)
        {
            if (ModelState.IsValid)
            {
                await _topicService.CreateTopicAsync(topicDto);

                return(RedirectToAction(nameof(Index)));
            }

            var subjects = await _subjectService.GetAllSubjectsAsync();

            ViewData["SubjectId"] = new SelectList(subjects, "Id", "Name", topicDto.SubjectId);
            return(View(topicDto));
        }