public ActionResult SaveBorderStyling(int widgetidborders, BorderSettings mdl)
        {

            if (ModelState.IsValid)
            {
                var item = _contentManager.Get<CustomStyle>(widgetidborders);
                if (item != null)
                {
                    string css = item.CssStyle;
                    if (string.IsNullOrWhiteSpace(css)) css = string.Empty;
                    //parse
                    var col = ParseStringTocssCollection(css);
                    //properties (border: 50px 50px 50px 5px;)

                    //clear any previous border-width instanses
                    if (col.ContainsKey("border-width")) col.Remove("border-width");
                    //build border-width rule
                    if (mdl.WidthSameForAll == true)
                    {
                        string borderwidthrule = string.Format("{0}px", mdl.WidthTop);
                        // add css styles from model
                        col.Add("border-width", borderwidthrule);
                    }

                    else
                    {
                        string borderwidthrule = string.Format("{0}px {1}px {2}px {3}px", mdl.WidthTop, mdl.WidthRight, mdl.WidthBottom, mdl.WidthLeft);
                        // add css styles from model
                        col.Add("border-width", borderwidthrule);
                    }



                    //clear any previous border-color instanses
                    if (col.ContainsKey("border-color")) col.Remove("border-color");
                    //build border-width rule
                    if (mdl.ColorSameForAll == true)
                    {
                        string bordercolorrule = string.Format("{0}", mdl.ColorTop);
                        // add css styles from model
                        col.Add("border-color", bordercolorrule);
                    }

                    else
                    {
                        string bordercolorrule = string.Format("{0} {1} {2} {3}", mdl.ColorTop, mdl.ColorRight, mdl.ColorBottom, mdl.ColorLeft);
                        // add css styles from model
                        col.Add("border-color", bordercolorrule);
                    }


                    //clear any previous border-style instanses
                    if (col.ContainsKey("border-style")) col.Remove("border-style");
                    //build border-width rule
                    if (mdl.StyleSameForAll == true)
                    {
                        string borderstylerule = string.Format("{0}", mdl.StyleTop);
                        // add css styles from model
                        col.Add("border-style", borderstylerule);
                    }

                    else
                    {
                        string borderstylerule = string.Format("{0} {1} {2} {3}", mdl.StyleTop, mdl.StyleRight, mdl.StyleBottom, mdl.StyleLeft);
                        // add css styles from model
                        col.Add("border-style", borderstylerule);
                    }


                    //clear any previous border-radius instanses
                    if (col.ContainsKey("border-radius")) col.Remove("border-radius");
                    //build border-width rule
                    if (mdl.RadiusSameForAll == true)
                    {
                        string borderradiusrule = string.Format("{0}px", mdl.RadiusTop);
                        // add css styles from model
                        col.Add("border-radius", borderradiusrule);
                    }

                    else
                    {
                        string borderradiusrule = string.Format("{0}px {1}px {2}px {3}px", mdl.RadiusTop, mdl.RadiusRight, mdl.RadiusBottom, mdl.RadiusLeft);
                        // add css styles from model
                        col.Add("border-radius", borderradiusrule);
                    }

                    //serialize back
                    item.CssStyle = CssCollectionTostring(col);


                    _repo.Update(item.Record);

                    return Json(new { s = "Saved settings!" });
                }
            }
            else
            {
                //model state is not valid
                return Json(new { s = PrepareErrMsg(ModelState) });

            }
 
            return null;


        }
        public ActionResult BordersStyling(int widgetid)
        {
            var item = _contentManager.Get<CustomStyle>(widgetid);

            if (item != null)
            {

                string css = item.CssStyle;
                //parse
                if (string.IsNullOrWhiteSpace(css)) css = string.Empty;
                //strip out the px symbol
                css = css.Replace("px", "");
                var col = ParseStringTocssCollection(css);
                ViewBag.widgetid = widgetid;


                var mdl = new BorderSettings();

                //border-width
                if (col.ContainsKey("border-width"))
                {
                    //parse 

                    string borderwidthvals = col["border-width"];

                    string[] borderwidthvalsArray = borderwidthvals.Split(Convert.ToChar(" "));

                    if (borderwidthvalsArray.Count() == 1)
                    {
                        mdl.WidthSameForAll = true;
                        mdl.WidthTop = Convert.ToInt32(borderwidthvalsArray[0]);


                    }
                    else
                    {
                        mdl.WidthSameForAll = false;
                        mdl.WidthTop = Convert.ToInt32(borderwidthvalsArray[0]);
                        mdl.WidthRight = Convert.ToInt32(borderwidthvalsArray[1]);
                        mdl.WidthBottom = Convert.ToInt32(borderwidthvalsArray[2]);
                        mdl.WidthLeft = Convert.ToInt32(borderwidthvalsArray[3]);
                    }

                }

                //border-color
                if (col.ContainsKey("border-color"))
                {
                    //parse 

                    string bordercolorvals = col["border-color"];

                    string[] bordercolorvalsArray = bordercolorvals.Split(Convert.ToChar(" "));

                    if (bordercolorvalsArray.Count() == 1)
                    {
                        mdl.ColorSameForAll = true;
                        mdl.ColorTop =  bordercolorvalsArray[0] ;


                    }
                    else
                    {
                        mdl.ColorSameForAll = false;
                        mdl.ColorTop =  bordercolorvalsArray[0];
                        mdl.ColorRight =  bordercolorvalsArray[1];
                        mdl.ColorBottom =  bordercolorvalsArray[2];
                        mdl.ColorLeft =  bordercolorvalsArray[3];
                    }

                }

                //border-style
                if (col.ContainsKey("border-style"))
                {
                    //parse 

                    string borderstylevals = col["border-style"];

                    string[] borderstylevalsArray = borderstylevals.Split(Convert.ToChar(" "));

                    if (borderstylevalsArray.Count() == 1)
                    {
                        mdl.StyleSameForAll = true;
                        mdl.StyleTop =  borderstylevalsArray[0] ;


                    }
                    else
                    {
                        mdl.StyleSameForAll = false;
                        mdl.StyleTop =  borderstylevalsArray[0] ;
                        mdl.StyleRight =  borderstylevalsArray[1] ;
                        mdl.StyleBottom =  borderstylevalsArray[2] ;
                        mdl.StyleLeft = borderstylevalsArray[3] ;
                    }

                }


                //border-radius
                if (col.ContainsKey("border-radius"))
                {
                    //parse 

                    string borderradiusvals = col["border-radius"];

                    string[] borderradiusvalsArray = borderradiusvals.Split(Convert.ToChar(" "));

                    if (borderradiusvalsArray.Count() == 1)
                    {
                        mdl.RadiusSameForAll = true;
                        mdl.RadiusTop = Convert.ToInt32(borderradiusvalsArray[0]);


                    }
                    else
                    {
                        mdl.RadiusSameForAll = false;
                        mdl.RadiusTop = Convert.ToInt32(borderradiusvalsArray[0]);
                        mdl.RadiusRight = Convert.ToInt32(borderradiusvalsArray[1]);
                        mdl.RadiusBottom = Convert.ToInt32(borderradiusvalsArray[2]);
                        mdl.RadiusLeft = Convert.ToInt32(borderradiusvalsArray[3]);
                    }

                }

                return PartialView(mdl);
            }

            return null;
        }