Ejemplo n.º 1
0
        public async Task <int> Handle(CreateAppendiceCommand request, CancellationToken cancellationToken)
        {
            Appendice appendice = request.ToAppendice();

            _context.Appendices.Add(appendice);
            return(await _context.SaveChangesAsync());
        }
Ejemplo n.º 2
0
        public async Task <int> Handle(CreatePromulgateStatusCommand request, CancellationToken cancellationToken)
        {
            PromulgateStatus promulgateStatus = request.ToPromulgateStatus();

            _context.PromulgateStatuses.Add(promulgateStatus);
            return(await _context.SaveChangesAsync(cancellationToken));
        }
        public async Task <int> Handle(CreateDocumentTypeCommand request, CancellationToken cancellationToken)
        {
            DocumentType documentType = request.ToDocumentType();

            _context.DocumentTypes.Add(documentType);
            return(await _context.SaveChangesAsync(cancellationToken));
        }
        public async Task <int> Handle(CreateModuleCommand request, CancellationToken cancellationToken)
        {
            Module module = request.ToModule();

            _context.Modules.Add(module);
            return(await _context.SaveChangesAsync());
        }
Ejemplo n.º 5
0
        public async Task <int> Handle(UpdateModuleCommand request, CancellationToken cancellationToken)
        {
            Module module = await _context.Modules.FirstOrDefaultAsync(d => !d.Deleted &&
                                                                       d.Id == request.Id);

            if (module == null)
            {
                throw new NotFoundException(nameof(DocumentType), request.Id);
            }

            module.Code       = request.Code;
            module.Name       = request.Name;
            module.ModifiedBy = request.ModifiedBy;
            module.ModifiedOn = DateTime.Now;

            return(await _context.SaveChangesAsync(cancellationToken));
        }
        public async Task <int> Handle(UpdatePromulgateStatusCommand request, CancellationToken cancellationToken)
        {
            PromulgateStatus promulgateStatus = await _context.PromulgateStatuses.FirstOrDefaultAsync(d => !d.Deleted &&
                                                                                                      d.Id == request.Id);

            if (promulgateStatus == null)
            {
                throw new NotFoundException(nameof(PromulgateStatus), request.Id);
            }

            promulgateStatus.Code       = request.Code;
            promulgateStatus.Name       = request.Name;
            promulgateStatus.ModifiedBy = request.ModifiedBy;
            promulgateStatus.ModifiedOn = DateTime.Now;

            return(await _context.SaveChangesAsync(cancellationToken));
        }
        public async Task ExecuteAsync(DeleteDocumentCommand command, IExecutionContext executionContext)
        {
            using (var scope = TransactionScopeFactory.Create(DbContext))
            {
                var document = await DbContext
                               .Documents
                               .FindAsync(command.Id);

                if (document != null)
                {
                    DbContext.Documents.Remove(document);

                    await DbContext.SaveChangesAsync();

                    await scope.CompleteAsync();
                }
            }
        }
Ejemplo n.º 8
0
        public async Task <int> Handle(DeleteFileByIdAndFileNameCommand request, CancellationToken cancellationToken)
        {
            Document document = await _context.Documents.FirstOrDefaultAsync(a => a.Id == request.Id &&
                                                                             !a.Deleted);

            if (document != null && document.Id > 0)
            {
                if (!string.IsNullOrEmpty(document.FileName))
                {
                    List <string> files = document.FileName.Split(';').ToList();
                    files.Remove(request.FileName);

                    document.FileName = string.Join(";", files);
                    document.LinkFile = string.Empty;
                    return(await _context.SaveChangesAsync());
                }
            }
            return(-1);
        }
        public async Task ExecuteAsync(AddDocumentCommand command, IExecutionContext executionContext)
        {
            using (var scope = TransactionScopeFactory.Create(DbContext))
            {
                var document = new Document
                {
                    Title       = command.Title,
                    MimeType    = command.MimeType,
                    Body        = command.Body,
                    CreatedDate = DateTime.Now,
                };

                DbContext.Documents.Add(document);
                await DbContext.SaveChangesAsync();

                command.OutputDocumentId = document.Id;

                await scope.CompleteAsync();
            }
        }
        public async Task <int> Handle(DeleteAppendiceCommand request, CancellationToken cancellationToken)
        {
            Appendice appendice = _context.Appendices.FirstOrDefault(a => a.Id == request.Id);

            if (appendice != null)
            {
                Document document = _context.Documents.FirstOrDefault(d => d.Id == appendice.DocumentId || d.Code == appendice.RelateToDocuments);
                if (document != null)
                {
                    try
                    {
                        string filePath = $"{UploadFolderPath}/{appendice.FileName}";
                        File.Delete(filePath);
                    }
                    catch
                    {
                    }
                }
                _context.Appendices.Remove(appendice);
                return(await _context.SaveChangesAsync());
            }
            return(-1);
        }
        public async Task <int> Handle(DeleteAppendiceFileCommand request, CancellationToken cancellationToken)
        {
            Appendice appendice = await _context.Appendices.FirstOrDefaultAsync(a => !a.Deleted && a.Id == request.Id);

            if (!appendice.LinkFile.IsNullOrEmpty())
            {
                NameValueCollection query = HttpUtility.ParseQueryString(appendice.LinkFile);
                string filePath           = $"{UploadFolderPath}/{query.Get("sourcedoc")}";
                if (!filePath.IsNullOrEmpty())
                {
                    try
                    {
                        File.Delete(filePath);
                    }
                    catch
                    {
                    }
                }
            }

            appendice.FileName = string.Empty;
            appendice.LinkFile = string.Empty;
            return(await _context.SaveChangesAsync());
        }
