Esempio n. 1
0
 public IActionResult Upload(FileStoreDTO upModel)
 {
     if (Request.Form != null && Request.Form.Files.Count > 0)
     {
         foreach (var formFile in Request.Form.Files)
         {
             if (formFile.Length > 100000000)
             {
                 return(StatusCode(500));//TODO вывести нормальную ошибку
             }
             //Костыль с кастомным FileStore. Когда будет новый core, нужно переписать
             var coreModel = new Core.Data.DTO.Common.FileStoreDTO();
             _objectMapper.Map(upModel, coreModel);
             var dto = FileStoreHelper.SaveFile(Configuration, formFile, coreModel);
             if (dto != null)
             {
                 try
                 {
                     _objectMapper.Map(dto, upModel);
                     Service.SaveAsync(upModel).Wait();
                 }
                 catch
                 {
                     FileStoreHelper.DeleteFileIfExist(dto.FilePath);
                     throw;
                 }
             }
         }
         return(Ok(new { count = Request.Form.Files.Count }));
     }
     else
     {
         return(NotFound());
     }
 }
Esempio n. 2
0
        public override async Task <JsonResult> Delete(Guid id)
        {
            try
            {
                var eDoc = _dataService.GetEntity <EDocument>(x => x.Id == id).SingleOrDefault();
                eDoc.RecordState = RecordState.D;
                var eDocBranches = _dataService.GetEntity <BranchEDocument>(x => x.EDocumentId == eDoc.Id)
                                   .ToList();
                eDocBranches.ForEach(x => x.RecordState = RecordState.D);
                var files = _dataService.GetEntity <FileStore>(x => x.EntityId == id && x.EntityName == "EDocument")
                            .ToList();
                files.ForEach(x =>
                {
                    x.RecordState = RecordState.D;
                    FileStoreHelper.DeleteFileIfExist(x.FilePath);
                });
                await _dataService.SaveChangesAsync();

                return(await Task.FromResult(Json(new { success = true })));
            }
            catch (Exception e)
            {
                return(await Task.FromResult(Json(new { success = false, ErrorMessage = "Помилка видалення. " + (e.InnerException ?? e).Message })));
            }
        }
Esempio n. 3
0
        public static async Task SaveFile(IConfiguration config, FilesViewModel model, FileStoreDTO fileStoreDto, ICommonDataService dataService)
        {
            var folderForSave = config.GetSection("FileStorePath").Value + DateTime.Now.ToString("ddMMyyyy") + "/";
            var filePath      = Path.GetFullPath(folderForSave);

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            var    newName       = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".zip";
            var    tempfolder    = Path.GetTempPath();
            var    fullOrigPath  = tempfolder + model.name;
            string fullZipPath   = filePath + newName;
            var    directoryInfo = (new FileInfo(fullOrigPath)).Directory;

            directoryInfo?.Create();
            await File.WriteAllBytesAsync(fullOrigPath, Convert.FromBase64String(model.file));

            CreateZip(fullZipPath, fullOrigPath);

            FileStoreHelper.DeleteFileIfExist(fullOrigPath);
            fileStoreDto.FileName = newName;
            fileStoreDto.FilePath = fullZipPath;
            dataService.Add <FileStore>(fileStoreDto);
        }
Esempio n. 4
0
        public async Task Delete(Guid id)
        {
            var branch = _dataService.GetEntity <Branch>(x => x.Id == id).SingleOrDefault();

            branch.RecordState = RecordState.D;
            var branchContractors = _dataService.GetEntity <PrlBranchContractor>(x => x.BranchId == id).ToList();
            var contractors       = _dataService
                                    .GetEntity <PrlContractor>(x => branchContractors.Select(y => y.ContractorId).Contains(x.Id)).ToList();

            contractors.ForEach(contr =>
            {
                var contrBranches = _dataService.GetEntity <PrlBranchContractor>(x => x.ContractorId == contr.Id).ToList();
                if (contrBranches.All(z => z.BranchId == id))
                {
                    contr.RecordState = RecordState.D;
                    contrBranches.ForEach(x => x.RecordState = RecordState.D);
                }
            }
                                );
            var branchAssignees = _dataService.GetEntity <AppAssigneeBranch>(x => x.BranchId == id).ToList();
            var assignees       = _dataService
                                  .GetEntity <AppAssignee>(x => branchAssignees.Select(y => y.AssigneeId).Contains(x.Id)).ToList();

            assignees.ForEach(assignee =>
            {
                var assigneeBranches = _dataService.GetEntity <AppAssigneeBranch>(x => x.AssigneeId == assignee.Id).ToList();
                if (assigneeBranches.All(z => z.BranchId == id))
                {
                    assignee.RecordState = RecordState.D;
                    assigneeBranches.ForEach(x => x.RecordState = RecordState.D);
                }
            }
                              );
            var branchEDocuments = _dataService.GetEntity <BranchEDocument>(x => x.BranchId == id).ToList();
            var eDocuments       = _dataService
                                   .GetEntity <EDocument>(x => branchEDocuments.Select(y => y.EDocumentId).Contains(x.Id)).ToList();

            eDocuments.ForEach(eDoc =>
            {
                var eDocBranches = _dataService.GetEntity <BranchEDocument>(x => x.EDocumentId == eDoc.Id).ToList();
                if (eDocBranches.All(z => z.BranchId == id))
                {
                    eDoc.RecordState = RecordState.D;
                    var files        = _dataService.GetEntity <FileStore>(x =>
                                                                          x.EntityId == eDoc.Id && x.EntityName == "EDocument").ToList();
                    files.ForEach(file =>
                    {
                        file.RecordState = RecordState.D;
                        FileStoreHelper.DeleteFileIfExist(file.FilePath);
                    });
                    eDocBranches.ForEach(x => x.RecordState = RecordState.D);
                }
            }
                               );
            await _dataService.SaveChangesAsync();
        }
