private void CreateMatchSelectLists(MatchSettingsViewModel model)
        {
            // Column content Dropbox
            var columnContent = from MatchColumnContentAlternative cC in Enum.GetValues(typeof(MatchColumnContentAlternative))
                                select new { value = (int)cC, text = cC.GetLocalizedDescription() };

            ViewData["ColumnContentAlternative"] = new SelectList(columnContent, "value", "text", model.ColumnContentAlternative.ToString());

            // RowDelimiter Dropbox
            var rowDelimiters = from MatchTaxonRowDelimiter rd in Enum.GetValues(typeof(MatchTaxonRowDelimiter))
                                select new { value = (int)rd, text = rd.GetLocalizedDescription() };

            ViewData["RowDelimiter"] = new SelectList(rowDelimiters, "value", "text", model.RowDelimiter.ToString());

            // ColumnDelimiter Dropbox
            var columnDelimiters = from MatchTaxonColumnDelimiter rd in Enum.GetValues(typeof(MatchTaxonColumnDelimiter))
                                   select new { value = (int)rd, text = rd.GetLocalizedDescription() };

            ViewData["ColumnDelimiter"] = new SelectList(columnDelimiters, "value", "text", model.ColumnDelimiter.ToString());

            // MatchTaxonToType Dropbox
            var matchToTypes = from MatchTaxonToType mt in Enum.GetValues(typeof(MatchTaxonToType))
                               select new { value = (int)mt, text = mt.GetLocalizedDescription() };

            ViewData["MatchToType"] = new SelectList(matchToTypes, "value", "text", model.MatchToType.ToString());
        }
        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);
        }
        public ActionResult Settings(string taxonId)
        {
            TaxonSearchResult searchResult = this.TaxonSearchManager.GetTaxon(taxonId);

            if (searchResult.NumberOfMatches != 1)
            {
                return(RedirectToSearch(taxonId));
            }

            ITaxon taxon = searchResult.Taxon;

            this.TaxonIdentifier = TaxonIdTuple.Create(taxonId, searchResult.Taxon.Id);
            ViewBag.Taxon        = taxon;
            var viewManager = new MatchViewManager(GetCurrentUser());
            MatchSettingsViewModel model = viewManager.GetMatchSettingsViewModel(taxon);

            CreateMatchSelectLists(model);
            ModelState.Remove("TaxonId");

            return(View(model));
        }
        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));
        }