Exemple #1
0
 partial void Deletearticle(article instance);
Exemple #2
0
 partial void Updatearticle(article instance);
Exemple #3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="OriginalArticle">Edited article</param>
        public Form_Article_Edit(article OriginalArticle)
        {
            _action = new CMS_Action("/backend/editArticle?id="+OriginalArticle.id.ToString());

            CMS_Form_Element_Textbox title = new CMS_Form_Element_Textbox("title");
            title.setLabel("Title");
            title.setRequired();
            title.setValue(OriginalArticle.title);
            title.addValidator(new CMS_Validator_StringLength(0, 100));

            this.addElement(title);

            CMS_Form_Element_Textarea perex = new CMS_Form_Element_Textarea("perex");
            perex.setRequired();
            perex.setValue(OriginalArticle.introtext);
            perex.setLabel("Introtext");
            perex.setClass("ckeditor");

            CMS_Validator_StringLength v = new CMS_Validator_StringLength();
            v.setMaxLength(1000);
            perex.addValidator(v);

            this.addElement(perex);

            CMS_Form_Element_Textarea text = new CMS_Form_Element_Textarea("text");
            text.setRequired();
            text.setValue(OriginalArticle.fulltext);
            text.setLabel("Text");
            text.setClass("ckeditor");

            this.addElement(text);

            CMS_Form_Element_Select authors = new CMS_Form_Element_Select("authors");
            authors.setIsMultiSelect();
            authors.setLabel("Authors");
            authors.setSize(4);
            authors.setRequired();

            this.addElement(authors);

            CMS_Form_Element_Select categories = new CMS_Form_Element_Select("categories");
            categories.setIsMultiSelect();
            categories.setLabel("Categories");
            categories.setSize(4);
            categories.setRequired();

            this.addElement(categories);

            CMS_Form_Element_DateTime published = new CMS_Form_Element_DateTime("published");
            published.setRequired();
            published.setValue(OriginalArticle.date_published.ToString());
            published.setLabel("Publish date");

            this.addElement(published);

            CMS_Form_Element_DateTime pullback = new CMS_Form_Element_DateTime("pullback");
            pullback.setLabel("Pullback date");
            pullback.setValue(OriginalArticle.date_pullback.ToString());

            this.addElement(pullback);

            CMS_Form_Element_Select roles = new CMS_Form_Element_Select("roles");
            roles.setRequired();
            roles.setLabel("Role with access to the article");
            roles.setValue("1");

            this.addElement(roles);

            CMS_Form_Element_File smallIcon = new CMS_Form_Element_File("smallIcon");
            smallIcon.setRequired();
            smallIcon.setLabel("Small icon");

            this.addElement(smallIcon);

            CMS_Form_Element_File bigIcon = new CMS_Form_Element_File("bigIcon");
            bigIcon.setRequired();
            bigIcon.setLabel("Big icon");

            this.addElement(bigIcon);

            CMS_Form_Element_Textbox tags = new CMS_Form_Element_Textbox("tags");
            tags.setLabel("Tags (whitespace separated)");

            this.addElement(tags);

            CMS_Form_Element_Select published_bool = new CMS_Form_Element_Select("published_bool");
            published_bool.addOption("0", "No");
            published_bool.addOption("1", "Yes");
            published_bool.setLabel("Published state");

            published_bool.setValue(OriginalArticle.published.ToString());

            this.addElement(published_bool);

            CMS_Form_Element_Submit submit = new CMS_Form_Element_Submit("submit");
            submit.setLabel("Save the article");
            this.addElement(submit);
        }
Exemple #4
0
 partial void Insertarticle(article instance);
