Пример #1
0
        public async Task AddAsyncTest()
        {
            var topic = new Topic
            {
                Name      = "C#",
                Questions = new List <Question>
                {
                    new Question
                    {
                        Text  = "add",
                        Price = 100
                    },
                    new Question
                    {
                        Text  = "add",
                        Price = 200
                    }
                }
            };
            var round = new Round
            {
                Name = "Add"
            };

            _db.Rounds.Add(round);
            _db.SaveChanges();

            var flag = await _topicService.AddAsync(round.Id, topic);

            await _topicService.RemoveAsync(topic.Id);

            _db.Rounds.Remove(round);

            Assert.IsTrue(flag);
        }
Пример #2
0
        public async Task <ActionResult> AddNewTopicAsync([FromBody] TopicModel topicModel)
        {
            try
            {
                topicModel.Id = await _topicService.AddAsync(topicModel, this.User);

                return(Created(new Uri($"{Request.Scheme}://{Request.Host}{Request.Path}{Request.QueryString}/{topicModel.Id}", UriKind.Absolute), topicModel));
            }
            catch (ForumException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Пример #3
0
        public async Task <IActionResult> Create([FromForm] TopicAddModel topicAddModel)
        {
            var uploadModel = await UploadFileAsync(topicAddModel.Image, "image/jpeg");

            if (uploadModel.UploadState == UploadState.Success)
            {
                topicAddModel.ImagePath = uploadModel.NewName;
                await _topicService.AddAsync(_mapper.Map <Topic>(topicAddModel));

                return(Created("", topicAddModel));
            }
            else if (uploadModel.UploadState == UploadState.NotExist)
            {
                await _topicService.AddAsync(_mapper.Map <Topic>(topicAddModel));

                return(Created("", topicAddModel));
            }
            else
            {
                return(BadRequest(uploadModel.ErrorMessage));
            }
        }