Example #1
0
        /// <summary>
        /// Adds a new comment to the article specifed with given id
        /// </summary>
        /// <param name="id">comment id</param>
        /// <param name="form">form containing data</param>
        /// <param name="ip">Client IP address</param>
        /// <returns></returns>
        public bool add(long id, Form_Comment_New form, string ip)
        {
            comment c = new comment();
            c.useralias = form["name"].getValue();
            c.title = form["title"].getValue();
            c.text = form["text"].getValue();
            c.parentid = null;
            c.ip = ip;
            c.email = form["email"].getValue();
            c.articlesid = id;

            if (this._app.users().isLogged())
            {
                c.usersid = this._app.users().getLogged().id;
            }

            try
            {
                using (LangDataContext a = new LangDataContext())
                {
                    a.comments.InsertOnSubmit(c);
                    a.SubmitChanges();
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
Example #2
0
        /// <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 (LangDataContext a = new LangDataContext())
            {
                a.categories.InsertOnSubmit(c);
                try
                {
                    a.SubmitChanges();
                }
                catch (Exception)
                {
                    return false;
                }
            }

            return true;
        }
Example #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public void deleteArticle(long id)
        {
            using (LangDataContext a = new LangDataContext())
            {
                a.articles.DeleteAllOnSubmit(a.articles.Where(x => x.id == id));

                try
                {
                    a.SubmitChanges();
                }
                catch(Exception)
                {
                    CMS.Services.CMS_Services_Message.getInstance().addError("The article hasn't been deleted.");
                }
            }
        }
Example #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="form"></param>
        /// <param name="Request"></param>
        /// <returns></returns>
        public bool saveArticle(CMS_Form form, HttpRequestBase Request)
        {
            long id = long.Parse(Request.Params["id"]);

            using (LangDataContext dataContext = new LangDataContext())
            {

                DateTime published = this._app.dateFromString(form["published"].getValue());
                DateTime pullback = this._app.dateFromString(form["pullback"].getValue());

                try
                {
                    article original = dataContext.articles.Where(x => x.id == id).Single();
                    article modified = dataContext.articles.Where(x => x.id == id).Single();

                    modified.date_published = published;
                    modified.date_lastmod = DateTime.Now;
                    modified.alias = this._app.makeAlias(form["title"].getValue());
                    modified.date_pullback = pullback;
                    modified.fulltext = form["text"].getValue();
                    modified.modifications_count++;
                    modified.title = form["title"].getValue();
                    modified.introtext = form["perex"].getValue();
                    modified.level = int.Parse(form["roles"].getValue());
                    modified.published = int.Parse(form["published_bool"].getValue());

                    dataContext.articles_authors.DeleteAllOnSubmit(dataContext.articles_authors.Where(x => x.articlesid == id));

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

                    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;
                        modified.articles_authors.Add(authorArticles);
                    }

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

                    dataContext.tags_articles.DeleteAllOnSubmit(dataContext.tags_articles.Where(x => x.articlesid == id));

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

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

                            dataContext.tags.InsertOnSubmit(newTag);

                            try
                            {
                                dataContext.SubmitChanges();
                            }
                            catch
                            {
                                return false;
                            }

                            tagId = newTag.id;
                        }

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

                        dataContext.tags_articles.InsertOnSubmit(tagArticle);

                    }

                    dataContext.articles_categories.DeleteAllOnSubmit(dataContext.articles_categories.Where(x => x.articlesid == id));

                    try
                    {
                        dataContext.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;

                        dataContext.articles_categories.InsertOnSubmit(articleCategory);
                    }

                    try
                    {
                        dataContext.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");
                        }
                    }

                }
                catch(InvalidOperationException) {
                    CMS_Services_Message.getInstance().addError("Article with specified ID does not exit");
                    return false;
                }

            }

            return true;
        }
