Esempio n. 1
0
        public async Task <ActionResult> GetLastProcessVersions()
        {
            //Stores data in cache;
            TempData["Name"] = Request.Query["Name"];
            string searchName = TempData["Name"].ToString();

            ViewBag.Name = searchName;

            TempData["Version"] = Request.Query["Version"];
            string searchVersion = TempData["Version"].ToString();

            ViewBag.Version = searchVersion;

            if (string.IsNullOrEmpty(searchName))
            {
                searchName = null;
            }

            //No caso de a string que representa a informação do filtro de pesquisa por versão, ser nula ou vazia,
            if (string.IsNullOrEmpty(searchVersion))
            {
                searchVersion = null;
            }

            _Connection.DatabaseConnection();
            var database = _Connection.GetDatabase();

            _Metadata.SetDatabase(database);
            _Branch.SetDatabase(database);
            _State.SetDatabase(database);

            _Metadata.SetFilterParameters(searchName, searchVersion);
            _Metadata.ReadFromDatabase();

            //------------------------------------------
            //Add - Pagination to Page (Phase 1)
            //------------------------------------------
            string pageNumber = Request.Query["Page"];

            if (string.IsNullOrEmpty(pageNumber))
            {
                pageNumber = 1.ToString();
            }
            int pageIndex = Convert.ToInt32(pageNumber);

            ViewBag.PageNumber = pageNumber; //Passa para a view o número da página;
            //------------------------------------------

            //------------------------------------------
            //Obter as últimas versões dos processos
            //------------------------------------------
            string resultBranch = string.Empty;
            string resultState  = string.Empty;

            List <MetadataModel> metadataList = _Metadata.GetProcessesMetadataList();

            if (metadataList != null)
            {
                foreach (var model in metadataList)
                {
                    _Branch.ReadFromDatabase(model.Branch);
                    resultBranch += (_Branch.GetBranches() + "|");

                    _State.ReadFromDatabase(model.State);
                    resultState += (_State.GetStateDescription() + "|");
                }
            }

            //------------------------------------------
            ViewBag.BranchesByProcess = resultBranch; //Armazena as descrições dos branches por processo;
            ViewBag.StatesByProcess   = resultState;  //Armazena as descrições dos estados por processo;

            //------------------------------------------
            //Add - Pagination to Page (Phase 2)
            //------------------------------------------
            Dictionary <int, List <MetadataModel> > modelsToDisplay = _Pagination.SetModelsByPage(metadataList);
            int NumberOfPages = modelsToDisplay.Count();

            ViewBag.NumberOfPages = NumberOfPages;
            //------------------------------------------

            //Se a base de dados não tiver processos armazenados para mostrar na listagem de processos;
            if (modelsToDisplay.Count() == 0)
            {
                List <MetadataModel> models = new List <MetadataModel>();
                MetadataModel        model  = new MetadataModel()
                {
                    Id      = string.Empty,
                    Name    = string.Empty,
                    Version = 0,
                    Date    = DateTime.Now.ToLocalTime(),
                    Branch  = new List <string>(),
                    Field   = new List <string>(),
                    State   = string.Empty
                };
                models.Add(model);
                return(await Task.Run(() => View("GetLastProcessVersions", models)));
            }

            return(await Task.Run(() => View("GetLastProcessVersions", modelsToDisplay[pageIndex])));
        }
        public async Task <ActionResult> Read()
        {
            //Stores data in cache;
            TempData["Name"] = Request.Query["Name"];
            string searchName = TempData["Name"].ToString();

            ViewBag.Name = searchName;

            TempData["Version"] = Request.Query["Version"];
            string searchVersion = TempData["Version"].ToString();

            ViewBag.Version = searchVersion;

            string pageNumber = Request.Query["Page"];

            if (string.IsNullOrEmpty(pageNumber))
            {
                pageNumber = 1.ToString();
            }

            int pageIndex = Convert.ToInt32(pageNumber);

            if (string.IsNullOrEmpty(searchName))
            {
                searchName = null;
            }
            //No caso de a string que representa a informação do filtro de pesquisa por versão, ser nula ou vazia,
            //define-se como valor default a versão 1;
            if (string.IsNullOrEmpty(searchVersion))
            {
                searchVersion = null;
            }

            ViewBag.PageNumber = pageNumber;

            _Connection.DatabaseConnection();
            _Metadata.SetDatabase(_Connection.GetDatabase()); //Estabeleçe a conexão;
            _GetBranchById.SetDatabase(_Connection.GetDatabase());
            _GetStateById.SetDatabase(_Connection.GetDatabase());

            _Metadata.SetFilterParameters(searchName, searchVersion);
            _Metadata.ReadFromDatabase();

            List <MetadataModel>     metadataList = _Metadata.GetProcessesMetadataList();
            List <ViewMetadataModel> viewModels   = new List <ViewMetadataModel>();

            if (metadataList != null)
            {
                foreach (var metadata in metadataList)
                {
                    _GetBranchById.ReadFromDatabase(metadata.Branch);
                    _GetStateById.ReadFromDatabase(metadata.State);

                    ViewMetadataModel viewModel = new ViewMetadataModel()
                    {
                        Id      = metadata.Id,
                        Name    = metadata.Name,
                        Version = metadata.Version.ToString(),
                        Date    = metadata.Date.ToString(),
                        Branch  = _GetBranchById.GetBranches(),
                        State   = _GetStateById.GetStateDescription()
                    };

                    viewModels.Add(viewModel);
                }
            }
            _SetPagination.SetNumberOfModelsByPage(4);
            Dictionary <int, List <ViewMetadataModel> > modelsToDisplay = _SetPagination.SetModelsByPage(viewModels);

            int NumberOfPages = modelsToDisplay.Count();

            ViewBag.NumberOfPages = NumberOfPages;


            //Se a base de dados não tiver processos armazenados para mostrar na listagem de processos;
            if (modelsToDisplay.Count() == 0)
            {
                List <ViewMetadataModel> models = new List <ViewMetadataModel>();
                ViewMetadataModel        model  = new ViewMetadataModel()
                {
                    Id      = string.Empty,
                    Name    = string.Empty,
                    Version = string.Empty,
                    Date    = string.Empty,
                    Branch  = string.Empty,
                    State   = string.Empty
                };
                models.Add(model);
                return(await Task.Run(() => View("Read", models)));
            }

            return(await Task.Run(() => View("Read", modelsToDisplay[pageIndex])));
        }
