Esempio n. 1
0
        public async Task <IActionResult> Post([FromForm] CreateTopicViewModel topicViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var topicDto = _mapper.Map <CreateTopicViewModel, TopicDto>(topicViewModel);

            byte[] fileBytes;

            using (var stream = new MemoryStream())
            {
                await topicViewModel.Image.CopyToAsync(stream);

                fileBytes = stream.ToArray();
            }

            await _topicService.CreateTopicWithImage(topicDto, topicViewModel.Image.FileName, _hostingEnvironment.WebRootPath, fileBytes);

            return(Ok());
        }