public int Save(ContentBindingList Model) { using (var _c = db) { var _CP = new ContentProperty { ContentPropertyParentID = Model.ContentPropertyParentID, SiteID = Model.SiteID, ContentPropertyType = Model.ContentPropertyType, ContentPropertyAlias = Model.ContentPropertyAlias, Priority = Model.Priority, Lock = Model.Lock, ShowInContent = Model.ShowInContent, Enabled = true }; _c.ContentProperties.Add(_CP); _c.SaveChanges(); //SAVE ROOT AddRoot(_CP.ContentPropertyID, _CP.ContentPropertyParentID); var _NumCultureSite = _c.Cultures.Where(m => m.SiteID == Model.SiteID).Count(); if (_NumCultureSite < Model.ContentCultures.Count()) throw new RuleException(ContentRuleExceptionCode.MORECULTURES.ToString(), "Content Alias:" + Model.ContentPropertyAlias + " with " + Model.ContentCultures.Count() + " and Site have " + _NumCultureSite + " Cultures"); foreach (var item in Model.ContentCultures) { item.ContentPropertyID = _CP.ContentPropertyID; SaveCulture(item, Model.SiteID); } return _CP.ContentPropertyID; } }
private int Duplicate(int ContentPropertyID, int ContentPropertyParentID, Boolean ShowInContent) { using (var _c = db) { var _CP = _c.ContentProperties.Where(m => m.ContentPropertyID == ContentPropertyID).SingleOrDefault(); var _IQParent = _c.ContentProperties.Where(m => m.ContentPropertyParentID == ContentPropertyParentID); var _CPNew = new ContentProperty { ContentPropertyAlias = _CP.ContentPropertyAlias, ContentPropertyParentID = ContentPropertyParentID, SiteID = _CP.SiteID, ContentPropertyType = _CP.ContentPropertyType, Priority = _IQParent.Any() ? _IQParent.Select(m => m.Priority).Max() + 1 : 0, Enabled = _CP.Enabled }; if (ShowInContent) _CPNew.ShowInContent = _CP.ShowInContent; _c.ContentProperties.Add(_CPNew); _c.SaveChanges(); //DUPLICATE ROOT DuplicateRoot(_CPNew.ContentPropertyID, ContentPropertyParentID); //COPY CULTURES var _CPC = _c.ContentPropertyCultures.Where(m => m.ContentPropertyID == ContentPropertyID).ToList(); foreach (var item in _CPC) { _c.ContentPropertyCultures.Add(new ContentPropertyCulture { ContentPropertyID = _CPNew.ContentPropertyID, CultureID = item.CultureID, ContentPropertyValue = item.ContentPropertyValue, Hint = item.Hint }); } _c.SaveChanges(); //Make the same with childs var _CPChilds = _c.ContentProperties.Where(m => m.ContentPropertyParentID == ContentPropertyID).OrderBy(m=>m.Priority).ToList(); foreach (var item in _CPChilds) { Duplicate(item.ContentPropertyID, _CPNew.ContentPropertyID, true); } return _CPNew.ContentPropertyID; } }
public int Save(ContentBinding Model) { using (var _c = db) { var _Model = new ContentProperty(); if (Model.ContentPropertyID == 0) { var _IQParent = _c.ContentProperties.Where(m => m.SiteID == Model.SiteID && m.ContentPropertyParentID == Model.ContentPropertyParentID); _Model.ContentPropertyParentID = Model.ContentPropertyParentID; _Model.SiteID = Model.SiteID; _Model.Priority = _IQParent.Any() ? _IQParent.Select(m => m.Priority).Max() + 1 : 0; _Model.Lock = Model.Lock; _Model.Enabled = true; _c.ContentProperties.Add(_Model); } else { _Model = _c.ContentProperties.Where(m => m.ContentPropertyID == Model.ContentPropertyID).SingleOrDefault(); _Model.Priority = Model.Priority; } _Model.ContentPropertyAlias = Model.ContentPropertyAlias; _Model.ContentPropertyType = Model.ContentPropertyType; _c.SaveChanges(); //SAVE ROOT AddRoot(_Model.ContentPropertyID, _Model.ContentPropertyParentID); return _Model.ContentPropertyID; } }