Ejemplo n.º 1
0
        /* this is to choose the option starting from global site options with user consideration */

        /// <summary> </summary>
        public static String get_option(String name)
        {
            String  result = "";
            options sdata  = ActiveRecordBase <options> .FindOne(
                new List <AbstractCriterion>() {
                Expression.Eq("site", siteService.getCurrentSite()),
                Expression.Eq("option_key", name)
            }.ToArray()
                );

            if (sdata != null)
            {
                result = sdata.value;
            }

            if (sdata != null && sdata.is_overwritable)
            {
                user_meta_data udata = ActiveRecordBase <user_meta_data> .FindOne(
                    new List <AbstractCriterion>() {
                    Expression.Eq("_user", userService.getUserFull()),
                    Expression.Eq("meta_key", name)
                }.ToArray()
                    );

                if (udata != null)
                {
                    result = udata.value;
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary> </summary>
        public void update_user(
            [ARDataBind("user", Validate = true, AutoLoad = AutoLoadBehavior.NewInstanceIfInvalidKey)] appuser user,
            [ARDataBind("image", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] posting image,
            HttpPostedFile newimage,
            int[] Sections,
            string apply,
            string cancel,
            Boolean ajaxed,
            String[] value,
            String[] meta_key
            )
        {
            if (user.user_meta_data != null)
            {
                user.user_meta_data.Clear();
            }
            else
            {
                user.user_meta_data = new List <user_meta_data>();
            }
            int i = 0;

            foreach (String item in value)
            {
                user_meta_data tmp = new user_meta_data()
                {
                    value    = item,
                    meta_key = meta_key[i]
                };
                i++;
                user.user_meta_data.Add(tmp);
            }

            if (cancel != null)
            {
                RedirectToAction("list_user");
                return;
            }
            if (user.groups == null || user.groups.baseid == 0)
            {
                List <AbstractCriterion> baseEx = new List <AbstractCriterion>();
                baseEx.Add(Expression.Eq("default_group", true));
                baseEx.Add(Expression.Eq("isAdmin", true));
                user.groups = ActiveRecordBase <user_group> .FindFirst(baseEx.ToArray());
            }

            try {
                ActiveRecordMediator <appuser> .Save(user);

                if (user == userService.getUser())
                {
                    userService.setUser();
                }
            } catch (Exception ex) {
                Flash["error"] = ex.Message;
                Flash["user"]  = user;
            }
            if (apply != null || ajaxed)
            {
                logger.writelog("Applied user edits", getView(), getAction(), user.baseid);
                if (user.baseid > 0)
                {
                    if (ajaxed)
                    {
                        CancelLayout();
                        RenderText(user.baseid.ToString());
                    }
                    else
                    {
                        RedirectToUrl("~/users/edit_user.castle?id=" + user.baseid);
                    }
                    return;
                }
                else
                {
                    RedirectToReferrer();
                    return;
                }
            }
            else
            {
                logger.writelog("Saved user edits on", getView(), getAction(), user.baseid);
                RedirectToAction("list_users");
                return;
            }
        }