CreateSelectList() public method

public CreateSelectList ( ) : List
return List
コード例 #1
0
        public ActionResult Create(CoordinatorSmsAndEmailModel model)
        {
            var trickleId = Guid.NewGuid();

            Session.Add("CoordinatorSmsAndEmailModel", model);
            Session.Add("trickleId", trickleId.ToString());
            var hpf = Request.Files[0];

            if (hpf.ContentLength == 0)
            {
                throw new ArgumentException("no content");
            }

            var csvFileContents = new CsvFileContents();

            using (var csvReader = new CsvHelper.CsvReader(new StreamReader(hpf.InputStream), new CsvConfiguration {
                HasHeaderRecord = false
            }))
            {
                // TODO : Not reading first row properly
                while (csvReader.Read())
                {
                    csvFileContents.Rows.Add(csvReader.CurrentRecord);
                }
            }

            var fileContentsId = trickleId.ToString() + "_fileContents";

            using (var session = Raven.GetStore().OpenSession())
            {
                session.Store(csvFileContents, fileContentsId);
                session.SaveChanges();
            }

            var dataColumnPicker = new DataColumnPicker {
                TrickleId = trickleId, FirstRowIsHeader = true
            };

            if (!string.IsNullOrWhiteSpace(model.TemplateName))
            {
                using (var session = Raven.GetStore().OpenSession("Configuration"))
                {
                    var communicationTemplate = session.Load <CommunicationTemplate>(model.TemplateName);
                    if (communicationTemplate.TemplateVariables != null)
                    {
                        communicationTemplate.TemplateVariables.ForEach(t => dataColumnPicker.TemplateVariableColumns.Add(t.VariableName, null));
                    }
                }
            }

            var dropDownList = csvFileContents.CreateSelectList();

            ViewData.Add("selectListData", dropDownList);
            return(View("CreateSmsAndEmailPickRows", dataColumnPicker));
        }
コード例 #2
0
        public ActionResult Create(CoordinatorSmsAndEmailModel model)
        {
            var trickleId = Guid.NewGuid();
            Session.Add("CoordinatorSmsAndEmailModel", model);
            Session.Add("trickleId", trickleId.ToString());
            var hpf = Request.Files[0];
            if (hpf.ContentLength == 0)
                throw new ArgumentException("no content");

            var csvFileContents = new CsvFileContents();
            using (var csvReader = new CsvHelper.CsvReader(new StreamReader(hpf.InputStream), new CsvConfiguration { HasHeaderRecord = false }))
            {
                // TODO : Not reading first row properly
                while (csvReader.Read())
                {
                    csvFileContents.Rows.Add(csvReader.CurrentRecord);
                }
            }

            var fileContentsId = trickleId.ToString() + "_fileContents";
            using (var session = Raven.GetStore().OpenSession())
            {
                session.Store(csvFileContents, fileContentsId);
                session.SaveChanges();
            }

            var dataColumnPicker = new DataColumnPicker {TrickleId = trickleId, FirstRowIsHeader = true};

            if (!string.IsNullOrWhiteSpace(model.TemplateName))
            {
                using (var session = Raven.GetStore().OpenSession("Configuration"))
                {
                    var communicationTemplate = session.Load<CommunicationTemplate>(model.TemplateName);
                    if (communicationTemplate.TemplateVariables  != null)
                        communicationTemplate.TemplateVariables.ForEach(t => dataColumnPicker.TemplateVariableColumns.Add(t.VariableName, null));
                }
            }

            var dropDownList = csvFileContents.CreateSelectList();
            ViewData.Add("selectListData", dropDownList);
            return View("CreateSmsAndEmailPickRows", dataColumnPicker);
        }