Exemplo n.º 1
0
        //
        // GET+POST: /Backend/Settings
        public ActionResult Settings()
        {
            Form_Settings form = new Form_Settings(this._app.ListLength, this._app.UnregistredComments);

            if (Request.HttpMethod.ToLower() == form.getMethod().ToString())
            {
                if (form.isValid(Request.Form))
                {
                    if (this._app.saveSettings(form))
                    {
                        _messages.addMessage("Settings have been successfully saved");
                        return Redirect("/backend");
                    }
                    else
                    {
                        _messages.addError("There was an error while saving settings");
                    }
                }
            }

            ViewData["form"] = form.render();
            return View();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves settings
        /// </summary>
        /// <param name="form">Form instance</param>
        /// <returns>boolean</returns>
        public bool saveSettings(Form_Settings form)
        {
            using (SettingsDataContext s = new SettingsDataContext())
            {
                try
                {
                    setting len = s.settings.Where(x => x.name == "list_length").Single();
                    len.value = form["list_length"].getValue();

                    setting comm = s.settings.Where(x => x.name == "unregistered_comments").Single();
                    comm.value = form["unregistered_comments"].getValue();

                    s.SubmitChanges();
                }
                catch (Exception){
                    return false;
                }

                return true;
            }
        }