Esempio n. 5
0
        public IActionResult Upload(FileStoreDTO upModel)
        {
            if (Request.Form != null && Request.Form.Files.Count > 0)
            {
                foreach (var formFile in Request.Form.Files)
                {
                    if (formFile.Length > 1e+8)
                    {
                        return(Json(new { success = false, fileSize = formFile.Length, fileName = formFile.FileName }));
                    }
                    //Костыль с кастомным FileStore. Когда будет новый core, нужно переписать
                    var coreModel = new Core.Data.DTO.Common.FileStoreDTO();
                    _objectMapper.Map(upModel, coreModel);
                    var dto = FileStoreHelper.SaveFile(Configuration, formFile, coreModel);
                    if (dto == null)
                    {
                        continue;
                    }

                    try
                    {
                        _objectMapper.Map(dto, upModel);
                        Service.SaveAsync(upModel).Wait();
                    }
                    catch
                    {
                        FileStoreHelper.DeleteFileIfExist(dto.FilePath);
                        throw;
                    }
                }
                return(Ok(new { count = Request.Form.Files.Count }));
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task Delete(Guid id, bool softDeleting)
        {
            try
            {
                var application = _commonDataService.GetEntity <ImlApplication>(x => x.Id == id).SingleOrDefault();
                application.RecordState = RecordState.D;
                var applicationBranches =
                    _commonDataService.GetEntity <ApplicationBranch>(x => x.LimsDocumentId == id).ToList();
                applicationBranches.ForEach(x => x.RecordState = RecordState.D);
                var branches = _commonDataService.GetEntity <Branch>(x => applicationBranches.Select(y => y.BranchId).Contains(x.Id)).ToList();
                branches.ForEach(x => x.RecordState = RecordState.D);
                var branchAssignees =
                    _commonDataService.GetEntity <AppAssigneeBranch>(x => branches.Select(y => y.Id).Contains(x.BranchId)).ToList();
                branchAssignees.ForEach(x => x.RecordState = RecordState.D);
                var assignees = _commonDataService
                                .GetEntity <AppAssignee>(x => branchAssignees.Select(y => y.AssigneeId).Contains(x.Id)).ToList();
                assignees.ForEach(x => x.RecordState = RecordState.D);
                var eDocumentBranches = _commonDataService
                                        .GetEntity <BranchEDocument>(x => branches.Select(y => y.Id).Contains(x.BranchId)).ToList();
                eDocumentBranches.ForEach(x => x.RecordState = RecordState.D);
                var eDocument =
                    _commonDataService.GetEntity <EDocument>(x =>
                                                             eDocumentBranches.Select(y => y.EDocumentId).Contains(x.Id)).ToList();
                var licFileName = new List <string>();
                eDocument.ForEach(x =>
                {
                    if (x.IsFromLicense == true)
                    {
                        var files = _commonDataService
                                    .GetEntity <FileStore>(y => y.EntityId == x.Id && y.EntityName == "EDocument").ToList();
                        licFileName.AddRange(files.Select(p => p.FileName));
                    }
                });

                eDocument.ForEach(x =>
                {
                    if (x.IsFromLicense == true)
                    {
                        return;
                    }
                    x.RecordState = RecordState.D;
                    var files     = _commonDataService
                                    .GetEntity <FileStore>(y => y.EntityId == x.Id && y.EntityName == "EDocument").ToList();
                    files.ForEach(y =>
                    {
                        y.RecordState = RecordState.D;
                        // Удалить файлы которые не принадлежат лицензии
                        if (!licFileName.Contains(y.FileName))
                        {
                            FileStoreHelper.DeleteFileIfExist(y.FilePath);
                        }
                    });
                });

                await _commonDataService.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }