Ejemplo n.º 1
0
        public async Task <IActionResult> PostQuestionItem([FromForm] NewSolution newSolution)
        {
            if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType))
            {
                return(BadRequest($"Expected a multipart request, but got {Request.ContentType}"));
            }
            SolutionItem solutionItem = new SolutionItem();

            try
            {
                using (var stream = newSolution.workingImage.OpenReadStream())
                {
                    var cloudBlock = await UploadToBlob(newSolution.workingImage.FileName, null, stream);

                    //// Retrieve the filename of the file you have uploaded
                    //var filename = provider.FileData.FirstOrDefault()?.LocalFileName;
                    if (string.IsNullOrEmpty(cloudBlock.StorageUri.ToString()))
                    {
                        return(BadRequest("An error has occured while uploading your file. Please try again."));
                    }
                    System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
                    solutionItem.workingImage = cloudBlock.SnapshotQualifiedUri.AbsoluteUri;
                }
            }
            catch (Exception)
            {
                // No images was received
                solutionItem.workingImage = "";
            }

            try
            {
                solutionItem.questionID  = newSolution.questionID;
                solutionItem.answer      = newSolution.answer;
                solutionItem.description = newSolution.description;
                // Solution is initialised with 0 upvotes
                solutionItem.upvotes  = 0;
                solutionItem.authorID = newSolution.authorID;
                _context.SolutionItem.Add(solutionItem);
                await _context.SaveChangesAsync();

                return(Ok($"File: {solutionItem.answer} has successfully uploaded"));
            }
            catch (Exception ex) {
                return(BadRequest($"An error has occured. Details: {ex.Message}"));
            }
        }
Ejemplo n.º 2
0
        public void Activation()
        {
            var shell = IoC.Get <IShell>();

            shell.AddDocument(this);
            shell.SolutionChanged += ShellOnSolutionChanged;

            //LoadNewsFeed().GetAwaiter().GetResult();
            //LoadVideoFeed().GetAwaiter().GetResult();
            var solutionExplorer = IoC.Get <ISolutionExplorer>();

            NewSolution.Subscribe(_ =>
            {
                solutionExplorer.NewSolution();
            });

            OpenSolution.Subscribe(_ =>
            {
                solutionExplorer.OpenSolution();
            });
        }