Exemple #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        public bool newArticle(CMS_Form form, HttpRequestBase Request)
        {
            DateTime published = this._app.dateFromString(form["published"].getValue());
            DateTime pullback = this._app.dateFromString(form["pullback"].getValue());

            article newArticle = new article();
            newArticle.date_published = published;
            newArticle.date_lastmod = newArticle.date = DateTime.Now;
            newArticle.alias = this._app.makeAlias(form["title"].getValue());
            newArticle.date_pullback = pullback;
            newArticle.fulltext = form["text"].getValue();
            newArticle.hits = 0;
            newArticle.modifications_count = 1;
            newArticle.title = form["title"].getValue();
            newArticle.introtext = form["perex"].getValue();
            newArticle.level = int.Parse(form["roles"].getValue());
            newArticle.published = int.Parse(form["published_bool"].getValue());

            long id;

            using (LangDataContext artDataCntx = new LangDataContext())
            {
                artDataCntx.articles.InsertOnSubmit(newArticle);

                try
                {
                    artDataCntx.SubmitChanges();
                }
                catch (Exception)
                {
                    return false;
                }

                id = newArticle.id;

                foreach (string articleAuthorIdString in ((CMS_Form_Element_Select)form["authors"]).getValues())
                {
                    articles_author authorArticles = new articles_author();
                    authorArticles.articlesid = id;
                    authorArticles.authorsid = long.Parse(articleAuthorIdString);
                    authorArticles.date = DateTime.Now;
                    newArticle.articles_authors.Add(authorArticles);
                }

                string[] tags = form["tags"].getValue().Split(' ');

                foreach (string t in tags)
                {
                    long tagId = 0;
                    try
                    {
                        var tag = artDataCntx.tags.Where(x => x.name == t).Single();
                        tagId = tag.id;
                    }
                    catch (InvalidOperationException)
                    {
                        tag newTag = new tag();
                        newTag.name = t;
                        newTag.date = DateTime.Now;

                        artDataCntx.tags.InsertOnSubmit(newTag);

                        try
                        {
                            artDataCntx.SubmitChanges();
                        }
                        catch (Exception)
                        {
                            return false;
                        }

                        tagId = newTag.id;
                    }

                    tags_article tagArticle = new tags_article();
                    tagArticle.articlesid = id;
                    tagArticle.tagsid = tagId;

                    artDataCntx.tags_articles.InsertOnSubmit(tagArticle);

                }

                try
                {
                    artDataCntx.SubmitChanges();
                }
                catch (Exception)
                {
                    return false;
                }

                CMS_Form_Element_Select cats = (CMS_Form_Element_Select)form["categories"];

                foreach (string cat in cats.getValues())
                {
                    long catId = long.Parse(cat);

                    articles_category articleCategory = new articles_category();
                    articleCategory.date = DateTime.Now;
                    articleCategory.articlesid = id;
                    articleCategory.categoriesid = catId;

                    artDataCntx.articles_categories.InsertOnSubmit(articleCategory);
                }

                try
                {
                    artDataCntx.SubmitChanges();
                }
                catch (Exception)
                {
                    return false;
                }
            }

            if (Request.Files.Count != 2)
            {
                CMS_Services_Message.getInstance().addError("Unexpected count of uploaded files, skipping.");
            }
            else
            {

                HttpPostedFileBase small = Request.Files[0];
                if (small.ContentLength > 0 && small.ContentType == "image/jpeg")
                {
                    string filename = id.ToString();
                    var path = Path.Combine(Request.MapPath("./../images"), filename + "_small.jpg");

                    small.SaveAs(path);

                    System.Drawing.Image i = System.Drawing.Image.FromFile(path);
                    if (i.Width != 100 || i.Height != 100)
                    {
                        CMS_Services_Message.getInstance().addError("Invalid image size - small icon should be 100x100 pixels");
                        FileInfo f = new FileInfo(path);
                        f.Delete();
                    }
                }
                else
                {
                    CMS_Services_Message.getInstance().addError("Invalid image - small icon");
                }

                HttpPostedFileBase big = Request.Files[1];
                if (big.ContentLength > 0 && big.ContentType == "image/jpeg")
                {
                    string filename = id.ToString();
                    var path = Path.Combine(Request.MapPath("./../images"), filename + "_big.jpg");

                    big.SaveAs(path);

                    System.Drawing.Image i = System.Drawing.Image.FromFile(path);
                    if (i.Width != 320 || i.Height != 240)
                    {
                        CMS_Services_Message.getInstance().addError("Invalid image size - big icon should be 320x240 pixels");
                        FileInfo f = new FileInfo(path);
                        f.Delete();
                    }
                }
                else
                {
                    CMS_Services_Message.getInstance().addError("Invalid image - big icon");
                }

            }

            return true;
        }