예제 #1
0
        /// <summary>
        /// Adds a new role
        /// </summary>
        /// <param name="parent">Parent role</param>
        /// <param name="form">Role data</param>
        /// <returns>success</returns>
        public bool add(long parent, Form_Role_Add form)
        {
            role r = new role();
            r.date = DateTime.Now;
            r.parentid = parent;
            if (parent == 0)
            {
                r.parentid = null;
            }
            r.name = form["name"].getValue();

            using (ACLDataContext a = new ACLDataContext())
            {
                a.roles.InsertOnSubmit(r);
                a.SubmitChanges();
            }

            return true;
        }
예제 #2
0
        //
        // GET: /Backend/EditRole?id={id}
        public ActionResult EditRole()
        {
            if (Request.Params.AllKeys.Contains("id"))
            {
                long id = 0;
                try
                {
                    id = long.Parse(Request.Params["id"]);
                }
                catch { }

                role r = this._app.roles().getById(id);

                if (r != null)
                {
                    Form_Role_Add form = new Form_Role_Add(0);
                    if (Request.HttpMethod.ToLower() == form.getMethod().ToString())
                    {
                        if (form.isValid(Request.Form))
                        {
                            if (this._app.roles().save(form, r))
                            {
                                _messages.addMessage("The role has been successfully saved");
                                if (r.parentid.HasValue)
                                {
                                    return Redirect("/backend/ListRoles?parent=" + r.parentid);
                                }
                                return Redirect("/backend/ListRoles?parent=" + r.id);
                            }
                        }
                    }

                    form.setEditData(r);

                    ViewData["form"] = form.render();

                    return View();
                }
            }

            _messages.addError("Undefined or wrong parameter ID");
            return RedirectToAction("listRoles", "backend");
        }
예제 #3
0
        //
        // GET+POST: /Backend/AddRole[?parent={id}]
        public ActionResult AddRole()
        {
            long parent = 0;
            if (Request.Params.AllKeys.Contains("parent"))
            {
                try
                {
                    parent = long.Parse(Request.Params["parent"]);
                }
                catch { }
            }

            string name = "root";

            if (parent > 0)
            {
                role r = this._app.roles().getById(parent);
                if (r != null)
                {
                    name = r.name;
                }
            }

            ViewData["name"] = name;

            Form_Role_Add form = new Form_Role_Add(parent);
            if (Request.HttpMethod.ToLower() == form.getMethod().ToString())
            {
                if (form.isValid(Request.Form))
                {
                    if (this._app.roles().add(parent, form))
                    {
                        _messages.addMessage("The role has been successfully added");
                        return Redirect("/backend/ListRoles?parent=" + parent.ToString());
                    }
                }
            }

            ViewData["form"] = form.render();

            return View();
        }
예제 #4
0
        /// <summary>
        /// Save changes to the given role
        /// </summary>
        /// <param name="form">Role data</param>
        /// <param name="r">Role</param>
        /// <returns>success</returns>
        public bool save(Form_Role_Add form, role r)
        {
            role newRole = new role();
            newRole.id = r.id;

            if (r.parentid.HasValue)
            {
                newRole.parentid = r.parentid;
            }

            newRole.name = form["name"].getValue();
            newRole.date = r.date;

            using (ACLDataContext a = new ACLDataContext())
            {
                a.roles.Attach(newRole, r);
                a.SubmitChanges();
            }

            return true;
        }