Beispiel #1
0
        public ActionResult AddSegment(SegmentViewModel viewModel)
        {
            var experiment = experimentRepository.Get(viewModel.ExperimentId);

            try
            {
                if (ModelState.IsValid)
                {
                    viewModel.Segment.CreatedBy    = HttpContext.User.Identity.Name;
                    viewModel.Segment.Variables    = new Dictionary <string, string>();
                    viewModel.Segment.ExperimentId = viewModel.ExperimentId;

                    foreach (var variable in experiment.Variables)
                    {
                        var varValue = Request["prop-" + variable];
                        if (!string.IsNullOrEmpty(varValue))
                        {
                            viewModel.Segment.Variables.Add(variable, varValue);
                        }
                    }

                    viewModel.Segment = experimentRepository.AddSegment(viewModel.Segment);
                    return(Redirect("/Experiments/Update?Id=" + experiment.Id));
                }
                else
                {
                    ViewBag.ErrorMessage = "There is a problem with one of your responses.";
                }
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "An Error Occurred while attempting to save that segment.";
            }


            viewModel.ExperimentName = experiment.Name;
            viewModel.Variables      = experiment.Variables;
            viewModel.ExperimentId   = experiment.Id;

            return(View(viewModel));
        }