public ActionResult Edit(int?id) { if (id == null) { return(RedirectToAction("Index", "Home")); } DataBaseArticles dataBaseArticle = new DataBaseArticles(); DataBaseCategories dataBaseCategory = new DataBaseCategories(); DataBaseArticles_Tegs dataBaseArticles_Tegs = new DataBaseArticles_Tegs(); DataBaseTegs dataBaseTeg = new DataBaseTegs(); OneArticle oneArticle = new OneArticle(); oneArticle.Article = dataBaseArticle.Select(id); oneArticle.Categories = new SelectList(dataBaseCategory.Select(), "Category_Id", "Name"); oneArticle.Category = dataBaseCategory.Select(oneArticle.Article.Category_Id); var id_tegs = dataBaseArticles_Tegs.SelectTegs(oneArticle.Article.Article_Id); foreach (var id_teg in id_tegs) { var teg = dataBaseTeg.Select(id_teg.Tegs_Id); oneArticle.Teg += teg.Name; } return(View(oneArticle)); }
public ActionResult Tegs(int?id_teg) { if (id_teg == null) { return(RedirectToAction("Index", "Home")); } DataBaseTegs dataBaseTeg = new DataBaseTegs(); DataBaseArticles_Tegs dataBaseArticles_Tegs = new DataBaseArticles_Tegs(); DataBaseArticles dataBaseArticle = new DataBaseArticles(); DataBaseCategories dataBaseCategory = new DataBaseCategories(); var id_articles = dataBaseArticles_Tegs.SelectArticles(id_teg); List <OneArticle> fullArticles = new List <OneArticle>(); foreach (var id_article in id_articles) { OneArticle oneArticle = new OneArticle(); var id_tegs = dataBaseArticles_Tegs.SelectTegs(id_article.Articles_Id); foreach (var teg in id_tegs) { var tegs = dataBaseTeg.Select(teg.Tegs_Id); oneArticle.Tegs.Add(tegs); } oneArticle.Article = dataBaseArticle.Select(id_article.Articles_Id); oneArticle.Category = dataBaseCategory.Select(oneArticle.Article.Category_Id); fullArticles.Add(oneArticle); } return(View(fullArticles)); }
private List <OneArticle> GetArticles(List <Article> articles) { DataBaseArticles_Tegs dataBaseArticles_Tegs = new DataBaseArticles_Tegs(); DataBaseTegs dataBaseTegs = new DataBaseTegs(); DataBaseCategories dataBaseCategories = new DataBaseCategories(); List <OneArticle> oneArticles = new List <OneArticle>(); foreach (var a in articles) { OneArticle oneArticle = new OneArticle(); oneArticle.Article = a; oneArticle.Category = dataBaseCategories.Select(a.Category_Id); var id_teg = dataBaseArticles_Tegs.SelectTegs(a.Article_Id); foreach (var teg in id_teg) { oneArticle.Tegs.Add(dataBaseTegs.Select(teg.Tegs_Id)); } oneArticles.Add(oneArticle); } return(oneArticles); }
public ActionResult Edit(int?id_category) { DataBaseCategories dataBaseCategory = new DataBaseCategories(); var category = dataBaseCategory.Select(Convert.ToInt32(id_category)); return(View(category)); }
public ActionResult Create(NewArticle newArticle) { DataBaseTegs dataBaseTeg = new DataBaseTegs(); DataBaseArticles dataBaseArticles = new DataBaseArticles(); DataBaseArticles_Tegs dataBaseArticles_Tegs = new DataBaseArticles_Tegs(); newArticle.Article.Category_Id = newArticle.CategoryId; newArticle.Article.DateTime = DateTime.Now; int id_article = dataBaseArticles.Insert(newArticle.Article); string[] tegs = newArticle.Tegs.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); foreach (string teg in tegs) { int id_teg = dataBaseTeg.Insert("#" + teg); dataBaseArticles_Tegs.Insert(id_article, id_teg); } DataBaseCategories dataBaseCategory = new DataBaseCategories(); NewArticle newArticle1 = new NewArticle { Categories = new SelectList(dataBaseCategory.Select(), "Category_Id", "Name") }; return(RedirectToAction("Index", "Home")); }
public ActionResult Category(int?id_category, int?id_page) { DataBaseArticles dataBaseArticle = new DataBaseArticles(); DataBaseCategories dataBaseCategory = new DataBaseCategories(); var articles = dataBaseArticle.SelectTop10Category(Convert.ToInt32(id_page), Convert.ToInt32(id_category)); var category = dataBaseCategory.Select(id_category); List <OneArticle> fullArticles = new List <OneArticle>(); bool check = false; try { if (articles[articles.Count - 1] == null) { articles.RemoveAt(articles.Count - 1); check = true; } } catch (NullReferenceException) { return(RedirectToAction("Index", "Home")); } foreach (var a in articles) { OneArticle oneArticle = new OneArticle { Article = a, Category = dataBaseCategory.Select(a.Category_Id) }; fullArticles.Add(oneArticle); } ViewBag.index = ++id_page; ViewBag.end = 0; if (check) { ViewBag.end = 1; } return(View(fullArticles)); }
public ActionResult Index(int id = 1) { DataBaseArticles dataBaseArticles = new DataBaseArticles(); DataBaseCategories dataBaseCategory = new DataBaseCategories(); var articles = dataBaseArticles.SelectTop10(id); SearchModel searchModel = new SearchModel(); bool check = false; try { if (articles.Last() == null) { articles.RemoveAt(articles.Count - 1); check = true; } } catch (ArgumentNullException) { return(RedirectToAction("Index", "Home")); } foreach (var a in articles) { OneArticle oneArticle = new OneArticle { Article = a, Category = dataBaseCategory.Select(a.Category_Id) }; searchModel.OneArticles.Add(oneArticle); } searchModel.Categories = new SelectList(dataBaseCategory.Select(), "Category_Id", "Name"); ViewBag.index = ++id; ViewBag.end = 0; if (check) { ViewBag.end = 1; } return(View(searchModel)); }
public ActionResult Categories() { DataBaseCategories dataBaseCategory = new DataBaseCategories(); ViewCategory viewCategory = new ViewCategory(); viewCategory.Categories = dataBaseCategory.Select(); return(View(viewCategory)); }
public ViewResult Create() { DataBaseCategories dataBaseCategory = new DataBaseCategories(); NewArticle newArticle = new NewArticle { Categories = new SelectList(dataBaseCategory.Select(), "Category_Id", "Name") }; return(View(newArticle)); }
private List <OneArticle> GetArticles(List <Article> articles, string tegsModel) { DataBaseArticles_Tegs dataBaseArticles_Tegs = new DataBaseArticles_Tegs(); DataBaseTegs dataBaseTegs = new DataBaseTegs(); DataBaseCategories dataBaseCategories = new DataBaseCategories(); string[] tegs = tegsModel.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries); List <OneArticle> oneArticles = new List <OneArticle>(); foreach (var a in articles) { bool check = false; OneArticle oneArticle = new OneArticle(); var id_teg = dataBaseArticles_Tegs.SelectTegs(a.Article_Id); List <Teg> listTegs = new List <Teg>(); foreach (var teg in id_teg) { var getTegs = dataBaseTegs.Select(teg.Tegs_Id); listTegs.Add(getTegs); if (tegs.Contains(getTegs.Name.Substring(1))) { check = true; } } if (check) { oneArticle.Article = a; oneArticle.Category = dataBaseCategories.Select(a.Category_Id); oneArticle.Tegs = listTegs; } oneArticles.Add(oneArticle); } try { oneArticles.Reverse(); } catch (Exception) {} return(oneArticles); }
public ActionResult Categories(ViewCategory category) { DataBaseCategories dataBaseCategory = new DataBaseCategories(); bool check = dataBaseCategory.Insert(category.NewCategory); ViewCategory viewCategory = new ViewCategory(); viewCategory.Categories = dataBaseCategory.Select(); Response.Redirect(Request.Path); if (check) { ModelState.AddModelError("", "Категория успешно добавлена"); } else { ModelState.AddModelError("", "Данная категория уже существует"); } return(View(viewCategory)); }