public CategoryOutputModel(category c) { this.Id = c.id; this.Title = new LangOutputModel(c.title); this.Content = new LangOutputModel(c.text); this.Parent = c.parentid; }
/// <summary> /// Adds a new child for the given parent category /// </summary> /// <param name="parent">parent category (0 for root)</param> /// <param name="form">form containig data</param> /// <returns></returns> public bool add(long parent, Form_Category_Add form) { category c = new category(); c.date = DateTime.Now; c.parentid = parent; if (parent == 0) { c.parentid = null; } c.name = form["name"].getValue(); c.alias = this._app.makeAlias(form["name"].getValue()); using (ArticleDataContext a = new ArticleDataContext()) { a.categories.InsertOnSubmit(c); try { a.SubmitChanges(); } catch (Exception) { return false; } } return true; }
public CategorizedProductOutputModel(category root) { Category = new CategoryOutputModel(root); Subcategories = new List<CategorizedProductOutputModel>(); foreach (category c in root.categories.Where(x => x.category1 == root)) { Subcategories.Add(new CategorizedProductOutputModel(c)); } Products = new List<ProductOutputModel>(); foreach (product p in root.products_categories.Select(x => x.product)) { Products.Add(new ProductOutputModel(p)); } }
public long add(CategoryInputModel input) { using (LangDataContext dataContext = new LangDataContext()) { category c = new category(); text title = new text(); text content = new text(); dataContext.categories.InsertOnSubmit(c); dataContext.texts.InsertOnSubmit(title); dataContext.texts.InsertOnSubmit(content); c.text = content; c.title = title; foreach (CategoryInputModel.Category cat in input.request) { texts_value titleValue = new texts_value(); titleValue.culture = cat.lang; titleValue.value = cat.data.Title; titleValue.text = title; titleValue.seo_value = this._app.makeAlias(cat.data.Title); texts_value contentValue = new texts_value(); contentValue.culture = cat.lang; contentValue.value = cat.data.Content; contentValue.text = content; dataContext.texts_values.InsertOnSubmit(titleValue); dataContext.texts_values.InsertOnSubmit(contentValue); } c.parentid = input.catParent; c.date = DateTime.Now; dataContext.SubmitChanges(); return c.id; } }
partial void Deletecategory(category instance);
partial void Updatecategory(category instance);
partial void Insertcategory(category instance);
private void detach_categories(category entity) { this.SendPropertyChanging(); entity.category1 = null; }
private void attach_categories(category entity) { this.SendPropertyChanging(); entity.category1 = this; }
/// <summary> /// Save changes for the given category /// </summary> /// <param name="form">form containing data</param> /// <param name="c">category</param> /// <returns>success</returns> public bool save(Form_Category_Add form, category c) { category newCat = new category(); newCat.id = c.id; if (c.parentid.HasValue) { newCat.parentid = c.parentid; } newCat.name = form["name"].getValue(); newCat.date = c.date; using (ArticleDataContext a = new ArticleDataContext()) { a.categories.Attach(newCat, c); try { a.SubmitChanges(); } catch (Exception) { return false; } } return true; }
/// <summary> /// Sets data for edit mode /// </summary> /// <param name="edited">edited entity</param> public void setEditData(category c) { this._action = new CMS_Action("/backend/editCategory?id=" + c.id); this._elements["name"].setValue(c.name); this._elements["ok"].setLabel("Save changes"); }
public CategoryOutputModel fillCategoryModel(category c) { if (c == null) return null; CategoryOutputModel om = new CategoryOutputModel(); om.Id = c.id; om.Parent = c.parentid; om.Content = this._app.fillLangModel(c.text.texts_values); om.Title = this._app.fillLangModel(c.title.texts_values); return om; }