예제 #1
0
 private void SaveParameter(EditingFormModel form)
 {
     form.parameter.MetaData.Variants = form.Variants;
     var model = new ParametersViewModel() { EditingForm = form };
     model.SaveParentsAndChildren();
     Get<IParameterRepository>().Edit(form.parameter);
 }
예제 #2
0
 public ActionResult EditParam(EditingFormModel form)
 {
     if (form == null || form.parameter == null)
     {
         return RedirectTo<ParametersController>(a => a.StartEditing());
     }
     else
         return View(form);
 }
예제 #3
0
        public ActionResult SaveEdit(EditingFormModel form)
        {
            if (form != null && ModelState.IsValid)
            {
                form.Parameters = Get<IParameterRepository>().GetAllParam();
                var parameter = Get<IParameterRepository>().GetById(form.parameter.Id);
                form.parameter.MetaData.Variants = parameter.MetaData.Variants;
                if (form.parameter.MetaData.Is_var)
                {
                    if (form.parameter.MetaData.Variants == null)
                    {
                        if (form.NumValue != 0)
                        {

                            return RedirectTo<ParametersController>(z => z.AddVariant(form));
                        }
                        else
                        {
                            form.parameter.MetaData.Is_var = !form.parameter.MetaData.Is_var;
                            return RedirectTo<ParametersController>(z => z.EditParam(form));
                        }
                    }
                    else
                    {
                        if (form.Variants.Last().Value != null && form.Variants.Last().Ball != null)
                        {
                            //TODO: решить проблему - если задать пустые ячейки, то они запишутся в БД.
                            form.parameter.MetaData.Variants = form.Variants;
                        }
                        else
                        {
                            IList<Variant> variants = form.Variants.ToList();
                            variants.RemoveAt(variants.Count - 1);
                            form.Variants = variants.ToArray();
                        }

                        for (var i = 0; i < form.CheckBoxVariant.Count; i++)
                        {
                            if (form.CheckBoxVariant[i])
                            {
                                IList<Variant> variants = form.Variants.ToList();
                                variants.RemoveAt(i);
                                form.Variants = variants.ToArray();
                            }
                        }

                        SaveParameter(form);
                        return RedirectTo<ParametersController>(z => z.EditConfirm());
                    }
                }
                else
                {
                    if (form.parameter.MetaData.Variants == null)
                    {
                        SaveParameter(form);
                        return RedirectTo<ParametersController>(z => z.EditConfirm());
                    }
                    else
                    {
                        form.Variants = null;
                        form.parameter.MetaData.Is_var = false;
                        SaveParameter(form);
                        return RedirectTo<ParametersController>(z => z.EditConfirm());
                    }
                }
            }
            else
            {
                throw new Exception("Ошибка, нет заполненной формы редактирования параметра.");
            }
            return View();
        }
예제 #4
0
        public ActionResult AddVariant(EditingFormModel form)
        {
            if (form == null && ModelState.IsValid == false && form.NumValue == 0)
            {
                throw new Exception("Ошибка, нет данных для добавления вариантов ответа");
            }
            TempData["parameter"] = form.parameter;
            return View(new VarFormModel()
            {
                NumVariant = form.NumValue,
                Variants = new Variant[form.NumValue],
                Parameter = form.parameter

            });
        }