Lab8
This commit is contained in:
parent
0a3d0f073f
commit
74adae9fc2
@ -5,9 +5,11 @@ VisualStudioVersion = 17.8.34330.188
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewsBlogView", "NewsBlogView\NewsBlogView.csproj", "{13D9F9B7-6693-4D26-8178-08389235382C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewsBlogAbstractions", "NewsBlogAbstractions\NewsBlogAbstractions.csproj", "{22CA3930-4C19-4623-9B58-C42A48B45576}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewsBlogAbstractions", "NewsBlogAbstractions\NewsBlogAbstractions.csproj", "{22CA3930-4C19-4623-9B58-C42A48B45576}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewsBlogDatabaseImplementation", "NewsBlogDatabaseImplementation\NewsBlogDatabaseImplementation.csproj", "{1DA49583-881B-4E05-A128-AEB692A174B4}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewsBlogDatabaseImplementation", "NewsBlogDatabaseImplementation\NewsBlogDatabaseImplementation.csproj", "{1DA49583-881B-4E05-A128-AEB692A174B4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewsBlogMongoDB", "NewsBlogMongoDB\NewsBlogMongoDB.csproj", "{223BAF22-6898-427D-A5D2-6D32BC50BD30}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -27,6 +29,10 @@ Global
|
||||
{1DA49583-881B-4E05-A128-AEB692A174B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1DA49583-881B-4E05-A128-AEB692A174B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1DA49583-881B-4E05-A128-AEB692A174B4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{223BAF22-6898-427D-A5D2-6D32BC50BD30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{223BAF22-6898-427D-A5D2-6D32BC50BD30}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{223BAF22-6898-427D-A5D2-6D32BC50BD30}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{223BAF22-6898-427D-A5D2-6D32BC50BD30}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
198
NewsBlog/NewsBlogMongoDB/ImplementationMongoDB.cs
Normal file
198
NewsBlog/NewsBlogMongoDB/ImplementationMongoDB.cs
Normal file
@ -0,0 +1,198 @@
|
||||
using MongoDB.Driver;
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
using Tag = NewsBlogAbstractions.Models.Tag;
|
||||
|
||||
namespace NewsBlogMongoDB
|
||||
{
|
||||
public class ImplementationMongoDB: StorageModel
|
||||
{
|
||||
private IMongoDatabase _database;
|
||||
private IMongoCollection<ArticleMongo> _articleCollection;
|
||||
private IMongoCollection<AuthorMongo> _authorCollection;
|
||||
private IMongoCollection<CategoryMongo> _categoryCollection;
|
||||
private IMongoCollection<CommentMongo> _CommentCollection;
|
||||
private IMongoCollection<TagMongo> _TagCollection;
|
||||
private IMongoCollection<Sequence> _SequenceCollection;
|
||||
|
||||
public ImplementationMongoDB()
|
||||
{
|
||||
var client = new MongoClient("mongodb://localhost:27017");
|
||||
_database = client.GetDatabase("NewsBlog");
|
||||
|
||||
_articleCollection = _database.GetCollection<ArticleMongo>("article");
|
||||
_authorCollection = _database.GetCollection<AuthorMongo>("author");
|
||||
_categoryCollection = _database.GetCollection<CategoryMongo>("category");
|
||||
_CommentCollection = _database.GetCollection<CommentMongo>("comment");
|
||||
_TagCollection = _database.GetCollection<TagMongo>("tag");
|
||||
_SequenceCollection = _database.GetCollection<Sequence>("sequence");
|
||||
}
|
||||
|
||||
// article
|
||||
public override void AddArticle(Article article)
|
||||
{
|
||||
string Author_id = GetMongoId("Author", article.AuthorId.ToString());
|
||||
string Category_id = GetMongoId("Category", article.CategoryId.ToString());
|
||||
|
||||
var art = new ArticleMongo(article, Author_id, Category_id);
|
||||
_articleCollection.InsertOne(art);
|
||||
|
||||
var seq = new Sequence { Sql_id = article.Id.ToString(), Mongo_id = art.Id, Table_name = "Article"};
|
||||
_SequenceCollection.InsertOne(seq);
|
||||
}
|
||||
|
||||
public override List<ArticleMongo> GetArticles()
|
||||
{
|
||||
return _articleCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override ArticleMongo GetArticleById(string id)
|
||||
{
|
||||
return _articleCollection.Find(article => article.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateArticle(ArticleMongo article)
|
||||
{
|
||||
_articleCollection.ReplaceOne(c => c.Id == article.Id, article);
|
||||
}
|
||||
|
||||
public override void DeleteArticle(string id)
|
||||
{
|
||||
_articleCollection.DeleteOne(article => article.Id == id);
|
||||
}
|
||||
|
||||
// Author
|
||||
public override void AddAuthor(Author author)
|
||||
{
|
||||
var art = new AuthorMongo(author);
|
||||
_authorCollection.InsertOne(art);
|
||||
|
||||
var seq = new Sequence { Sql_id = author.Id.ToString(), Mongo_id = art.Id, Table_name = "Author" };
|
||||
_SequenceCollection.InsertOne(seq);
|
||||
}
|
||||
|
||||
public override List<AuthorMongo> GetAuthors()
|
||||
{
|
||||
return _authorCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override AuthorMongo GetAuthorById(string id)
|
||||
{
|
||||
return _authorCollection.Find(author => author.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateAuthor(AuthorMongo author)
|
||||
{
|
||||
_authorCollection.ReplaceOne(c => c.Id == author.Id, author);
|
||||
}
|
||||
|
||||
public override void DeleteAuthor(string id)
|
||||
{
|
||||
_authorCollection.DeleteOne(author => author.Id == id);
|
||||
}
|
||||
|
||||
// Category
|
||||
public override void AddCategory(Category category)
|
||||
{
|
||||
var cat = new CategoryMongo(category);
|
||||
_categoryCollection.InsertOne(cat);
|
||||
|
||||
var seq = new Sequence { Sql_id = category.Id.ToString(), Mongo_id = cat.Id, Table_name = "Category" };
|
||||
_SequenceCollection.InsertOne(seq);
|
||||
}
|
||||
|
||||
public override List<CategoryMongo> GetCategorys()
|
||||
{
|
||||
return _categoryCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override CategoryMongo GetCategoryById(string id)
|
||||
{
|
||||
return _categoryCollection.Find(category => category.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateCategory(CategoryMongo category)
|
||||
{
|
||||
_categoryCollection.ReplaceOne(r => r.Id == category.Id, category);
|
||||
}
|
||||
|
||||
public override void DeleteCategory(string id)
|
||||
{
|
||||
_categoryCollection.DeleteOne(category => category.Id == id);
|
||||
}
|
||||
|
||||
// Comment
|
||||
public override void AddComment(Comment Comment)
|
||||
{
|
||||
string ArticleId = GetMongoId("Article", Comment.ArticleId.ToString());
|
||||
|
||||
_CommentCollection.InsertOne(new CommentMongo(Comment, ArticleId));
|
||||
}
|
||||
|
||||
public override List<CommentMongo> GetComments()
|
||||
{
|
||||
return _CommentCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override CommentMongo GetCommentById(string id)
|
||||
{
|
||||
return _CommentCollection.Find(model => model.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateComment(CommentMongo Comment)
|
||||
{
|
||||
_CommentCollection.ReplaceOne(m => m.Id == Comment.Id, Comment);
|
||||
}
|
||||
|
||||
public override void DeleteComment(string id)
|
||||
{
|
||||
_CommentCollection.DeleteOne(model => model.Id == id);
|
||||
}
|
||||
|
||||
// Tag
|
||||
public override void AddTag(Tag Tag)
|
||||
{
|
||||
string ArticleId = GetMongoId("Article", Tag.ArticleId.ToString());
|
||||
|
||||
_TagCollection.InsertOne(new TagMongo(Tag, ArticleId));
|
||||
}
|
||||
|
||||
public override List<TagMongo> GetTags()
|
||||
{
|
||||
return _TagCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override TagMongo GetTagById(string id)
|
||||
{
|
||||
return _TagCollection.Find(Tag => Tag.Id == id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public override void UpdateTag(TagMongo Tag)
|
||||
{
|
||||
_TagCollection.ReplaceOne(b => b.Id == Tag.Id, Tag);
|
||||
}
|
||||
|
||||
public override void DeleteTag(string id)
|
||||
{
|
||||
_TagCollection.DeleteOne(Tag => Tag.Id == id);
|
||||
}
|
||||
|
||||
public List<Sequence> GetSequence()
|
||||
{
|
||||
return _SequenceCollection.Find(_ => true).ToList();
|
||||
}
|
||||
|
||||
public override string GetMongoId(string tableName, string sqlId)
|
||||
{
|
||||
var sequence = _SequenceCollection.Find(s => s.Table_name == tableName && s.Sql_id == sqlId).FirstOrDefault();
|
||||
|
||||
return sequence?.Mongo_id ?? string.Empty;
|
||||
}
|
||||
|
||||
public void DeleteSequence(string id)
|
||||
{
|
||||
_SequenceCollection.DeleteOne(Sequence => Sequence.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
34
NewsBlog/NewsBlogMongoDB/Models/ArticleMongo.cs
Normal file
34
NewsBlog/NewsBlogMongoDB/Models/ArticleMongo.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class ArticleMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public string Publication_date { get; set; } = string.Empty;
|
||||
public string Author_id { get; set; } = string.Empty;
|
||||
public string Category_id { get; set; } = string.Empty;
|
||||
|
||||
public ArticleMongo(NewsBlogAbstractions.Models.Article model, string author_id, string category_id)
|
||||
{
|
||||
Title = model.Title;
|
||||
Content = model.Content;
|
||||
Publication_date = model.PublicationDate.ToString("d");
|
||||
Author_id = author_id;
|
||||
Category_id = category_id;
|
||||
}
|
||||
public ArticleMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
31
NewsBlog/NewsBlogMongoDB/Models/AuthorMongo.cs
Normal file
31
NewsBlog/NewsBlogMongoDB/Models/AuthorMongo.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NewsBlogAbstractions.Models;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class AuthorMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
|
||||
public AuthorMongo(NewsBlogAbstractions.Models.Author model)
|
||||
{
|
||||
Name = model.Name;
|
||||
Description = model.Description;
|
||||
Phone = model.Phone;
|
||||
}
|
||||
public AuthorMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
27
NewsBlog/NewsBlogMongoDB/Models/CategoryMongo.cs
Normal file
27
NewsBlog/NewsBlogMongoDB/Models/CategoryMongo.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using NewsBlogAbstractions.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class CategoryMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public CategoryMongo(NewsBlogAbstractions.Models.Category model)
|
||||
{
|
||||
Name = model.Name;
|
||||
}
|
||||
public CategoryMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
33
NewsBlog/NewsBlogMongoDB/Models/CommentMongo.cs
Normal file
33
NewsBlog/NewsBlogMongoDB/Models/CommentMongo.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using NewsBlogAbstractions.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class CommentMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public string Create_date { get; set; } = string.Empty;
|
||||
public string Article_id { get; set; } = string.Empty;
|
||||
|
||||
public CommentMongo(NewsBlogAbstractions.Models.Comment model, string ArticleId)
|
||||
{
|
||||
Title = model.Title;
|
||||
Content = model.Content;
|
||||
Create_date = model.CreateDate.ToString("d");
|
||||
Article_id = ArticleId;
|
||||
}
|
||||
public CommentMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
20
NewsBlog/NewsBlogMongoDB/Models/Sequence.cs
Normal file
20
NewsBlog/NewsBlogMongoDB/Models/Sequence.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class Sequence
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; } = string.Empty;
|
||||
public string Sql_id { get; set; } = string.Empty;
|
||||
public string Mongo_id { get; set; } = string.Empty;
|
||||
public string Table_name { get; set;} = string.Empty;
|
||||
}
|
||||
}
|
31
NewsBlog/NewsBlogMongoDB/Models/TagMongo.cs
Normal file
31
NewsBlog/NewsBlogMongoDB/Models/TagMongo.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NewsBlogAbstractions.Models;
|
||||
|
||||
namespace NewsBlogMongoDB.Models
|
||||
{
|
||||
public class TagMongo
|
||||
{
|
||||
[BsonId]
|
||||
[BsonRepresentation(BsonType.ObjectId)]
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Decsription { get; set; } = string.Empty;
|
||||
public string Article_id { get; set; } = string.Empty;
|
||||
|
||||
public TagMongo(NewsBlogAbstractions.Models.Tag model, string ArticleId)
|
||||
{
|
||||
Name = model.Name;
|
||||
Decsription = model.Description;
|
||||
Article_id = ArticleId;
|
||||
}
|
||||
public TagMongo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
18
NewsBlog/NewsBlogMongoDB/NewsBlogMongoDB.csproj
Normal file
18
NewsBlog/NewsBlogMongoDB/NewsBlogMongoDB.csproj
Normal file
@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NewsBlogAbstractions\NewsBlogAbstractions.csproj" />
|
||||
<ProjectReference Include="..\NewsBlogDatabaseImplementation\NewsBlogDatabaseImplementation.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
50
NewsBlog/NewsBlogMongoDB/StoragesContracts/StorageModel.cs
Normal file
50
NewsBlog/NewsBlogMongoDB/StoragesContracts/StorageModel.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NewsBlogMongoDB.StoragesContracts
|
||||
{
|
||||
public abstract class StorageModel
|
||||
{
|
||||
// Article
|
||||
public abstract void AddArticle(Article article);
|
||||
public abstract List<ArticleMongo> GetArticles();
|
||||
public abstract ArticleMongo GetArticleById(string id);
|
||||
public abstract void UpdateArticle(ArticleMongo article);
|
||||
public abstract void DeleteArticle(string id);
|
||||
|
||||
// Author
|
||||
public abstract void AddAuthor(Author author);
|
||||
public abstract AuthorMongo GetAuthorById(string id);
|
||||
public abstract List<AuthorMongo> GetAuthors();
|
||||
public abstract void UpdateAuthor(AuthorMongo author);
|
||||
public abstract void DeleteAuthor(string id);
|
||||
|
||||
// Category
|
||||
public abstract void AddCategory(Category category);
|
||||
public abstract CategoryMongo GetCategoryById(string id);
|
||||
public abstract List<CategoryMongo> GetCategorys();
|
||||
public abstract void UpdateCategory(CategoryMongo category);
|
||||
public abstract void DeleteCategory(string id);
|
||||
|
||||
// Comment
|
||||
public abstract void AddComment(Comment comment);
|
||||
public abstract CommentMongo GetCommentById(string id);
|
||||
public abstract List<CommentMongo> GetComments();
|
||||
public abstract void UpdateComment(CommentMongo comment);
|
||||
public abstract void DeleteComment(string id);
|
||||
|
||||
// Tag
|
||||
public abstract void AddTag(Tag tag);
|
||||
public abstract TagMongo GetTagById(string id);
|
||||
public abstract List<TagMongo> GetTags();
|
||||
public abstract void UpdateTag(TagMongo tag);
|
||||
public abstract void DeleteTag(string id);
|
||||
|
||||
public abstract string GetMongoId(string tableName, string sqlId);
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -18,12 +20,14 @@ namespace NewsBlogView
|
||||
private readonly IArticleWork _articleLogic;
|
||||
private readonly IAuthorWork _authorLogic;
|
||||
private readonly ICategoryWork _categoryLogic;
|
||||
public FormArticle(IArticleWork articleLogic, IAuthorWork authorLogic, ICategoryWork categoryLogic)
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormArticle(IArticleWork articleLogic, IAuthorWork authorLogic, ICategoryWork categoryLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_articleLogic = articleLogic;
|
||||
_authorLogic = authorLogic;
|
||||
_categoryLogic = categoryLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormArticle_Load(object sender, EventArgs e)
|
||||
@ -42,14 +46,19 @@ namespace NewsBlogView
|
||||
CategoryId = ((Category?)comboBoxCategory.SelectedItem)?.Id ?? 0,
|
||||
};
|
||||
|
||||
_articleLogic.Create(newArticle);
|
||||
if (Program.isPostgreSQL)
|
||||
_articleLogic.Create(newArticle);
|
||||
else
|
||||
_mongoLogic.AddArticle(newArticle);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var articles = _articleLogic.GetAll();
|
||||
var articlesSql = _articleLogic.GetAll();
|
||||
|
||||
var articlesMongo = _mongoLogic.GetArticles();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
@ -82,11 +91,18 @@ namespace NewsBlogView
|
||||
comboBoxCategory.DisplayMember = "Category";
|
||||
comboBoxCategory.ValueMember = "Name";
|
||||
|
||||
foreach (var article in articles)
|
||||
{
|
||||
dataGridView.Rows.Add(article.Id, article.Title, article.Content, article.PublicationDate.ToString("d"),
|
||||
article.AuthorId, article.CategoryId, _authorLogic.Get(article.AuthorId)?.Name, _categoryLogic.Get(article.CategoryId)?.Name);
|
||||
}
|
||||
if(Program.isPostgreSQL)
|
||||
foreach (var article in articlesSql)
|
||||
{
|
||||
dataGridView.Rows.Add(article.Id, article.Title, article.Content, article.PublicationDate.ToString("d"),
|
||||
article.AuthorId, article.CategoryId, _authorLogic.Get(article.AuthorId)?.Name, _categoryLogic.Get(article.CategoryId)?.Name);
|
||||
}
|
||||
else
|
||||
foreach (var article in articlesMongo)
|
||||
{
|
||||
dataGridView.Rows.Add(article.Id, article.Title, article.Content, article.Publication_date,
|
||||
article.Author_id, article.Category_id, _mongoLogic.GetAuthorById(article.Author_id)?.Name, _mongoLogic.GetCategoryById(article.Category_id)?.Name);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||
@ -94,19 +110,37 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int articleId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Article updatedArticle = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = articleId,
|
||||
Title = textBoxTitle.Text,
|
||||
Content = textBoxContent.Text,
|
||||
PublicationDate = DateTime.Now,
|
||||
AuthorId = ((Author?)comboBoxAuthor.SelectedItem)?.Id ?? 0,
|
||||
CategoryId = ((Category?)comboBoxCategory.SelectedItem)?.Id ?? 0,
|
||||
};
|
||||
int articleId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_articleLogic.Update(updatedArticle);
|
||||
Article updatedArticle = new()
|
||||
{
|
||||
Id = articleId,
|
||||
Title = textBoxTitle.Text,
|
||||
Content = textBoxContent.Text,
|
||||
PublicationDate = DateTime.Now,
|
||||
AuthorId = ((Author?)comboBoxAuthor.SelectedItem)?.Id ?? 0,
|
||||
CategoryId = ((Category?)comboBoxCategory.SelectedItem)?.Id ?? 0,
|
||||
};
|
||||
_articleLogic.Update(updatedArticle);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? articleId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
ArticleMongo updated = new()
|
||||
{
|
||||
Id = articleId,
|
||||
Title = textBoxTitle.Text,
|
||||
Content = textBoxContent.Text,
|
||||
Publication_date = DateTime.Now.ToString("d"),
|
||||
Author_id = _mongoLogic.GetMongoId("Author", ((Author?)comboBoxAuthor.SelectedItem)?.Id.ToString() ?? string.Empty),
|
||||
Category_id = _mongoLogic.GetMongoId("Category", ((Category?)comboBoxCategory.SelectedItem)?.Id.ToString() ?? string.Empty),
|
||||
};
|
||||
_mongoLogic.UpdateArticle(updated);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -121,9 +155,17 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int articleId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_articleLogic.Delete(articleId);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int articleId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
_articleLogic.Delete(articleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? articleIdMongo = selectedRow.Cells["Id"].Value.ToString();
|
||||
_mongoLogic.DeleteArticle(articleIdMongo);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -15,10 +17,12 @@ namespace NewsBlogView
|
||||
public partial class FormAuthor : Form
|
||||
{
|
||||
private readonly IAuthorWork _authorLogic;
|
||||
public FormAuthor(IAuthorWork authorLogic)
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormAuthor(IAuthorWork authorLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_authorLogic = authorLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormAuthor_Load(object sender, EventArgs e)
|
||||
@ -35,7 +39,10 @@ namespace NewsBlogView
|
||||
Phone = textBoxPhone.Text,
|
||||
};
|
||||
|
||||
_authorLogic.Create(newAuthor);
|
||||
if (Program.isPostgreSQL)
|
||||
_authorLogic.Create(newAuthor);
|
||||
else
|
||||
_mongoLogic.AddAuthor(newAuthor);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -43,6 +50,7 @@ namespace NewsBlogView
|
||||
private void LoadData()
|
||||
{
|
||||
var authors = _authorLogic.GetAll();
|
||||
var authorsMongo = _mongoLogic.GetAuthors();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
@ -59,9 +67,19 @@ namespace NewsBlogView
|
||||
dataGridView.Columns["Description"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["Phone"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
|
||||
foreach (var author in authors)
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(author.Id, author.Name, author.Description, author.Phone);
|
||||
foreach (var author in authors)
|
||||
{
|
||||
dataGridView.Rows.Add(author.Id, author.Name, author.Description, author.Phone);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var author in authorsMongo)
|
||||
{
|
||||
dataGridView.Rows.Add(author.Id, author.Name, author.Description, author.Phone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,17 +88,34 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int authorId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Author updatedAuthor = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = authorId,
|
||||
Name = textBoxName.Text,
|
||||
Description = textBoxDescription.Text,
|
||||
Phone = textBoxPhone.Text,
|
||||
};
|
||||
int authorId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_authorLogic.Update(updatedAuthor);
|
||||
Author updatedAuthor = new()
|
||||
{
|
||||
Id = authorId,
|
||||
Name = textBoxName.Text,
|
||||
Description = textBoxDescription.Text,
|
||||
Phone = textBoxPhone.Text,
|
||||
};
|
||||
|
||||
_authorLogic.Update(updatedAuthor);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? authorId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
AuthorMongo updatedAuthor = new()
|
||||
{
|
||||
Id = authorId,
|
||||
Name = textBoxName.Text,
|
||||
Description = textBoxDescription.Text,
|
||||
Phone = textBoxPhone.Text,
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateAuthor(updatedAuthor);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -95,9 +130,18 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int authorId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int authorId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_authorLogic.Delete(authorId);
|
||||
_authorLogic.Delete(authorId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? authorId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteAuthor(authorId);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -15,10 +17,12 @@ namespace NewsBlogView
|
||||
public partial class FormCategory : Form
|
||||
{
|
||||
private readonly ICategoryWork _categoryLogic;
|
||||
public FormCategory(ICategoryWork categoryLogic)
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormCategory(ICategoryWork categoryLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_categoryLogic = categoryLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormCategory_Load(object sender, EventArgs e)
|
||||
@ -33,7 +37,10 @@ namespace NewsBlogView
|
||||
Name = textBoxName.Text,
|
||||
};
|
||||
|
||||
_categoryLogic.Create(newCategory);
|
||||
if (Program.isPostgreSQL)
|
||||
_categoryLogic.Create(newCategory);
|
||||
else
|
||||
_mongoLogic.AddCategory(newCategory);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -41,6 +48,7 @@ namespace NewsBlogView
|
||||
private void LoadData()
|
||||
{
|
||||
var categories = _categoryLogic.GetAll();
|
||||
var categoriesMongo = _mongoLogic.GetCategorys();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
@ -53,9 +61,19 @@ namespace NewsBlogView
|
||||
dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
|
||||
foreach (var category in categories)
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(category.Id, category.Name);
|
||||
foreach (var category in categories)
|
||||
{
|
||||
dataGridView.Rows.Add(category.Id, category.Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var category in categoriesMongo)
|
||||
{
|
||||
dataGridView.Rows.Add(category.Id, category.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,15 +82,30 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int categoryId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Category updatedCategory = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = categoryId,
|
||||
Name = textBoxName.Text,
|
||||
};
|
||||
int categoryId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_categoryLogic.Update(updatedCategory);
|
||||
Category updatedCategory = new()
|
||||
{
|
||||
Id = categoryId,
|
||||
Name = textBoxName.Text,
|
||||
};
|
||||
|
||||
_categoryLogic.Update(updatedCategory);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? categoryId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
CategoryMongo updatedCategory = new()
|
||||
{
|
||||
Id = categoryId,
|
||||
Name = textBoxName.Text,
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateCategory(updatedCategory);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -87,9 +120,18 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int categoryId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int categoryId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_categoryLogic.Delete(categoryId);
|
||||
_categoryLogic.Delete(categoryId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? categoryId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteCategory(categoryId);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -16,11 +18,13 @@ namespace NewsBlogView
|
||||
{
|
||||
private readonly ICommentWork _commentLogic;
|
||||
private readonly IArticleWork _articleLogic;
|
||||
public FormComment(ICommentWork commentLogic, IArticleWork articleLogic)
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormComment(ICommentWork commentLogic, IArticleWork articleLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_commentLogic = commentLogic;
|
||||
_articleLogic = articleLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormComment_Load(object sender, EventArgs e)
|
||||
@ -38,15 +42,16 @@ namespace NewsBlogView
|
||||
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||
};
|
||||
|
||||
_commentLogic.Create(newComment);
|
||||
if (Program.isPostgreSQL)
|
||||
_commentLogic.Create(newComment);
|
||||
else
|
||||
_mongoLogic.AddComment(newComment);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var comments = _commentLogic.GetAll();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
if (dataGridView.ColumnCount == 0)
|
||||
@ -70,10 +75,25 @@ namespace NewsBlogView
|
||||
comboBoxArticle.DisplayMember = "Article";
|
||||
comboBoxArticle.ValueMember = "Title";
|
||||
|
||||
foreach (var comment in comments)
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(comment.Id, comment.Title, comment.Content, comment.CreateDate.ToString("d"), comment.ArticleId, _articleLogic.Get(comment.ArticleId)?.Title);
|
||||
var comments = _commentLogic.GetAll();
|
||||
|
||||
foreach (var comment in comments)
|
||||
{
|
||||
dataGridView.Rows.Add(comment.Id, comment.Title, comment.Content, comment.CreateDate.ToString("d"), comment.ArticleId, _articleLogic.Get(comment.ArticleId)?.Title);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var comments = _mongoLogic.GetComments();
|
||||
|
||||
foreach (var comment in comments)
|
||||
{
|
||||
dataGridView.Rows.Add(comment.Id, comment.Title, comment.Content, comment.Create_date, comment.Article_id, _mongoLogic.GetArticleById(comment.Article_id)?.Title);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||
@ -81,18 +101,36 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int commentId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Comment updatedComment = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = commentId,
|
||||
Title = textBoxTitle.Text,
|
||||
Content = textBoxContent.Text,
|
||||
CreateDate = DateTime.Now,
|
||||
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||
};
|
||||
int commentId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_commentLogic.Update(updatedComment);
|
||||
Comment updatedComment = new()
|
||||
{
|
||||
Id = commentId,
|
||||
Title = textBoxTitle.Text,
|
||||
Content = textBoxContent.Text,
|
||||
CreateDate = DateTime.Now,
|
||||
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||
};
|
||||
|
||||
_commentLogic.Update(updatedComment);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? commentId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
CommentMongo updatedComment = new()
|
||||
{
|
||||
Id = commentId,
|
||||
Title = textBoxTitle.Text,
|
||||
Content = textBoxContent.Text,
|
||||
Create_date = DateTime.Now.ToString("d"),
|
||||
Article_id = _mongoLogic.GetMongoId("Article", ((Article?)comboBoxArticle.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateComment(updatedComment);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -107,9 +145,18 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int commentId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int commentId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_commentLogic.Delete(commentId);
|
||||
_commentLogic.Delete(commentId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? commentId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteComment(commentId);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
63
NewsBlog/NewsBlogView/FormMain.Designer.cs
generated
63
NewsBlog/NewsBlogView/FormMain.Designer.cs
generated
@ -28,6 +28,7 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
CheckBox MongoDB;
|
||||
menuStrip1 = new MenuStrip();
|
||||
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
||||
articleToolStripMenuItem = new ToolStripMenuItem();
|
||||
@ -41,7 +42,9 @@
|
||||
get1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||
update1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||
delete1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||
updateMongoDBToolStripMenuItem = new ToolStripMenuItem();
|
||||
labelTest = new Label();
|
||||
MongoDB = new CheckBox();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -51,8 +54,7 @@
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, замерВремениToolStripMenuItem, замерыВремениToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Padding = new Padding(7, 3, 0, 3);
|
||||
menuStrip1.Size = new Size(633, 30);
|
||||
menuStrip1.Size = new Size(554, 24);
|
||||
menuStrip1.TabIndex = 0;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
@ -60,102 +62,120 @@
|
||||
//
|
||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { articleToolStripMenuItem, authorToolStripMenuItem, categoryToolStripMenuItem, commentToolStripMenuItem, tagToolStripMenuItem });
|
||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||
справочникиToolStripMenuItem.Size = new Size(117, 24);
|
||||
справочникиToolStripMenuItem.Size = new Size(94, 20);
|
||||
справочникиToolStripMenuItem.Text = "Справочники";
|
||||
//
|
||||
// articleToolStripMenuItem
|
||||
//
|
||||
articleToolStripMenuItem.Name = "articleToolStripMenuItem";
|
||||
articleToolStripMenuItem.Size = new Size(157, 26);
|
||||
articleToolStripMenuItem.Size = new Size(151, 22);
|
||||
articleToolStripMenuItem.Text = "Статьи";
|
||||
articleToolStripMenuItem.Click += articleToolStripMenuItem_Click;
|
||||
//
|
||||
// authorToolStripMenuItem
|
||||
//
|
||||
authorToolStripMenuItem.Name = "authorToolStripMenuItem";
|
||||
authorToolStripMenuItem.Size = new Size(157, 26);
|
||||
authorToolStripMenuItem.Size = new Size(151, 22);
|
||||
authorToolStripMenuItem.Text = "Авторы";
|
||||
authorToolStripMenuItem.Click += authorToolStripMenuItem_Click;
|
||||
//
|
||||
// CategoryToolStripMenuItem
|
||||
// categoryToolStripMenuItem
|
||||
//
|
||||
categoryToolStripMenuItem.Name = "categoryToolStripMenuItem";
|
||||
categoryToolStripMenuItem.Size = new Size(157, 26);
|
||||
categoryToolStripMenuItem.Size = new Size(151, 22);
|
||||
categoryToolStripMenuItem.Text = "Категории";
|
||||
categoryToolStripMenuItem.Click += categoryToolStripMenuItem_Click;
|
||||
//
|
||||
// commentToolStripMenuItem
|
||||
//
|
||||
commentToolStripMenuItem.Name = "commentToolStripMenuItem";
|
||||
commentToolStripMenuItem.Size = new Size(157, 26);
|
||||
commentToolStripMenuItem.Size = new Size(151, 22);
|
||||
commentToolStripMenuItem.Text = "Комментарии";
|
||||
commentToolStripMenuItem.Click += commentToolStripMenuItem_Click;
|
||||
//
|
||||
// tagToolStripMenuItem
|
||||
//
|
||||
tagToolStripMenuItem.Name = "tagToolStripMenuItem";
|
||||
tagToolStripMenuItem.Size = new Size(157, 26);
|
||||
tagToolStripMenuItem.Size = new Size(151, 22);
|
||||
tagToolStripMenuItem.Text = "Тэги";
|
||||
tagToolStripMenuItem.Click += tagToolStripMenuItem_Click;
|
||||
//
|
||||
// замерВремениToolStripMenuItem
|
||||
//
|
||||
замерВремениToolStripMenuItem.Name = "замерВремениToolStripMenuItem";
|
||||
замерВремениToolStripMenuItem.Size = new Size(14, 24);
|
||||
замерВремениToolStripMenuItem.Size = new Size(12, 20);
|
||||
//
|
||||
// замерыВремениToolStripMenuItem
|
||||
//
|
||||
замерыВремениToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { add1000ToolStripMenuItem, get1000ToolStripMenuItem, update1000ToolStripMenuItem, delete1000ToolStripMenuItem });
|
||||
замерыВремениToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { add1000ToolStripMenuItem, get1000ToolStripMenuItem, update1000ToolStripMenuItem, delete1000ToolStripMenuItem, updateMongoDBToolStripMenuItem });
|
||||
замерыВремениToolStripMenuItem.Name = "замерыВремениToolStripMenuItem";
|
||||
замерыВремениToolStripMenuItem.Size = new Size(144, 24);
|
||||
замерыВремениToolStripMenuItem.Size = new Size(114, 20);
|
||||
замерыВремениToolStripMenuItem.Text = "Замеры времени";
|
||||
//
|
||||
// add1000ToolStripMenuItem
|
||||
//
|
||||
add1000ToolStripMenuItem.Name = "add1000ToolStripMenuItem";
|
||||
add1000ToolStripMenuItem.Size = new Size(224, 26);
|
||||
add1000ToolStripMenuItem.Size = new Size(185, 22);
|
||||
add1000ToolStripMenuItem.Text = "Добавление 1000";
|
||||
add1000ToolStripMenuItem.Click += add1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// get1000ToolStripMenuItem
|
||||
//
|
||||
get1000ToolStripMenuItem.Name = "get1000ToolStripMenuItem";
|
||||
get1000ToolStripMenuItem.Size = new Size(224, 26);
|
||||
get1000ToolStripMenuItem.Size = new Size(185, 22);
|
||||
get1000ToolStripMenuItem.Text = "Получение 1000";
|
||||
get1000ToolStripMenuItem.Click += get1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// update1000ToolStripMenuItem
|
||||
//
|
||||
update1000ToolStripMenuItem.Name = "update1000ToolStripMenuItem";
|
||||
update1000ToolStripMenuItem.Size = new Size(224, 26);
|
||||
update1000ToolStripMenuItem.Size = new Size(185, 22);
|
||||
update1000ToolStripMenuItem.Text = "Обновление 1000";
|
||||
update1000ToolStripMenuItem.Click += update1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// delete1000ToolStripMenuItem
|
||||
//
|
||||
delete1000ToolStripMenuItem.Name = "delete1000ToolStripMenuItem";
|
||||
delete1000ToolStripMenuItem.Size = new Size(224, 26);
|
||||
delete1000ToolStripMenuItem.Size = new Size(185, 22);
|
||||
delete1000ToolStripMenuItem.Text = "Удаление 1000";
|
||||
delete1000ToolStripMenuItem.Click += delete1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// updateMongoDBToolStripMenuItem
|
||||
//
|
||||
updateMongoDBToolStripMenuItem.Name = "updateMongoDBToolStripMenuItem";
|
||||
updateMongoDBToolStripMenuItem.Size = new Size(185, 22);
|
||||
updateMongoDBToolStripMenuItem.Text = "Обновить MongoDB";
|
||||
updateMongoDBToolStripMenuItem.Click += updateMongoDBToolStripMenuItem_Click;
|
||||
//
|
||||
// labelTest
|
||||
//
|
||||
labelTest.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelTest.Location = new Point(178, 109);
|
||||
labelTest.Location = new Point(156, 82);
|
||||
labelTest.Name = "labelTest";
|
||||
labelTest.Size = new Size(285, 133);
|
||||
labelTest.Size = new Size(250, 100);
|
||||
labelTest.TabIndex = 3;
|
||||
labelTest.TextAlign = ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// MongoDB
|
||||
//
|
||||
MongoDB.AutoSize = true;
|
||||
MongoDB.Location = new Point(459, 230);
|
||||
MongoDB.Name = "MongoDB";
|
||||
MongoDB.Size = new Size(80, 19);
|
||||
MongoDB.TabIndex = 4;
|
||||
MongoDB.Text = "MongoDB";
|
||||
MongoDB.UseVisualStyleBackColor = true;
|
||||
MongoDB.CheckedChanged += MongoDB_CheckedChanged;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(633, 348);
|
||||
ClientSize = new Size(554, 261);
|
||||
Controls.Add(MongoDB);
|
||||
Controls.Add(labelTest);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormMain";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "Электронный дневник";
|
||||
@ -181,5 +201,6 @@
|
||||
private ToolStripMenuItem get1000ToolStripMenuItem;
|
||||
private ToolStripMenuItem update1000ToolStripMenuItem;
|
||||
private ToolStripMenuItem delete1000ToolStripMenuItem;
|
||||
private ToolStripMenuItem updateMongoDBToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB;
|
||||
using System.Security.Policy;
|
||||
|
||||
namespace NewsBlogView
|
||||
@ -85,7 +86,7 @@ namespace NewsBlogView
|
||||
if (service is IAuthorWork authorLogic)
|
||||
{
|
||||
DateTime startTime = DateTime.Now;
|
||||
for (int i =0; i < 1000; i++)
|
||||
for (int i = 0; i < 1000; i++)
|
||||
authorLogic.Get(i + 1000);
|
||||
DateTime endTime = DateTime.Now;
|
||||
|
||||
@ -131,5 +132,73 @@ namespace NewsBlogView
|
||||
labelTest.Text = $"Óäàëåíèå 1000 ñòðîê âûïîëíåíî çà {(endTime - startTime).TotalMilliseconds} ìèëëèñåêóíä";
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMongoDBToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
ImplementationMongoDB implementationMongoDB = new();
|
||||
|
||||
// î÷èùàåì âñ¸
|
||||
foreach (var it in implementationMongoDB.GetArticles())
|
||||
implementationMongoDB.DeleteArticle(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetAuthors())
|
||||
implementationMongoDB.DeleteAuthor(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetCategorys())
|
||||
implementationMongoDB.DeleteCategory(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetComments())
|
||||
implementationMongoDB.DeleteComment(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetTags())
|
||||
implementationMongoDB.DeleteTag(it.Id);
|
||||
foreach (var it in implementationMongoDB.GetSequence())
|
||||
implementationMongoDB.DeleteSequence(it.Id);
|
||||
|
||||
// ñêà÷èâàåì èç ïîñòãðåñà
|
||||
List<Article> listArticle = null;
|
||||
List<Author> listAuthor = null;
|
||||
List<Category> listCategory = null;
|
||||
List<Comment> listComment = null;
|
||||
List<Tag> listTag = null;
|
||||
|
||||
var service = Program.ServiceProvider?.GetService(typeof(IArticleWork));
|
||||
if (service is IArticleWork articleLogic)
|
||||
listArticle = articleLogic.GetAll();
|
||||
|
||||
service = Program.ServiceProvider?.GetService(typeof(IAuthorWork));
|
||||
if (service is IAuthorWork authorLogic)
|
||||
listAuthor = authorLogic.GetAll();
|
||||
|
||||
service = Program.ServiceProvider?.GetService(typeof(ICategoryWork));
|
||||
if (service is ICategoryWork categoryLogic)
|
||||
listCategory = categoryLogic.GetAll();
|
||||
|
||||
service = Program.ServiceProvider?.GetService(typeof(ICommentWork));
|
||||
if (service is ICommentWork commentLogic)
|
||||
listComment = commentLogic.GetAll();
|
||||
|
||||
service = Program.ServiceProvider?.GetService(typeof(ITagWork));
|
||||
if (service is ITagWork tagLogic)
|
||||
listTag = tagLogic.GetAll();
|
||||
|
||||
// âëèâàåì äàííûå ìîíãî äá
|
||||
if (listAuthor != null)
|
||||
foreach (var it in listAuthor)
|
||||
implementationMongoDB.AddAuthor(it);
|
||||
if (listCategory != null)
|
||||
foreach (var it in listCategory)
|
||||
implementationMongoDB.AddCategory(it);
|
||||
if (listArticle != null)
|
||||
foreach (var it in listArticle)
|
||||
implementationMongoDB.AddArticle(it);
|
||||
if (listComment != null)
|
||||
foreach (var it in listComment)
|
||||
implementationMongoDB.AddComment(it);
|
||||
if (listTag != null)
|
||||
foreach (var it in listTag)
|
||||
implementationMongoDB.AddTag(it);
|
||||
}
|
||||
|
||||
private void MongoDB_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
Program.isPostgreSQL = !Program.isPostgreSQL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
@ -26,36 +26,36 @@
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
@ -117,4 +117,10 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="MongoDB.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>False</value>
|
||||
</metadata>
|
||||
</root>
|
@ -1,5 +1,7 @@
|
||||
using NewsBlogAbstractions.Models;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogMongoDB.Models;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -16,12 +18,14 @@ namespace NewsBlogView
|
||||
{
|
||||
private readonly ITagWork _tagLogic;
|
||||
private readonly IArticleWork _articleLogic;
|
||||
private readonly StorageModel _mongoLogic;
|
||||
|
||||
public FormTag(ITagWork logic, IArticleWork articleLogic)
|
||||
public FormTag(ITagWork logic, IArticleWork articleLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_tagLogic = logic;
|
||||
_articleLogic = articleLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormTag_Load(object sender, EventArgs e)
|
||||
@ -38,15 +42,16 @@ namespace NewsBlogView
|
||||
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||
};
|
||||
|
||||
_tagLogic.Create(newTag);
|
||||
if (Program.isPostgreSQL)
|
||||
_tagLogic.Create(newTag);
|
||||
else
|
||||
_mongoLogic.AddTag(newTag);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var tags = _tagLogic.GetAll();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
if (dataGridView.ColumnCount == 0)
|
||||
@ -68,9 +73,21 @@ namespace NewsBlogView
|
||||
comboBoxArticle.DisplayMember = "Article";
|
||||
comboBoxArticle.ValueMember = "Title";
|
||||
|
||||
foreach (var tag in tags)
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(tag.Id, tag.Name, tag.Description, tag.ArticleId, _articleLogic.Get(tag.ArticleId)?.Title);
|
||||
var tags = _tagLogic.GetAll();
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
dataGridView.Rows.Add(tag.Id, tag.Name, tag.Description, tag.ArticleId, _articleLogic.Get(tag.ArticleId)?.Title);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var tags = _mongoLogic.GetTags();
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
dataGridView.Rows.Add(tag.Id, tag.Name, tag.Decsription, tag.Article_id, _mongoLogic.GetArticleById(tag.Article_id)?.Title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,17 +96,34 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int tagId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Tag updatedTag = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = tagId,
|
||||
Name = textBoxName.Text,
|
||||
Description = textBoxDescription.Text,
|
||||
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||
};
|
||||
int tagId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_tagLogic.Update(updatedTag);
|
||||
Tag updatedTag = new()
|
||||
{
|
||||
Id = tagId,
|
||||
Name = textBoxName.Text,
|
||||
Description = textBoxDescription.Text,
|
||||
ArticleId = ((Article?)comboBoxArticle.SelectedItem)?.Id ?? 0,
|
||||
};
|
||||
|
||||
_tagLogic.Update(updatedTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? tagId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
TagMongo updatedTag = new()
|
||||
{
|
||||
Id = tagId,
|
||||
Name = textBoxName.Text,
|
||||
Decsription = textBoxDescription.Text,
|
||||
Article_id = _mongoLogic.GetMongoId("Article", ((Article?)comboBoxArticle.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateTag(updatedTag);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -104,9 +138,18 @@ namespace NewsBlogView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int tagId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int tagId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_tagLogic.Delete(tagId);
|
||||
_tagLogic.Delete(tagId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? tagId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteTag(tagId);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NewsBlogAbstractions\NewsBlogAbstractions.csproj" />
|
||||
<ProjectReference Include="..\NewsBlogDatabaseImplementation\NewsBlogDatabaseImplementation.csproj" />
|
||||
<ProjectReference Include="..\NewsBlogMongoDB\NewsBlogMongoDB.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,6 +1,8 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NewsBlogAbstractions.WorkAbstractions;
|
||||
using NewsBlogDatabaseImplementation.WorkImplementation;
|
||||
using NewsBlogMongoDB.StoragesContracts;
|
||||
using NewsBlogMongoDB;
|
||||
|
||||
namespace NewsBlogView
|
||||
{
|
||||
@ -9,6 +11,8 @@ namespace NewsBlogView
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
public static bool isPostgreSQL = true;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -32,6 +36,8 @@ namespace NewsBlogView
|
||||
services.AddTransient<ICommentWork, CommentWork>();
|
||||
services.AddTransient<ITagWork, TagWork>();
|
||||
|
||||
services.AddTransient<StorageModel, ImplementationMongoDB>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormArticle>();
|
||||
services.AddTransient<FormAuthor>();
|
||||
|
Loading…
Reference in New Issue
Block a user