Ejemplo n.º 12
0
        public async Task <int> Handle(UpdateAppendiceCommand request, CancellationToken cancellationToken)
        {
            Appendice appendice = await _context.Appendices.Where(a => a.Id == request.Id &&
                                                                  !a.Deleted).FirstOrDefaultAsync();

            if (appendice != null && appendice.Id > 0)
            {
                appendice.Approver        = request.Approver;
                appendice.CompanyCode     = request.CompanyCode;
                appendice.CompanyName     = request.CompanyName;
                appendice.DDCAudited      = request.DDCAudited;
                appendice.DepartmentCode  = request.DepartmentCode;
                appendice.DepartmentName  = request.DepartmentName;
                appendice.EffectiveDate   = request.EffectiveDate;
                appendice.AppendiceNumber = request.AppendiceNumber;

                if (request.Files != null && request.Files.Any())
                {
                    appendice.FileName = request.FileName;
                    appendice.LinkFile = request.LinkFile;
                }
                appendice.ModifiedBy         = request.ModifiedBy;
                appendice.ModifiedOn         = request.ModifiedOn;
                appendice.Module             = request.Module;
                appendice.Name               = request.Name;
                appendice.RelateToDocuments  = request.RelateToDocuments;
                appendice.ReviewDate         = request.ReviewDate;
                appendice.ReviewNumber       = request.ReviewNumber;
                appendice.ScopeOfApplication = request.ScopeOfApplication;
                appendice.ScopeOfDeloyment   = request.ScopeOfDeloyment;

                return(await _context.SaveChangesAsync());
            }

            return(appendice.Id);
        }
