Example #1
0
        public void _save_siteSettings(
            [ARDataBind("user", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] users user
            )
        {
            Dictionary <string, string> urlparams = getPostParmasAsObj_obj("settings");
            var jss = new JavaScriptSerializer();
            //jss.RegisterConverters(new JavaScriptConverter[] { new DynamicJsonConverter() });

            //var values = new Dictionary<string, object>();
            MyJsonDictionary <String, Object> values = new MyJsonDictionary <String, Object>();

            foreach (KeyValuePair <string, string> _urlparams in urlparams)
            {
                values.Add(_urlparams.Key, _urlparams.Value);
            }

            /*
             *  values.Add("Title", "Hello World!");
             *  values.Add("Text", "My first post");
             *  values.Add("Tags", new[] { "hello", "world" });
             */
            //var usettings = new DynamicEntity(values);

            user.settings.attr = Serialize(values);    //jss.Serialize(usettings);
            ActiveRecordMediator <users> .Save(user);

            Flash["message"] = "Your setting were saved";
            RedirectToAction("_list_siteSettings");
        }
        public void Update(
            [ARDataBind("view", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] map_views view,
            [ARDataBind("tabs", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] infotabs[] tabs,
            int[] cats,
            String[] newtab,
            [ARDataBind("images", Validate = true, AutoLoad = AutoLoadBehavior.NewRootInstanceIfInvalidKey)] media_repo[] images,
            String[][] fields,
            int[] geolist,
            int[] placelist,
            bool ajaxed_update,
            bool forced_tmp,
            string LongLength,
            string Length,
            string apply,
            string cancel
            )
        {
            //if (view.options.id == 0)  ActiveRecordMediator<map_views_options>.Save(view.options);

            Flash["view"]    = view;
            Flash["tags"]    = view;
            Flash["authors"] = view;
            //ActiveRecordMediator<map_views>.Update(view);



            if (cancel != null)
            {
                HelperService.writelog("Canceled changes mapview", view.id);
                view.editing = null;
                ActiveRecordMediator <map_views> .Save(view);

                RedirectToAction("list");
                return;
            }
            if (view.name == null || view.name.Length == 0)
            {
                //Flash["error"] = "You are missing the basic parts of a view";
                //RedirectToReferrer();
                //return;
            }
            if (forced_tmp && view.id == 0)
            {
                view.tmp = true;
            }
            else
            {
                view.tmp = false;
                string       gemSql       = "POINT (" + LongLength + " " + Length + ")";
                string       wkt          = gemSql;
                SqlChars     udtText      = new SqlChars(wkt);
                SqlGeography sqlGeometry1 = SqlGeography.STGeomFromText(udtText, 4326);

                MemoryStream ms  = new MemoryStream();
                BinaryWriter bw  = new BinaryWriter(ms);
                byte[]       WKB = sqlGeometry1.STAsBinary().Buffer;
                view.center = geometrics.AsByteArray(sqlGeometry1);//WKB;//
            }



            //view.tags.Clear();
            //view.Images.Clear();


            users user = userService.getUserFull();

            view.authors.Clear();
            if (apply != null)
            {
            }
            else
            {
                view.editing = null;
            }

            if (view.id == 0)
            {
                if (!userService.checkPrivilege("can_publish") || view.status == null)
                {
                    status stat = ActiveRecordBase <status> .Find(1);

                    view.status = stat;
                }
                view.creation_date = DateTime.Now;
            }
            else
            {
                view.updated_date = DateTime.Now;
            }

            /* foreach (authors author in authors){
             *   if (author.id > 0)
             *       view.authors.Add(author);
             * }*/
            view.authors.Add(user);
            if (HelperService.alias_exsits(view.alias, this.GetType().Name).Length > 1)
            {
                view.alias = view.alias + "1";
                ActiveRecordMediator <map_views> .Save(view);

                Flash["error"] = "The url you choose is in use.  Please choose a new one.  We have saved it as '" + view.alias + "1" + "' currently.";
                if (apply != " Save ")
                {
                    RedirectToUrl("~/view/_edit.castle?id=" + view.id);
                }
                else
                {
                    RedirectToReferrer();
                }
                return;
            }

            /*
             * //map_views_options tmp = view.options;
             * var jss = new JavaScriptSerializer();
             * var json = jss.Serialize(tmp);
             * view.options_obj = json;
             */
            Dictionary <string, string> urlparams = getPostParmasAsObj_obj("options");
            var jss = new JavaScriptSerializer();
            //jss.RegisterConverters(new JavaScriptConverter[] { new DynamicJsonConverter() });

            //var values = new Dictionary<string, object>();
            MyJsonDictionary <String, Object> values = new MyJsonDictionary <String, Object>();

            foreach (KeyValuePair <string, string> _urlparams in urlparams)
            {
                values.Add(_urlparams.Key, _urlparams.Value);
            }
            view.options_obj = Serialize(values);//jss.Serialize(usettings);

            if (view.geometrics != null)
            {
                view.geometrics.Clear();
                foreach (int newItem in geolist)
                {
                    view.geometrics.Add(ActiveRecordBase <geometrics> .Find(newItem));
                }
            }
            if (view.places != null)
            {
                view.places.Clear();
                foreach (int newItem in placelist)
                {
                    view.places.Add(ActiveRecordBase <place> .Find(newItem));
                }
            }



            ActiveRecordMediator <map_views> .Save(view);

            string appPath   = getRootPath();
            String cachePath = appPath + "cache/embeds/";
            string file      = HelperService.CalculateMD5Hash(view.alias) + ".ext";
            String file_path = cachePath + file;

            if (File.Exists(file_path))
            {
                File.Delete(file_path);
            }

            cleanUpview_media(view.id);

            Flash["view"]    = null;
            Flash["tags"]    = null;
            Flash["authors"] = null;


            if (apply != null)
            {
                HelperService.writelog("Applied changes mapview ", view.id);
                if (apply != " Save ")
                {
                    RedirectToUrl("~/view/_edit.castle?applied=true&id=" + view.id);
                }
                else
                {
                    RedirectToUrl("~/view/_edit.castle?applied=true"); //RedirectToReferrer();
                }
            }
            else
            {
                view.editing = null;
                ActiveRecordMediator <map_views> .Save(view);

                HelperService.writelog("Saved mapview ", view.id);
                RedirectToAction("list");
            }
        }