コード例 #1
0
        public ActionResult MatchItems()
        {
            var options = (MatchSettingsViewModel)Session["MatchOptions"];
            var items   = (List <DyntaxaMatchItem>)Session["MatchItems"];

            if (options.IsNull() || items.IsNull())
            {
                return(RedirectToAction("Settings"));
            }

            var manager = new DyntaxaMatchManager(GetCurrentUser());
            List <DyntaxaMatchItem> problematicItems = manager.GetMatchProblems(items);

            if (problematicItems.Count > 0)
            {
                ViewData["MatchItems"] = problematicItems;
                foreach (DyntaxaMatchItem item in problematicItems)
                {
                    if (item.Status == MatchStatus.NeedsManualSelection)
                    {
                        ViewData[item.DropDownListIdentifier] = item.AlternativeTaxa;
                    }
                }
                return(View(options));
            }

            return(RedirectToAction("ResultTable"));
        }
コード例 #2
0
        public ActionResult ResultTable()
        {
            var options = (MatchSettingsViewModel)Session["MatchOptions"];
            var items   = (List <DyntaxaMatchItem>)Session["MatchItems"];

            if (options.IsNull() || items.IsNull())
            {
                return(RedirectToAction("Settings"));
            }

            var manager = new DyntaxaMatchManager(GetCurrentUser());

            items = manager.GetMatchResults(items, options);

            ViewData["MatchItems"] = items;
            Session["MatchItems"]  = items;

            return(View(options));
        }
コード例 #3
0
        public ActionResult CreateExcelFile(MatchSettingsViewModel options, List <DyntaxaMatchItem> items, string downloadTokenValue)
        {
            if (options.IsNull() || items.IsNull())
            {
                return(RedirectToAction("Settings"));
            }

            var manager = new DyntaxaMatchManager(GetCurrentUser());

            items = manager.GetMatchResults(items, options);

            ExcelFileFormat fileFormat       = ExcelFileFormat.OpenXml;
            var             fileDownloadName = "match" + ExcelFileFormatHelper.GetExtension(fileFormat);
            MemoryStream    excelFileStream  = manager.CreateExcelFile(options, items, fileFormat);
            var             fileStreamResult = new FileStreamResult(excelFileStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

            fileStreamResult.FileDownloadName = fileDownloadName;
            Response.AppendCookie(new HttpCookie("fileDownloadToken", downloadTokenValue));
            return(fileStreamResult);
        }
コード例 #4
0
        public ActionResult Settings(MatchSettingsViewModel model)
        {
            CreateMatchSelectLists(model);

            if (ModelState.IsValid)
            {
                var manager = new DyntaxaMatchManager(GetCurrentUser());
                List <DyntaxaMatchItem> items;

                if (model.MatchToType == MatchTaxonToType.TaxonId)
                {
                    model.LabelForProvidedText = Resources.DyntaxaResource.MatchOptionsOutputProvidedTaxonIdLabel;
                }

                bool fileFound = false;
                if (Request.Files.Count > 0)
                {
                    foreach (string file in Request.Files)
                    {
                        HttpPostedFileBase hpf = this.Request.Files[file];
                        if (hpf == null || hpf.ContentLength == 0)
                        {
                            continue;
                        }
                        fileFound = true;

                        string fileExtension = Path.GetExtension(hpf.FileName);
                        if (fileExtension == ".xls" || fileExtension == ".xlsx")
                        {
                            string fileName = GetFileName(fileExtension);
                            hpf.SaveAs(fileName);
                            DyntaxaLogger.WriteMessage("Match->Settings saved uploaded file: " + fileName);
                            model.FileName = fileName;
                            items          = manager.GetMatches(fileName, model);

                            try
                            {
                                if (System.IO.File.Exists(fileName))
                                {
                                    System.IO.File.Delete(fileName);
                                    DyntaxaLogger.WriteMessage("Match->Settings deleted uploaded file: " + fileName);
                                }
                            }
                            catch
                            {
                                DyntaxaLogger.WriteMessage("Match->Settings exception when trying to delete: " + fileName);
                            }

                            if (items.IsNotEmpty())
                            {
                                Session["MatchOptions"] = model;
                                Session["MatchItems"]   = items;
                                return(RedirectToAction("MatchItems"));
                            }
                            else
                            {
                                //TODO: Error. File has no valid content or is not a valid excel file.
                            }
                        }
                        else
                        {
                            ViewData.ModelState.AddModelError("FileName", Resources.DyntaxaResource.MatchOptionsFileExtensionError);
                        }
                    }
                }

                if (!fileFound)
                {
                    if (model.ClipBoard.IsNotEmpty())
                    {
                        items = manager.GetDyntaxaMatchItemsFromText(model.ClipBoard, model);
                        if (items.IsNotEmpty())
                        {
                            Session["MatchOptions"] = model;
                            Session["MatchItems"]   = items;
                            return(RedirectToAction("MatchItems"));
                        }
                        else
                        {
                            //TODO: Error. File has no valid content or is not a valid excel file.
                        }
                    }
                    else
                    {
                        //TODO: Handle error when data is missing
                    }
                }
            }

            return(View(model));
        }