Example #1
0
        public virtual ActionResult ChangeLanguage(long formId, String culture)
        {
            var form = formsService.Find(formId);

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

            bool allowManage = permissionService.IsAllowed((Int32)FormOperations.Manage, this.CorePrincipal(),
                                                           typeof(Form), form.Id, IsFormOwner(form),
                                                           PermissionOperationLevel.Object);

            FormViewModel model = new FormViewModel {
                AllowManage = allowManage
            }.MapFrom(form);

            model.SelectedCulture = culture;

            //get locale
            var        localeService = ServiceLocator.Current.GetInstance <IFormLocaleService>();
            FormLocale locale        = localeService.GetLocale(formId, culture);

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

            return(PartialView("EditForm", model));
        }
Example #2
0
        public FormViewModel MapLocaleFrom(FormLocale locale)
        {
            Title            = locale.Title;
            SubmitButtonText = locale.SubmitButtonText;
            ResetButtonText  = locale.ResetButtonText;
            SelectedCulture  = locale.Culture;

            return(this);
        }
Example #3
0
 public FormLocale MapLocaleTo(FormLocale locale)
 {
     locale.Title            = Title;
     locale.SubmitButtonText = SubmitButtonText;
     locale.ResetButtonText  = ResetButtonText;
     if (SelectedCulture != null)
     {
         locale.Culture = SelectedCulture;
     }
     return(locale);
 }
Example #4
0
        public virtual ActionResult Save(FormViewModel model)
        {
            FormsHelper.ValidateForm(model, ModelState);
            if (ModelState.IsValid)
            {
                var form = formsService.Find(model.Id);

                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)));
                }

                if (formsService.Save(model.MapTo(form)))
                {
                    //save locale
                    var        localeService = ServiceLocator.Current.GetInstance <IFormLocaleService>();
                    FormLocale locale        = localeService.GetLocale(form.Id, model.SelectedCulture);
                    locale = model.MapLocaleTo(locale ?? new FormLocale {
                        Form = form
                    });

                    localeService.Save(locale);

                    Success(HttpContext.Translate("Messages.SuccessFormSubmit",
                                                  ResourceHelper.GetControllerScope(this)));
                    return(RedirectToAction(FormsMVC.Forms.Edit(model.Id)));
                }
            }
            else
            {
                Error(HttpContext.Translate("Messages.ValidationError",
                                            ResourceHelper.GetControllerScope(this)));
            }

            model.AllowManage = true;

            return(View("Edit", model));
        }