Beispiel #1
0
        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;

            }
        }
Beispiel #2
0
 public ActionResult EditCategoryAjax(CategoryInputModel input)
 {
     return Json(new {result = this._app.categories().edit(input)});
 }
Beispiel #3
0
        public bool edit(CategoryInputModel input)
        {
            using (LangDataContext dc = new LangDataContext())
            {
                category c = dc.categories.Single(x => x.id == input.catId);

                foreach (String lang in Helpers.LangHelper.langs)
                {
                    texts_value titleval = c.title.texts_values.SingleOrDefault(x => x.culture == lang);
                    string value = input.request.Single(x => x.lang == lang).data.Title;

                    if (titleval == null)
                    {
                        titleval = new texts_value();
                        titleval.text = c.title;
                        titleval.culture = lang;
                    }

                    titleval.value = value;
                    titleval.seo_value = this._app.makeAlias(value);

                    texts_value text = c.text.texts_values.SingleOrDefault(x => x.culture == lang);
                    if (text == null)
                    {
                        text = new texts_value();
                        text.text = c.text;
                        text.culture = lang;
                    }

                    text.value = input.request.Single(x => x.lang == lang).data.Content;
                }

                dc.SubmitChanges();
            }

            return true;
        }