public static void Insert(Clanci article, List<string> tags)
        {
            Connection.dm.Clanci.Add(article);
            Connection.dm.SaveChanges();

            foreach (string t in tags)
            {
                try
                {
                    Connection.dm.fsp_ClanciTagovi_Insert(article.ClanakID, t);
                }
                catch
                {

                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            List<string> words = new List<string>();
            words.Add("Linux");
            words.Add("Unix");
            words.Add("Ubuntu");

            ExternalIntegration integration = new ExternalIntegration();
            List<WikiP> articlesWiki = new List<WikiP>();
            List<WikiP> articlesWikiRecommend = new List<WikiP>();

            foreach (string w in words)
            {
                articlesWiki.Clear();
                articlesWiki.AddRange(integration.SearchWikipedia(w));
                articlesWikiRecommend.AddRange(articlesWiki.Take(200).ToList());
            }

            articlesWikiRecommend = articlesWikiRecommend.Distinct().ToList();

            List<string> tags = new List<string>();

            tags.Add("Linux");
            tags.Add("Unix");
            tags.Add("Ubuntu");

            foreach (var item in articlesWikiRecommend)
            {
                Clanci clanak = new Clanci();
                clanak.Naslov = item.Name;
                clanak.Tekst = item.Description;
                clanak.Autori = "Wiki";
                clanak.KljucneRijeci = "linux, unix, ubuntu";
                clanak.VrstaID = 4;
                clanak.TemaID = 24;
                clanak.KorisnikID = 21;
                clanak.Status = true;
                clanak.DatumKreiranja = DateTime.Now;
                clanak.DatumIzmjene = DateTime.Now;

                DAClanci.Insert(clanak, tags);
            }
        }
        protected void documentDeleteSubmit_Click(object sender, EventArgs e)
        {
            article = DAClanci.Select(articleId);

            if (article.DokumentPath != null && article.Dokument != null)
            {
                string[] filename = article.DokumentPath.Split('/');
                System.IO.File.Delete(Server.MapPath("/Content/articles/") + filename);

                DAClanci.DeleteDocument(articleId);

                successLabel.Text = "Dokument uspješno uklonjen.";
                error_label.Visible = false;
                success_label.Visible = true;
            }
            else
            {
                warningLabel.Text = "Ne postoji dokument.";
                warning_label.Visible = true;
            }
        }
        protected void saveArticleSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                Clanci article = new Clanci();
                if (typesList.SelectedIndex != 0)
                    article.VrstaID = Convert.ToInt32(typesList.SelectedValue);
                if (themeList.SelectedIndex != 0)
                    article.TemaID = Convert.ToInt32(themeList.SelectedValue);

                article.Naslov = titleInput.Text.Trim();
                article.Autori = authorsInput.Text.Trim();
                article.KljucneRijeci = keyWordsInput.Text.Trim();
                article.DatumKreiranja = DateTime.Now;
                article.DatumIzmjene = DateTime.Now;
                article.Status = true;
                article.KorisnikID = Convert.ToInt32(User.Identity.Name);
                article.Tekst = wysiwyg.InnerText;

                string extension = "";
                if (documentFile.PostedFile != null && documentFile.PostedFile.FileName != null
                          && documentFile.PostedFile.FileName != "")
                {
                    extension = System.IO.Path.GetExtension(documentFile.PostedFile.FileName);
                    if (extension == ".pdf")
                    {
                        article.DokumentType = documentFile.PostedFile.ContentType;
                        article.Dokument = new byte[documentFile.PostedFile.ContentLength];
                        documentFile.PostedFile.InputStream.Read(article.Dokument, 0, documentFile.PostedFile.ContentLength);
                    }
                    else
                    {
                        errorLabel.Text = "Format dokumenta nije podržan.";
                        error_label.Visible = true;
                        return;
                    }
                }

                List<string> tags = new List<string>();

                foreach (string tag in tagsInput.Text.Split(','))
                {
                    if (tag != "")
                        tags.Add(tag.Trim());
                }

                DAClanci.Insert(article, tags);

                if (article.Dokument != null)
                {
                    string filename = article.ClanakID + extension;
                    System.IO.File.WriteAllBytes(Server.MapPath("/Content/articles/") + filename, article.Dokument);
                    article.DokumentPath = "~/Content/articles/" + filename;
                }

                successLabel.Text = "Uspješno ste dodali članak.";
                error_label.Visible = false;
                success_label.Visible = true;
                clearFields();
            }
            catch (Exception ex)
            {
                errorLabel.Text = ex.Message;
                error_label.Visible = true;
            }
        }
        public static void Update(Clanci article, List<string> tags)
        {
            Connection.dm.fsp_Clanci_Update(article.ClanakID, article.Naslov, article.Autori, article.Tekst, article.KljucneRijeci,
                                            article.VrstaID, article.TemaID, article.Dokument, article.DokumentType, article.DokumentPath);

            Connection.dm.fsp_Clanci_DeleteTags(article.ClanakID);

            foreach (string t in tags)
            {
                try
                {
                    Connection.dm.fsp_ClanciTagovi_Insert(article.ClanakID, t);
                }
                catch
                {
                }
            }
        }
        protected void saveArticleSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (documentFile.PostedFile.ContentLength == 0)
                    article = DAClanci.Select(articleId);
                else if (documentFile.PostedFile != null && documentFile.PostedFile.FileName != null
                          && documentFile.PostedFile.FileName != "")
                {
                    string extension = "";
                    article = new Clanci();
                    article.ClanakID = articleId;

                    extension = System.IO.Path.GetExtension(documentFile.PostedFile.FileName);
                    if (extension == ".pdf")
                    {
                        article.DokumentType = documentFile.PostedFile.ContentType;
                        article.Dokument = new byte[documentFile.PostedFile.ContentLength];
                        documentFile.PostedFile.InputStream.Read(article.Dokument, 0, documentFile.PostedFile.ContentLength);
                        string filename = article.ClanakID + extension;
                        System.IO.File.WriteAllBytes(Server.MapPath("/Content/articles/") + filename, article.Dokument);
                        article.DokumentPath = "~/Content/articles/" + filename;
                    }
                    else
                    {
                        errorLabel.Text = "Podržani format dokumenta je pdf.";
                        error_label.Visible = true;
                        return;
                    }
                }

                if (typesList.SelectedIndex != 0)
                    article.VrstaID = Convert.ToInt32(typesList.SelectedValue);
                if (themeList.SelectedIndex != 0)
                    article.TemaID = Convert.ToInt32(themeList.SelectedValue);

                article.Naslov = titleInput.Text.Trim();
                article.Autori = authorsInput.Text.Trim();
                article.KljucneRijeci = keyWordsInput.Text.Trim();
                article.DatumKreiranja = DateTime.Now;
                article.DatumIzmjene = DateTime.Now;
                article.Status = true;
                article.KorisnikID = Convert.ToInt32(User.Identity.Name);
                article.Tekst = wysiwyg.InnerText;

                List<string> tags = new List<string>();

                foreach (string tag in tagsInput.Text.Split(','))
                {
                    if (tag.Trim() != "")
                        tags.Add(tag.Trim());
                }

                DAClanci.Update(article, tags);

                //Praćenje izmjena članka
                ClanciIzmjene articleChange = new ClanciIzmjene();
                articleChange.KorisnikID = Convert.ToInt32(User.Identity.Name);
                articleChange.ClanakID = articleId;
                articleChange.Datum = DateTime.Now;
                articleChange.Opis = editDescriptionInput.InnerText;

                DAClanci.TrackChange(articleChange);

                successLabel.Text = "Uspješno ste sačuvali izmjene.";
                error_label.Visible = false;
                success_label.Visible = true;
            }
            catch (Exception ex)
            {
                errorLabel.Text = ex.Message;
                if (ex.InnerException != null)
                    errorLabel.Text += "\n" + ex.InnerException;
                error_label.Visible = true;
            }
        }
        private void BindArticle()
        {
            if (Request["articleId"] != null)
            {
                articleId = Convert.ToInt32(Request["articleId"]);
                article = DAClanci.Select(articleId);
                List<Tagovi> tags = DAClanci.SelectTags(article.ClanakID);

                foreach (Tagovi tag in tags)
                    tagsInput.Text += tag.Naziv + ", ";

                typesList.SelectedValue = article.VrstaID.ToString();
                themeList.SelectedValue = article.TemaID.ToString();
                titleInput.Text = article.Naslov;
                authorsInput.Text = article.Autori;
                keyWordsInput.Text = article.KljucneRijeci;
                wysiwyg.InnerText = article.Tekst;
            }
        }