Example #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="a"></param>
        /// <returns></returns>
        public article getById(long id, LangDataContext a)
        {
            using (a)
            {
                try
                {
                    var data = a.articles
                        .Single(x => x.id == id);

                    data.hits++;

                    try
                    {
                        a.SubmitChanges();
                    }
                    catch (Exception)
                    {
                    }

                    return data;
                }
                catch (Exception)
                {
                    return null;
                }
            }
        }
Example #6
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;

            }
        }
Example #7
0
        public long add(PageInputModel input)
        {
            using (LangDataContext dataContext = new LangDataContext())
            {
                page p = new page();

                text title = new text();
                text content = new text();

                dataContext.pages.InsertOnSubmit(p);
                dataContext.texts.InsertOnSubmit(title);
                dataContext.texts.InsertOnSubmit(content);

                p.text = title;
                p.text1 = content;

                foreach (PageInputModel.Page newPage in input.request)
                {
                    texts_value titleValue = new texts_value();
                    titleValue.culture = newPage.lang;
                    titleValue.value = newPage.data.title;
                    titleValue.text = title;
                    titleValue.seo_value = this._app.makeAlias(newPage.data.title);

                    texts_value contentValue = new texts_value();
                    contentValue.culture = newPage.lang;
                    contentValue.value = newPage.data.content;
                    contentValue.text = content;

                    dataContext.texts_values.InsertOnSubmit(titleValue);
                    dataContext.texts_values.InsertOnSubmit(contentValue);
                }

                dataContext.SubmitChanges();

                return p.id;

            }
        }
Example #8
0
        /// <summary>
        /// Saves a reply to a comment with the given id
        /// </summary>
        /// <param name="id">Comment id</param>
        /// <param name="form">Reply data</param>
        /// <param name="aid">Article id</param>
        /// <param name="ip">Client IP address</param>
        /// <returns></returns>
        public bool reply(long id, Form_Comment_New form, string ip, out long aid)
        {
            comment c = new comment();
            c.useralias = form["name"].getValue();
            c.title = form["title"].getValue();
            c.text = form["text"].getValue();
            c.parentid = id;
            c.ip = ip;
            c.email = form["email"].getValue();

            if (this._app.users().isLogged())
            {
                c.usersid = this._app.users().getLogged().id;
            }

            try
            {
                using (LangDataContext a = new LangDataContext())
                {
                    comment replied = a.comments.Where(x => x.id == id).Single();
                    aid = c.articlesid = replied.articlesid;
                    a.comments.InsertOnSubmit(c);
                    a.SubmitChanges();
                }
            }
            catch
            {
                aid = 0;
                return false;
            }

            return true;
        }
Example #9
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;
        }
Example #10
0
        /// <summary>
        /// Deletes a category specified by the given id
        /// </summary>
        /// <param name="id">category id</param>
        /// <returns>success</returns>
        public Object delete(long id)
        {
            using (LangDataContext u = new LangDataContext())
            {
                try
                {
                    u.categories.DeleteAllOnSubmit(u.categories.Where(x => x.id == id));
                    u.SubmitChanges();
                }
                catch(Exception e)
                {
                    return new { result = false, errorMsg = e.Message };
                }

                return new { result = true };
            }
        }
Example #11
0
        /// <summary>
        /// Save changes to the given author
        /// </summary>
        /// <param name="form">Author data</param>
        /// <param name="edited">Edited author</param>
        /// <returns>success</returns>
        public bool saveAuthor(Form_Author_Add form, author edited)
        {
            author toSave = new author();
            toSave.id = edited.id;
            toSave.lastname = form["lastname"].getValue();
            toSave.description = form["description"].getValue();
            toSave.name = form["name"].getValue();
            toSave.usersid = edited.usersid;
            toSave.date = edited.date;

            using (LangDataContext a = new LangDataContext())
            {
                a.authors.Attach(toSave, edited);
                try
                {
                    a.SubmitChanges();
                }
                catch (Exception)
                {
                    return false;
                }

                return true;
            }
        }
