public ActionResult SaveShadowStyling(int widgetidshadows, ShadowSettings mdl) { if (ModelState.IsValid) { var item = _contentManager.Get<CustomStyle>(widgetidshadows); if (item != null) { string css = item.CssStyle; if (string.IsNullOrWhiteSpace(css)) css = string.Empty; //parse var col = ParseStringTocssCollection(css); //properties (box-shadow: 50px 50px 50px 5px black;) //clear any previous instanses if (col.ContainsKey("box-shadow")) col.Remove("box-shadow"); //build shadow rule string shadowrule = string.Format("{0}px {1}px {2}px {3}px {4}", mdl.HorizontalOffset, mdl.VerticalOffset, mdl.Blur, mdl.Size, mdl.ShadowColor); // add css styles from model col.Add("box-shadow", shadowrule); //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 ShadowStyling(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 ShadowSettings(); if (col.ContainsKey("box-shadow")) { //parse string shadowvals = col["box-shadow"]; string[] shadowvalsArray = shadowvals.Split(Convert.ToChar(" ")); mdl.HorizontalOffset = Convert.ToInt32(shadowvalsArray[0]); mdl.VerticalOffset= Convert.ToInt32(shadowvalsArray[1]); mdl.Blur= Convert.ToInt32(shadowvalsArray[2]); mdl.Size = Convert.ToInt32(shadowvalsArray[3]); mdl.ShadowColor= shadowvalsArray[4]; } return PartialView(mdl); } return null; }