Esempio n. 3
0
        public async Task <ActionResult> GetProcessFieldDataByVersions(string name, string version)
        {
            _Connection.DatabaseConnection();         //Estabeleçer a ligação com a base de dados;
            var database = _Connection.GetDatabase(); //Obter a ligação com a base de dados;

            _Metadata.SetDatabase(database);
            _Data.SetDatabase(database);

            /*
             * Paginação - Fase de obtenção do nº de página;
             */
            string pageNumber = Request.Query["Page"];

            if (string.IsNullOrEmpty(pageNumber))
            {
                pageNumber = 1.ToString();
            }

            int pageIndex = Convert.ToInt32(pageNumber);

            ViewBag.ProcessName    = name;
            ViewBag.ProcessVersion = version;
            ViewBag.PageNumber     = pageNumber;

            List <string> processIdList      = new List <string>(); //Armazena a lista de id´s do processo nas diferentes versões;
            List <int>    processVersionList = new List <int>();    //Armazena as versões correspondentes ao id do processo;

            //Recupera versões anteriores do processo se as mesmas existirem;
            if (int.Parse(version) >= 1)
            {
                for (int j = int.Parse(version); j >= 1; j--)
                {
                    processIdList.Add(_Metadata.GetProcessByVersion(name, j).Id);
                    processVersionList.Add(j);
                }
            }

            List <ViewDataModel> viewDataModelList = new List <ViewDataModel>(); //Lista de ViewDataModels, para display da dados;

            //Ciclo que percorre as diferentes combinações de {Process Id - Version - Branch}
            for (int i = 0; i < processIdList.Count; i++)
            {
                List <DataModel> dataModelList = _Data.GetDataModelByProcessId(processIdList.ElementAt(i));

                foreach (var dataModel in dataModelList)
                {
                    //É criado o modelo de dados do tipo ViewDataModel;
                    ViewDataModel modelToDisplay = new ViewDataModel()
                    {
                        ObjectId       = _Data.GetObjectId(processIdList.ElementAt(i), processVersionList.ElementAt(i), dataModel.ProcessBranch, dataModel.Data),
                        ProcessId      = processIdList.ElementAt(i),
                        ProcessVersion = processVersionList.ElementAt(i),
                        ProcessBranch  = dataModel.ProcessBranch,
                        CreationDate   = dataModel.Date,
                        Data           = dataModel.Data
                    };
                    viewDataModelList.Add(modelToDisplay); //Adiciona-se à lista de ViewDataModel o modelo criado;
                }
            }
            _SetPagination.SetNumberOfModelsByPage(4);
            Dictionary <int, List <ViewDataModel> > modelsToDisplay = _SetPagination.SetModelsByPage(viewDataModelList);

            int NumberOfPages = modelsToDisplay.Count();

            ViewBag.NumberOfPages = NumberOfPages;

            if (modelsToDisplay.Count == 0)
            {
                List <ViewDataModel> auxViewDataModelList = new List <ViewDataModel>();
                ViewDataModel        emptyModel           = new ViewDataModel()
                {
                    ObjectId       = null,
                    ProcessId      = null,
                    ProcessVersion = 0,
                    ProcessBranch  = null,
                    CreationDate   = DateTime.UtcNow.Date,
                    Data           = null
                };
                auxViewDataModelList.Add(emptyModel);
                return(await Task.Run(() => View("GetProcessFieldDataByVersions", auxViewDataModelList)));
            }

            return(await Task.Run(() => View("GetProcessFieldDataByVersions", modelsToDisplay[pageIndex])));
        }