Example #12
0
 /// <summary>
 /// Removes an author from the system (if there is no article written by him - DB FK)
 /// </summary>
 /// <param name="id">User id</param>
 /// <returns>success</returns>
 public bool removeAuthorByUserId(long id)
 {
     using (LangDataContext a = new LangDataContext())
     {
         a.authors.DeleteAllOnSubmit(a.authors.Where(x => x.usersid == id));
         try
         {
             a.SubmitChanges();
         }
         catch (Exception)
         {
             return false;
         }
     }
     return true;
 }
Example #13
0
        /// <summary>
        /// Adds an author to the system
        /// </summary>
        /// <param name="form">Author data</param>
        /// <param name="id">User id</param>
        /// <returns>success</returns>
        public bool promoteUser(Form_Author_Add form, long id)
        {
            using (LangDataContext a = new LangDataContext())
            {
                author toSave = new author();
                toSave.date = DateTime.Now;
                toSave.description = form["description"].getValue();
                toSave.lastname = form["lastname"].getValue();
                toSave.name = form["name"].getValue();
                toSave.usersid = id;

                a.authors.InsertOnSubmit(toSave);
                try
                {
                    a.SubmitChanges();
                }
                catch(Exception e)
                {
                    CMS.Services.CMS_Services_Message.getInstance().addError(e.Message);
                    return false;
                }
            }

            return true;
        }
Example #14
0
        public bool delete(long id)
        {
            using (LangDataContext dataContext = new LangDataContext())
            {
                dataContext.pages.DeleteOnSubmit(dataContext.pages.Where(x => x.id == id).Single());

                dataContext.SubmitChanges();

                return true;
            }
        }
Example #15
0
        public object edit(InputModels.ProductInputModel p)
        {
            try
            {
                using (LangDataContext dc = new LangDataContext())
                {

                    var prod = dc.products.Single(x => x.id == p.prodId);

                    foreach (string lang in Helpers.LangHelper.langs)
                    {
                        prod.text_title.texts_values.Single(x => x.culture == lang).value = p.request.Single(x => x.lang == lang).data.Title;
                        prod.text_subtitle.texts_values.Single(x => x.culture == lang).value = p.request.Single(x => x.lang == lang).data.Subtitle;
                        prod.text_description.texts_values.Single(x => x.culture == lang).value = p.request.Single(x => x.lang == lang).data.Shortdesc;
                        prod.text_text.texts_values.Single(x => x.culture == lang).value = p.request.Single(x => x.lang == lang).data.Content;
                    }

                    if (p.docGroups != null)
                    {
                        foreach (docgroups_product dgp in prod.docgroups_products.Where(x => p.docGroups.Where(u => u.Id == x.docgroup_id).Count() == 0))
                        {
                            prod.docgroups_products.Remove(dgp);
                        }

                        foreach (InputModels.DocGroupInputModel dg in p.docGroups)
                        {
                            if (dg.Id == null || prod.docgroups_products.Where(x => x.docgroup_id == dg.Id).Count() > 0) continue;

                            docgroups_product dgp = new docgroups_product();
                            dgp.docgroup_id = (long)dg.Id;
                            dgp.product = prod;
                        }
                    }

                    foreach (products_connection pdc in prod.products_connections.Where(x => !p.Connections.Contains(x.product_id)))
                    {
                        prod.products_connections.Remove(pdc);
                    }

                    foreach (long conn in p.Connections)
                    {
                        if (prod.products_connections.Select(x => x.product_id_2).Contains(conn)) continue;

                        products_connection prodConn = new products_connection();
                        prodConn.product = prod;
                        prodConn.product_id_2 = conn;
                    }

                    prod.image_id = p.mainImage;

                    dc.products.InsertOnSubmit(prod);

                    dc.SubmitChanges();

                    return new { result = true };
                }
            }
            catch (Exception e)
            {
                return new { result = false, errMsg = e.Message };
            }
        }