Ejemplo n.º 13
0
        public async Task <int> Handle(CreateDocumentCommand request, CancellationToken cancellationToken)
        {
            Document existsDocument = _context.Documents.FirstOrDefault(d =>
                                                                        d.CompanyCode == request.CompanyCode &&
                                                                        d.ContentChange == request.ContentChange &&
                                                                        d.DepartmentCode == request.DepartmentCode &&
                                                                        d.Description == request.Description &&
                                                                        d.DocumentNumber == request.DocumentNumber &&
                                                                        d.DocumentType == request.DocumentType &&
                                                                        d.Drafter == request.Drafter &&
                                                                        d.EffectiveDate == request.EffectiveDate &&
                                                                        d.FileName == request.FileName &&
                                                                        d.Module == request.Module &&
                                                                        d.Name == request.Name &&
                                                                        d.RelateToDocuments == request.RelateToDocuments &&
                                                                        d.ReplaceOf == request.ReplaceOf &&
                                                                        d.ReviewDate == request.ReviewDate &&
                                                                        d.ReviewNumber == request.ReviewNumber &&
                                                                        d.ScopeOfApplication == request.ScopeOfApplication &&
                                                                        d.ScopeOfDeloyment == request.ScopeOfDeloyment
                                                                        );

            if (existsDocument != null && existsDocument.Id > 0)
            {
                throw new ExistsException(nameof(Document), "fields");
            }

            Document document = request.ToDocument();

            document.StatusId           = 1;
            document.PromulgateStatusId = 1;
            _context.Documents.Add(document);
            await _context.SaveChangesAsync(cancellationToken);

            if (document.Id > 0)
            {
                if (request.Appendices != null && request.Appendices.Any())
                {
                    List <Appendice> appendices = request.Appendices.Select(a => new Appendice
                    {
                        Active             = document.Active,
                        DDCAudited         = document.DDCAudited,
                        AppendiceNumber    = document.DocumentNumber,
                        ReviewNumber       = a.ReviewNumber,
                        LinkFile           = a.LinkFile,
                        Approver           = document.Approver,
                        Code               = $"PL{DateTime.Now.ToString("yyyymmddtthhss")}",
                        Name               = a.Name,
                        FileName           = a.FileName,
                        CompanyCode        = document.CompanyCode,
                        CompanyName        = document.CompanyName,
                        DepartmentCode     = document.DepartmentCode,
                        DepartmentName     = document.DepartmentName,
                        CreatedBy          = document.CreatedBy,
                        CreatedOn          = document.CreatedOn,
                        Deleted            = false,
                        DocumentType       = "PL",
                        EffectiveDate      = document.EffectiveDate,
                        Module             = document.Module,
                        StatusId           = document.StatusId,
                        FormType           = document.FormType,
                        PromulgateStatusId = document.PromulgateStatusId,
                        RelateToDocuments  = document.Code,
                        DocumentId         = document.Id,
                        ScopeOfApplication = document.ScopeOfApplication,
                        ScopeOfDeloyment   = document.ScopeOfDeloyment
                    }).ToList();
                    _context.Appendices.AddRange(appendices);
                    await _context.SaveChangesAsync(cancellationToken);
                }
            }
            return(document.Id);
        }
        public async Task <int> Handle(UpdateDocumentCommand request, CancellationToken cancellationToken)
        {
            Document document = _context.Documents.Where(a => a.Id == request.Id &&
                                                         !a.Deleted)
                                .FirstOrDefault();

            if (document != null && document.Id > 0)
            {
                if (!string.IsNullOrEmpty(document.FileName))
                {
                    List <string> oldFiles = document.FileName.Split(';').Where(f => !f.IsNullOrEmpty()).ToList();
                    List <string> newFiles = request.FileName.Split(';').Where(f => !f.IsNullOrEmpty()).ToList();
                    foreach (string newFile in newFiles)
                    {
                        if (!oldFiles.Any(file => file == newFile))
                        {
                            oldFiles.Add(newFile);
                        }
                    }
                    document.FileName = string.Join(";", oldFiles);
                }
                else
                {
                    document.FileName = request.FileName;
                }

                document.ModifiedBy         = request.ModifiedBy;
                document.ModifiedOn         = request.ModifiedOn;
                document.Approver           = request.Approver;
                document.Drafter            = request.Drafter;
                document.Auditor            = request.Auditor;
                document.CompanyCode        = request.CompanyCode;
                document.CompanyName        = request.CompanyName;
                document.Module             = request.Module;
                document.DepartmentCode     = request.DepartmentCode;
                document.DepartmentName     = request.DepartmentName;
                document.Description        = request.Description;
                document.DocumentNumber     = request.DocumentNumber;
                document.ContentChange      = request.ContentChange;
                document.DocumentType       = request.DocumentType;
                document.EffectiveDate      = request.EffectiveDate;
                document.RelateToDocuments  = request.RelateToDocuments;
                document.ScopeOfApplication = request.ScopeOfApplication;
                document.ScopeOfDeloyment   = request.ScopeOfDeloyment;
                document.FormType           = request.FormType;
                document.DDCAudited         = request.DDCAudited;
                document.ReviewDate         = request.ReviewDate;
                document.LinkFile           = request.LinkFile;
                document.FolderName         = request.FolderName;
                document.Name = request.Name;

                if (request.Appendices != null && request.Appendices.Any())
                {
                    List <Appendice> appendices = request.Appendices.Select(a => new Appendice
                    {
                        Id                 = a.Id,
                        Active             = document.Active,
                        Code               = a.Code ?? $"PL{DateTime.Now.ToString("yyyymmddtthhss")}",
                        DDCAudited         = document.DDCAudited,
                        AppendiceNumber    = document.DocumentNumber,
                        ReviewNumber       = a.ReviewNumber,
                        LinkFile           = a.LinkFile,
                        Approver           = document.Approver,
                        Name               = a.Name,
                        FileName           = a.FileName,
                        CompanyCode        = document.CompanyCode,
                        CompanyName        = document.CompanyName,
                        DepartmentCode     = document.DepartmentCode,
                        DepartmentName     = document.DepartmentName,
                        CreatedBy          = document.CreatedBy,
                        CreatedOn          = document.CreatedOn,
                        Deleted            = false,
                        DocumentType       = "PL",
                        EffectiveDate      = document.EffectiveDate,
                        Module             = document.Module,
                        StatusId           = document.StatusId,
                        FormType           = document.FormType,
                        PromulgateStatusId = document.PromulgateStatusId,
                        RelateToDocuments  = document.Code,
                        DocumentId         = document.Id,
                        ScopeOfApplication = document.ScopeOfApplication,
                        ScopeOfDeloyment   = document.ScopeOfDeloyment
                    }).ToList();

                    _context.Appendices.AddOrUpdate(a => new { a.Id }, appendices.ToArray());
                }
                await _context.SaveChangesAsync();
            }
            return(document.Id);
        }