Exemplo n.º 1
0
        public async Task <UploadResult> HandleUpload(string fileName, string contentType, Stream stream)
        {
            IUploadHandler handler = _fileUploadHandlers.FirstOrDefault(c => c.IsValid(fileName, contentType));

            if (handler == null)
            {
                return(null);
            }

            return(await handler.UploadFile(fileName, contentType, stream));
        }
Exemplo n.º 2
0
        public async Task <UploadResult> HandleUpload(string fileName, string contentType, Stream stream, long contentLength)
        {
            var settings = _kernel.Get <ApplicationSettings>();

            if (contentLength > settings.MaxFileUploadBytes)
            {
                return(null);
            }

            IUploadHandler handler = _fileUploadHandlers.FirstOrDefault(c => c.IsValid(fileName, contentType));

            if (handler == null)
            {
                return(null);
            }

            return(await handler.UploadFile(fileName, contentType, stream));
        }
Exemplo n.º 3
0
        public async Task <UploadResult> HandleUpload(string fileName, string contentType, Stream stream, long contentLength)
        {
            var settings = _kernel.Get <ApplicationSettings>();

            if (contentLength > settings.MaxFileUploadBytes)
            {
                return(new UploadResult {
                    UploadTooLarge = true, MaxUploadSize = settings.MaxFileUploadBytes
                });
            }

            string fileNameSlug = fileName.ToFileNameSlug();

            IUploadHandler handler = _fileUploadHandlers.FirstOrDefault(c => c.IsValid(fileNameSlug, contentType));

            if (handler == null)
            {
                return(null);
            }

            return(await handler.UploadFile(fileNameSlug, contentType, stream));
        }
        public async Task <IActionResult> Add(CreateIssue model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var previousVersion = await _issueManager.GetIssue(model.Id);

                    var newVersion = await _issueManager.SaveIssue(model, null);

                    var issueActivity = _issueManager.SaveActivity(model, previousVersion, newVersion);

                    //ConnectionManager c = new ConnectionManager(new DefaultDependencyResolver());
                    //  var context = c.GetHubContext<IssuesHub>();
                    // context.Clients.All.addNewTeamActivity(issueActivity);

                    if ((model.Files != null) && (model.Files.Any()))
                    {
                        foreach (var file in model.Files)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            using (var s = file.OpenReadStream())
                            {
                                var uploadResult = await _uploadHandler.UploadFile(fileName, MimeMapping.GetMimeMapping(fileName), s);

                                if (!String.IsNullOrEmpty(uploadResult.Url))
                                {
                                    uploadResult.ParentId    = model.Id;
                                    uploadResult.CreatedById = this._userSessionHelper.UserId;
                                    uploadResult.Type        = "Issue";
                                    await this._uploadManager.SaveUpload(uploadResult);
                                }
                            }
                        }
                    }
                    if (previousVersion != null)
                    {
                    }
                    if (model.IncludeIssueInResponse)
                    {
                        var newIssue = _issueManager.GetIssue(newVersion.Id);
                        return(Json(new { Status = "Success", Data = newIssue }));
                    }

                    var newIssueUrl = this._urlHelper.Action("Details", new { id = newVersion.Id });
                    return(Json(new { Status = "Success", Url = newIssueUrl }));
                }
                else
                {
                    var validationErrors = new List <string>();
                    foreach (var modelStateVal in ViewData.ModelState.Values)
                    {
                        validationErrors.AddRange(modelStateVal.Errors.Select(error => error.ErrorMessage));
                    }

                    return(Json(new { Status = "Error", Message = "Validation failed", Errors = validationErrors }));
                }
            }
            catch (MissingSettingsException mex)
            {
                return(Json(new { Status = "Error", Message = String.Format("You need to set a value for {0} first.", mex.MissingSettingName) }));
            }
            catch (Exception ex)
            {
                tc.TrackException(ex);
                return(Json(new { Status = "Error", Message = "Error saving issue" }));
            }
        }