Example #16
0
        public object add(InputModels.ProductInputModel p)
        {
            using (LangDataContext dc = new LangDataContext())
            {
                product prod = new product();
                prod.text_title = new text();
                prod.text_subtitle = new text();
                prod.text_description = new text();
                prod.text_text = new text();

                foreach (InputModels.ProductInputModel.Product inProd in p.request)
                {
                    texts_value titleval = new texts_value();
                    titleval.culture = inProd.lang;
                    titleval.value = inProd.data.Title;
                    titleval.text = prod.text_title;
                    titleval.seo_value = this._app.makeAlias(inProd.data.Title);

                    texts_value subtitleval = new texts_value();
                    subtitleval.culture = inProd.lang;
                    subtitleval.value = inProd.data.Subtitle;
                    subtitleval.text = prod.text_subtitle;

                    texts_value descval = new texts_value();
                    descval.culture = inProd.lang;
                    descval.value = inProd.data.Shortdesc;
                    descval.text = prod.text_description;

                    texts_value textval = new texts_value();
                    textval.culture = inProd.lang;
                    textval.value = inProd.data.Content;
                    textval.text = prod.text_text;
                }

                if (p.docGroups != null)
                {
                    foreach (InputModels.DocGroupInputModel dg in p.docGroups)
                    {
                        if (dg.Id == null) continue;

                        docgroups_product dgp = new docgroups_product();
                        dgp.docgroup_id = (long)dg.Id;
                        dgp.product = prod;
                    }
                }

                foreach (long cat in p.Categories)
                {
                    products_category pc = new products_category();
                    pc.product = prod;
                    pc.category_id = cat;
                }

                foreach (long conn in p.Connections)
                {
                    products_connection prodConn = new products_connection();
                    prodConn.product = prod;
                    prodConn.product_id_2 = conn;
                }

                prod.image_id = p.mainImage;

                dc.products.InsertOnSubmit(prod);

                dc.SubmitChanges();

                return new { Id = prod.id };
            }
        }
Example #17
0
        /// <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 (LangDataContext a = new LangDataContext())
            {
                a.categories.Attach(newCat, c);
                try
                {
                    a.SubmitChanges();
                }
                catch (Exception)
                {
                    return false;
                }
            }

            return true;
        }
Example #18
0
        public object setParent(long? id, long? parentId)
        {
            try
            {
                using (LangDataContext dc = new LangDataContext())
                {
                    dc.categories.Single(x => x.id == id).parentid = parentId;
                    dc.SubmitChanges();

                    return new { result = true };
                }
            }
            catch (Exception e)
            {
                return new { result = false, errMsg = e.Message };
            }
        }
Example #19
0
        public bool edit(PageInputModel input)
        {
            using (LangDataContext dC = new LangDataContext())
            {
                page p = dC.pages.Where(x => x.id == input.request[0].Id).Single();

                foreach (string lang in Helpers.LangHelper.langs)
                {
                    var titleTxt = p.text.texts_values.SingleOrDefault(x => x.culture == lang);
                    var txtTxt = p.text1.texts_values.SingleOrDefault(x => x.culture == lang);

                    if (titleTxt == null)
                    {
                        titleTxt = new texts_value();
                        titleTxt.culture = lang;
                        titleTxt.text = p.text;
                    }

                    if (txtTxt == null)
                    {
                        txtTxt = new texts_value();
                        txtTxt.culture = lang;
                        txtTxt.text = p.text1;
                    }

                    titleTxt.value = input.request.Single(x => x.lang == lang).data.title;
                    titleTxt.seo_value = this._app.makeAlias(input.request.Single(x => x.lang == lang).data.title);

                    txtTxt.value = input.request.Single(x => x.lang == lang).data.content;
                }

                dC.SubmitChanges();
            }

            return true;
        }