예제 #1
0
        public virtual ActionResult ChangeFormElementLanguage(long formElementId, String culture)
        {
            var formElement = formsElementService.Find(formElementId);

            if (formElement == null || formElement.Form == null || !permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(), typeof(Form), formElement.Form.Id, IsFormOwner(formElement.Form), PermissionOperationLevel.Object))
            {
                throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this)));
            }

            FormElementViewModel model = new FormElementViewModel {
                FormId = formElement.Form.Id
            }.MapFrom(formElement);

            model.SelectedCulture = culture;

            //get locale
            var localeService        = ServiceLocator.Current.GetInstance <IFormElementLocaleService>();
            FormElementLocale locale = localeService.GetLocale(formElementId, culture);

            if (locale != null)
            {
                model.MapLocaleFrom(locale);
            }

            return(PartialView("FormElementEditor", model));
        }
예제 #2
0
        public FormElementViewModel MapLocaleFrom(FormElementLocale locale)
        {
            Title           = locale.Title;
            Values          = locale.ElementValues;
            SelectedCulture = locale.Culture;

            return(this);
        }
예제 #3
0
 public FormElementLocale MapLocaleTo(FormElementLocale locale)
 {
     locale.Title         = Title;
     locale.ElementValues = Values;
     if (SelectedCulture != null)
     {
         locale.Culture = SelectedCulture;
     }
     return(locale);
 }
예제 #4
0
        public virtual ActionResult SaveElement(long formId, FormElementViewModel model)
        {
            FormsHelper.ValidateFormElement(model, ModelState);

            if (ModelState.IsValid)
            {
                FormsHelper.UpdateFormElement(model);

                var form = formsService.Find(formId);
                if (form == null || !permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(), typeof(Form), form.Id, IsFormOwner(form), PermissionOperationLevel.Object))
                {
                    throw new HttpException((int)HttpStatusCode.NotFound, HttpContext.Translate("Messages.NotFound", ResourceHelper.GetControllerScope(this)));
                }

                var  formElement = new FormElement();
                bool isEdited    = model.Id > 0;
                if (isEdited)
                {
                    formElement = formsElementService.Find(model.Id);
                }
                else
                {
                    formElement.Form        = form;
                    formElement.OrderNumber = formsElementService.GetLastOrderNumber(formElement.Form.Id);
                }

                if (formsElementService.Save(model.MapTo(formElement)))
                {
                    if (isEdited)
                    {
                        //save locale
                        var localeService        = ServiceLocator.Current.GetInstance <IFormElementLocaleService>();
                        FormElementLocale locale = localeService.GetLocale(formElement.Id, model.SelectedCulture);
                        locale = model.MapLocaleTo(locale ?? new FormElementLocale {
                            FormElement = formElement
                        });
                        localeService.Save(locale);
                    }
                    Success(HttpContext.Translate("Messages.FormElementSaveSuccess", ResourceHelper.GetControllerScope(this)) /*"Sucessfully save form element."*/);
                    return(RedirectToAction(FormsMVC.Forms.ShowFormElements(formId)));
                }
            }

            Error(HttpContext.Translate("Messages.ElementValidationError", ResourceHelper.GetControllerScope(this)) /*"Validation errors occurred while processing this form. Please take a moment to review the form and correct any input errors before continuing."*/);
            return(View("EditFormElement", model));
        }