Esempio n. 1
0
        // GET: Task/Edit/5
        public IActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var task = _interactor.GetTaskDetails(id);

            if (task == null)
            {
                return(NotFound());
            }

            var model = GetNewTaskModel(task.ProjectId);

            model.MapToEntity(task);
            model.Id           = task.Id;
            model.Name         = task.Name;
            model.Description  = task?.Description;
            model.EffortId     = task.EffortId;
            model.ResourceId   = task.ResourceId;
            model.CreatedDate  = task.CreatedDate;
            model.ModifiedDate = task.ModifiedDate;
            model.StatusId     = task.StatusId;

            model.ListFiles = (task.Documents.Count > 0) ? task.Documents.ToList() : new List <Documents>();

            this.AssignLookUps(_projectInteractor.GetProjectName(model.ProjectId), model);

            return(View(model));
        }
        public IActionResult DownloadFile([FromBody] DownloadFileModel model)
        {
            try
            {
                var file = _taskInteractor.GetTaskDetails(model.TaskId);

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

                if (file.Documents.Count() == 0)
                {
                    return(null);
                }

                var    fileDetails = file.Documents.Where(x => x.Id == model.ItemId).FirstOrDefault();
                string filepath    = Path.Combine(_settings.DocumentsPath, fileDetails.Task.ProjectId.ToString(), fileDetails.FileName);

                if (!System.IO.File.Exists(filepath))
                {
                    throw new ArgumentException("Invalid file name or file does not exist!");
                }

                byte[] fileBytes = System.IO.File.ReadAllBytes(filepath);
                var    fs        = new FileStream(filepath, FileMode.Open);
                var    ms        = new MemoryStream();
                ms.CopyTo(fs);


                var    ext         = Path.GetExtension(filepath).ToLowerInvariant();
                string contentType = _fileManager.GetContentType()[ext];

                Response.ContentType = contentType;
                Response.Headers.Add("Content-Disposition", "attachment; filename=" + fileDetails.FileName);

                //return File(memory, contentType);
                //return File(fileBytes, "application/force-download", fileDetails.FileName);
                return(PhysicalFile(filepath, "application/force-download", fileDetails.FileName));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }