Ejemplo n.º 1
0
        public async Task <ActionResult> Create(IFormFile file, ReplyViewModel reply)
        {
            Topic topic = new Topic()
            {
                Title            = reply.Title,
                Content          = reply.Content,
                MediaDescription = reply.MediaDescription,
                UserId           = reply.UserId,
                UserName         = reply.UserName,
                CreatedDate      = DateTime.Now
            };

            try
            {
                if (file != null)
                {
                    using (var filestream = file.OpenReadStream())
                    {
                        topic.MediaUrl = await _mediaService.UploadMediaAsync(filestream, file.FileName, file.ContentType);

                        topic.MediaType = file.ContentType;
                    }
                }

                await _storeService.AddTopicAsync(topic);

                return(Ok(new ResultViewModel()
                {
                    Result = Result.SUCCESS,
                    Data = topic
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new ResultViewModel()
                {
                    Result = Result.ERROR,
                    Message = ex.Message
                }));
            }
        }