From 33db1a3e6832ce7ca724d6d2318607e8868105ae Mon Sep 17 00:00:00 2001 From: Ismailov_Rovshan Date: Wed, 6 Sep 2023 20:32:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=D0=BC=D0=BD=D0=BE=D0=B6=D0=BA?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=BE=D0=B4=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BC?= =?UTF-8?q?=20=D0=B2=D1=81=D1=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModel/CommentBindingModel.cs | 18 -- .../BindingModel/NewsBindingModel.cs | 22 -- .../BindingModel/TagBindingModel.cs | 19 -- .../BindingModel/UserBindingModel.cs | 18 -- .../BlogContracts/BlogContracts.csproj | 8 + .../BusinessLogicContracts/ICommentLogic.cs | 20 -- .../BusinessLogicContracts/INewsLogic.cs | 20 -- .../BusinessLogicContracts/ITagLogic.cs | 20 -- .../BusinessLogicContracts/IUserLogic.cs | 20 -- .../SearchModels/CommentSearchModel.cs | 15 -- .../SearchModels/NewsSearchModel.cs | 16 -- .../SearchModels/TagSearchModel.cs | 14 -- .../SearchModels/UserSearchModel.cs | 14 -- .../StorageContracts/ICommentStorage.cs | 21 -- .../StorageContracts/INewsStorage.cs | 21 -- .../StorageContracts/ITagStorage.cs | 21 -- .../StorageContracts/IUserStorage.cs | 21 -- .../ViewModels/CommentViewModel.cs | 20 -- .../BlogContracts/ViewModels/NewsViewModel.cs | 24 --- .../BlogContracts/ViewModels/TagViewModel.cs | 20 -- .../BlogContracts/ViewModels/UserViewModel.cs | 21 -- BlogDataModels/BlogDataModels/IId.cs | 13 -- .../BlogDataModels/Model/IComment.cs | 14 -- BlogDataModels/BlogDataModels/Model/INews.cs | 16 -- BlogDataModels/BlogDataModels/Model/ITag.cs | 14 -- BlogDataModels/BlogDataModels/Model/IUser.cs | 14 -- .../BlogDatabaseImplement.csproj | 9 +- .../Implements/CommentStorage.cs | 89 -------- .../Implements/NewsStorage.cs | 106 ---------- .../Implements/TagStorage.cs | 96 --------- .../Implements/UserStorage.cs | 89 -------- .../20230518164254_Start.Designer.cs | 197 ------------------ .../Migrations/20230518164254_Start.cs | 150 ------------- .../Migrations/BlogDatabaseModelSnapshot.cs | 194 ----------------- .../BlogDatabaseImplement/Model/Comment.cs | 54 ----- .../BlogDatabaseImplement/Model/News.cs | 109 ---------- .../BlogDatabaseImplement/Model/NewsTag.cs | 25 --- .../BlogDatabaseImplement/Model/Tag.cs | 68 ------ .../BlogDatabaseImplement/Model/User.cs | 58 ------ .../BlogViewModel/BlogViewModel.csproj | 1 - .../BlogViewModel/FormMain.Designer.cs | 126 ----------- BlogDataModels/BlogViewModel/FormMain.cs | 30 --- BlogDataModels/BlogViewModel/FormMain.resx | 63 ------ .../BlogViewModel/FormUser.Designer.cs | 123 ----------- BlogDataModels/BlogViewModel/FormUser.cs | 102 --------- BlogDataModels/BlogViewModel/FormUser.resx | 60 ------ .../BlogViewModel/FormUsers.Designer.cs | 128 ------------ BlogDataModels/BlogViewModel/FormUsers.cs | 119 ----------- BlogDataModels/BlogViewModel/FormUsers.resx | 60 ------ BlogDataModels/BlogViewModel/Program.cs | 7 +- BlogDataModels/BusinessLogic/CommentLogic.cs | 95 --------- BlogDataModels/BusinessLogic/NewsLogic.cs | 107 ---------- BlogDataModels/BusinessLogic/TagLogic.cs | 95 --------- BlogDataModels/BusinessLogic/UserLogic.cs | 100 --------- 54 files changed, 14 insertions(+), 2910 deletions(-) delete mode 100644 BlogDataModels/BlogContracts/BindingModel/CommentBindingModel.cs delete mode 100644 BlogDataModels/BlogContracts/BindingModel/NewsBindingModel.cs delete mode 100644 BlogDataModels/BlogContracts/BindingModel/TagBindingModel.cs delete mode 100644 BlogDataModels/BlogContracts/BindingModel/UserBindingModel.cs delete mode 100644 BlogDataModels/BlogContracts/BusinessLogicContracts/ICommentLogic.cs delete mode 100644 BlogDataModels/BlogContracts/BusinessLogicContracts/INewsLogic.cs delete mode 100644 BlogDataModels/BlogContracts/BusinessLogicContracts/ITagLogic.cs delete mode 100644 BlogDataModels/BlogContracts/BusinessLogicContracts/IUserLogic.cs delete mode 100644 BlogDataModels/BlogContracts/SearchModels/CommentSearchModel.cs delete mode 100644 BlogDataModels/BlogContracts/SearchModels/NewsSearchModel.cs delete mode 100644 BlogDataModels/BlogContracts/SearchModels/TagSearchModel.cs delete mode 100644 BlogDataModels/BlogContracts/SearchModels/UserSearchModel.cs delete mode 100644 BlogDataModels/BlogContracts/StorageContracts/ICommentStorage.cs delete mode 100644 BlogDataModels/BlogContracts/StorageContracts/INewsStorage.cs delete mode 100644 BlogDataModels/BlogContracts/StorageContracts/ITagStorage.cs delete mode 100644 BlogDataModels/BlogContracts/StorageContracts/IUserStorage.cs delete mode 100644 BlogDataModels/BlogContracts/ViewModels/CommentViewModel.cs delete mode 100644 BlogDataModels/BlogContracts/ViewModels/NewsViewModel.cs delete mode 100644 BlogDataModels/BlogContracts/ViewModels/TagViewModel.cs delete mode 100644 BlogDataModels/BlogContracts/ViewModels/UserViewModel.cs delete mode 100644 BlogDataModels/BlogDataModels/IId.cs delete mode 100644 BlogDataModels/BlogDataModels/Model/IComment.cs delete mode 100644 BlogDataModels/BlogDataModels/Model/INews.cs delete mode 100644 BlogDataModels/BlogDataModels/Model/ITag.cs delete mode 100644 BlogDataModels/BlogDataModels/Model/IUser.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Implements/CommentStorage.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Implements/NewsStorage.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Implements/TagStorage.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Implements/UserStorage.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Migrations/20230518164254_Start.Designer.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Migrations/20230518164254_Start.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Migrations/BlogDatabaseModelSnapshot.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Model/Comment.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Model/News.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Model/NewsTag.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Model/Tag.cs delete mode 100644 BlogDataModels/BlogDatabaseImplement/Model/User.cs delete mode 100644 BlogDataModels/BlogViewModel/FormMain.Designer.cs delete mode 100644 BlogDataModels/BlogViewModel/FormMain.cs delete mode 100644 BlogDataModels/BlogViewModel/FormMain.resx delete mode 100644 BlogDataModels/BlogViewModel/FormUser.Designer.cs delete mode 100644 BlogDataModels/BlogViewModel/FormUser.cs delete mode 100644 BlogDataModels/BlogViewModel/FormUser.resx delete mode 100644 BlogDataModels/BlogViewModel/FormUsers.Designer.cs delete mode 100644 BlogDataModels/BlogViewModel/FormUsers.cs delete mode 100644 BlogDataModels/BlogViewModel/FormUsers.resx delete mode 100644 BlogDataModels/BusinessLogic/CommentLogic.cs delete mode 100644 BlogDataModels/BusinessLogic/NewsLogic.cs delete mode 100644 BlogDataModels/BusinessLogic/TagLogic.cs delete mode 100644 BlogDataModels/BusinessLogic/UserLogic.cs diff --git a/BlogDataModels/BlogContracts/BindingModel/CommentBindingModel.cs b/BlogDataModels/BlogContracts/BindingModel/CommentBindingModel.cs deleted file mode 100644 index 807f638..0000000 --- a/BlogDataModels/BlogContracts/BindingModel/CommentBindingModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.BindingModel -{ - public class CommentBindingModel : IComment - { - public string Text { get; set; } = string.Empty; - - public int NewsId { get; set; } - - public int Id { get; set; } - } -} diff --git a/BlogDataModels/BlogContracts/BindingModel/NewsBindingModel.cs b/BlogDataModels/BlogContracts/BindingModel/NewsBindingModel.cs deleted file mode 100644 index f828036..0000000 --- a/BlogDataModels/BlogContracts/BindingModel/NewsBindingModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.BindingModel -{ - public class NewsBindingModel : INews - { - public string Title { get; set; } = string.Empty; - - public int UserId { get; set; } - - public int Id { get; set; } - - public string Text { get; set; } = string.Empty; - - public Dictionary NewsTag { get; set; } = new(); - } -} diff --git a/BlogDataModels/BlogContracts/BindingModel/TagBindingModel.cs b/BlogDataModels/BlogContracts/BindingModel/TagBindingModel.cs deleted file mode 100644 index ca67c94..0000000 --- a/BlogDataModels/BlogContracts/BindingModel/TagBindingModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.BindingModel -{ - public class TagBindingModel : ITag - { - public int NewsId { get; set; } - - public int Id { get; set; } - - public string Name { get; set; } = string.Empty; - } -} diff --git a/BlogDataModels/BlogContracts/BindingModel/UserBindingModel.cs b/BlogDataModels/BlogContracts/BindingModel/UserBindingModel.cs deleted file mode 100644 index 235ae10..0000000 --- a/BlogDataModels/BlogContracts/BindingModel/UserBindingModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.BindingModel -{ - public class UserBindingModel : IUser - { - public string Name { get; set; } = string.Empty; - - public string DateCreate { get; set; } = string.Empty; - - public int Id { get; set; } - } -} diff --git a/BlogDataModels/BlogContracts/BlogContracts.csproj b/BlogDataModels/BlogContracts/BlogContracts.csproj index d209a2c..99efd31 100644 --- a/BlogDataModels/BlogContracts/BlogContracts.csproj +++ b/BlogDataModels/BlogContracts/BlogContracts.csproj @@ -17,4 +17,12 @@ + + + + + + + + diff --git a/BlogDataModels/BlogContracts/BusinessLogicContracts/ICommentLogic.cs b/BlogDataModels/BlogContracts/BusinessLogicContracts/ICommentLogic.cs deleted file mode 100644 index 6b94cf2..0000000 --- a/BlogDataModels/BlogContracts/BusinessLogicContracts/ICommentLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.BusinessLogicContracts -{ - public interface ICommentLogic - { - List? ReadList(CommentSearchModel? model); - CommentViewModel? ReadElement(CommentSearchModel model); - bool Create(CommentBindingModel model); - bool Update(CommentBindingModel model); - bool Delete(CommentBindingModel model); - } -} diff --git a/BlogDataModels/BlogContracts/BusinessLogicContracts/INewsLogic.cs b/BlogDataModels/BlogContracts/BusinessLogicContracts/INewsLogic.cs deleted file mode 100644 index 6a899d6..0000000 --- a/BlogDataModels/BlogContracts/BusinessLogicContracts/INewsLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.BusinessLogicContracts -{ - public interface INewsLogic - { - List? ReadList(NewsSearchModel? model); - NewsViewModel? ReadElement(NewsSearchModel model); - bool Create(NewsBindingModel model); - bool Update(NewsBindingModel model); - bool Delete(NewsBindingModel model); - } -} diff --git a/BlogDataModels/BlogContracts/BusinessLogicContracts/ITagLogic.cs b/BlogDataModels/BlogContracts/BusinessLogicContracts/ITagLogic.cs deleted file mode 100644 index e2f7d9c..0000000 --- a/BlogDataModels/BlogContracts/BusinessLogicContracts/ITagLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.BusinessLogicContracts -{ - public interface ITagLogic - { - List? ReadList(TagSearchModel? model); - TagViewModel? ReadElement(TagSearchModel model); - bool Create(TagBindingModel model); - bool Update(TagBindingModel model); - bool Delete(TagBindingModel model); - } -} diff --git a/BlogDataModels/BlogContracts/BusinessLogicContracts/IUserLogic.cs b/BlogDataModels/BlogContracts/BusinessLogicContracts/IUserLogic.cs deleted file mode 100644 index 2a3babd..0000000 --- a/BlogDataModels/BlogContracts/BusinessLogicContracts/IUserLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.BusinessLogicContracts -{ - public interface IUserLogic - { - List? ReadList(UserSearchModel? model); - UserViewModel? ReadElement(UserSearchModel model); - bool Create(UserBindingModel model); - bool Update(UserBindingModel model); - bool Delete(UserBindingModel model); - } -} diff --git a/BlogDataModels/BlogContracts/SearchModels/CommentSearchModel.cs b/BlogDataModels/BlogContracts/SearchModels/CommentSearchModel.cs deleted file mode 100644 index 3e4f03c..0000000 --- a/BlogDataModels/BlogContracts/SearchModels/CommentSearchModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.SearchModels -{ - public class CommentSearchModel - { - public int? Id { get; set; } - public int? NewsId { get; set; } - public string? Text { get; set; } - } -} diff --git a/BlogDataModels/BlogContracts/SearchModels/NewsSearchModel.cs b/BlogDataModels/BlogContracts/SearchModels/NewsSearchModel.cs deleted file mode 100644 index 99439ec..0000000 --- a/BlogDataModels/BlogContracts/SearchModels/NewsSearchModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.SearchModels -{ - public class NewsSearchModel - { - public int? Id { get; set; } - public string? Title { get; set; } - public int? UserId { get; set; } - - } -} diff --git a/BlogDataModels/BlogContracts/SearchModels/TagSearchModel.cs b/BlogDataModels/BlogContracts/SearchModels/TagSearchModel.cs deleted file mode 100644 index 52b63f2..0000000 --- a/BlogDataModels/BlogContracts/SearchModels/TagSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.SearchModels -{ - public class TagSearchModel - { - public int? Id { get; set; } - public string? Name { get; set; } - } -} diff --git a/BlogDataModels/BlogContracts/SearchModels/UserSearchModel.cs b/BlogDataModels/BlogContracts/SearchModels/UserSearchModel.cs deleted file mode 100644 index 18efc81..0000000 --- a/BlogDataModels/BlogContracts/SearchModels/UserSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.SearchModels -{ - public class UserSearchModel - { - public int? Id { get; set; } - public string? Name { get; set; } - } -} diff --git a/BlogDataModels/BlogContracts/StorageContracts/ICommentStorage.cs b/BlogDataModels/BlogContracts/StorageContracts/ICommentStorage.cs deleted file mode 100644 index 028a640..0000000 --- a/BlogDataModels/BlogContracts/StorageContracts/ICommentStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.StorageContracts -{ - public interface ICommentStorage - { - List GetFullList(); - List GetFilteredList(CommentSearchModel model); - CommentViewModel? GetElement(CommentSearchModel model); - CommentViewModel? Insert(CommentBindingModel model); - CommentViewModel? Update(CommentBindingModel model); - CommentViewModel? Delete(CommentBindingModel model); - } -} diff --git a/BlogDataModels/BlogContracts/StorageContracts/INewsStorage.cs b/BlogDataModels/BlogContracts/StorageContracts/INewsStorage.cs deleted file mode 100644 index 8c32722..0000000 --- a/BlogDataModels/BlogContracts/StorageContracts/INewsStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.StorageContracts -{ - public interface INewsStorage - { - List GetFullList(); - List GetFilteredList(NewsSearchModel model); - NewsViewModel? GetElement(NewsSearchModel model); - NewsViewModel? Insert(NewsBindingModel model); - NewsViewModel? Update(NewsBindingModel model); - NewsViewModel? Delete(NewsBindingModel model); - } -} diff --git a/BlogDataModels/BlogContracts/StorageContracts/ITagStorage.cs b/BlogDataModels/BlogContracts/StorageContracts/ITagStorage.cs deleted file mode 100644 index c70e52f..0000000 --- a/BlogDataModels/BlogContracts/StorageContracts/ITagStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.StorageContracts -{ - public interface ITagStorage - { - List GetFullList(); - List GetFilteredList(TagSearchModel model); - TagViewModel? GetElement(TagSearchModel model); - TagViewModel? Insert(TagBindingModel model); - TagViewModel? Update(TagBindingModel model); - TagViewModel? Delete(TagBindingModel model); - } -} diff --git a/BlogDataModels/BlogContracts/StorageContracts/IUserStorage.cs b/BlogDataModels/BlogContracts/StorageContracts/IUserStorage.cs deleted file mode 100644 index 412dc6c..0000000 --- a/BlogDataModels/BlogContracts/StorageContracts/IUserStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.StorageContracts -{ - public interface IUserStorage - { - List GetFullList(); - List GetFilteredList(UserSearchModel model); - UserViewModel? GetElement(UserSearchModel model); - UserViewModel? Insert(UserBindingModel model); - UserViewModel? Update(UserBindingModel model); - UserViewModel? Delete(UserBindingModel model); - } -} diff --git a/BlogDataModels/BlogContracts/ViewModels/CommentViewModel.cs b/BlogDataModels/BlogContracts/ViewModels/CommentViewModel.cs deleted file mode 100644 index 6ad9910..0000000 --- a/BlogDataModels/BlogContracts/ViewModels/CommentViewModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.ViewModels -{ - public class CommentViewModel : IComment - { - [DisplayName("Номер")] - public int Id { get; set; } - [DisplayName("Текст комментария")] - public string Text { get; set; } = string.Empty; - public int NewsId { get; set; } - - } -} diff --git a/BlogDataModels/BlogContracts/ViewModels/NewsViewModel.cs b/BlogDataModels/BlogContracts/ViewModels/NewsViewModel.cs deleted file mode 100644 index 0f6420f..0000000 --- a/BlogDataModels/BlogContracts/ViewModels/NewsViewModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.ViewModels -{ - public class NewsViewModel : INews - { - [DisplayName("Название")] - public string Title { get; set; } = string.Empty; - [DisplayName("Автор")] - public int UserId { get; set; } - [DisplayName("Номер")] - public int Id { get; set; } - [DisplayName("Текст")] - public string Text { get; set; } = string.Empty; - - public Dictionary NewsTag { get; set; } = new(); - } -} diff --git a/BlogDataModels/BlogContracts/ViewModels/TagViewModel.cs b/BlogDataModels/BlogContracts/ViewModels/TagViewModel.cs deleted file mode 100644 index a37673d..0000000 --- a/BlogDataModels/BlogContracts/ViewModels/TagViewModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.ViewModels -{ - public class TagViewModel : ITag - { - [DisplayName("Номер")] - public int Id { get; set; } - [DisplayName("Номер новости")] - public int NewsId { get; set; } - [DisplayName("Название")] - public string Name { get; set; } = string.Empty; - } -} diff --git a/BlogDataModels/BlogContracts/ViewModels/UserViewModel.cs b/BlogDataModels/BlogContracts/ViewModels/UserViewModel.cs deleted file mode 100644 index 958aed5..0000000 --- a/BlogDataModels/BlogContracts/ViewModels/UserViewModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogContracts.ViewModels -{ - public class UserViewModel : IUser - { - [DisplayName("Номер")] - public int Id { get; set; } - [DisplayName("Имя пользователя")] - public string Name { get; set; } = string.Empty; - [DisplayName("Дата регистрации")] - public String DateCreate { get; set; } = string.Empty; - - } -} diff --git a/BlogDataModels/BlogDataModels/IId.cs b/BlogDataModels/BlogDataModels/IId.cs deleted file mode 100644 index 3cb15f2..0000000 --- a/BlogDataModels/BlogDataModels/IId.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDataModels -{ - public interface IId - { - int Id { get; } - } -} diff --git a/BlogDataModels/BlogDataModels/Model/IComment.cs b/BlogDataModels/BlogDataModels/Model/IComment.cs deleted file mode 100644 index 11a5b5c..0000000 --- a/BlogDataModels/BlogDataModels/Model/IComment.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDataModels.Model -{ - public interface IComment : IId - { - string Text { get; } - int NewsId { get; } - } -} diff --git a/BlogDataModels/BlogDataModels/Model/INews.cs b/BlogDataModels/BlogDataModels/Model/INews.cs deleted file mode 100644 index f01ade3..0000000 --- a/BlogDataModels/BlogDataModels/Model/INews.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDataModels.Model -{ - public interface INews : IId - { - string Title { get; } - string Text { get; } - int UserId { get; } - Dictionary NewsTag { get; } - } -} diff --git a/BlogDataModels/BlogDataModels/Model/ITag.cs b/BlogDataModels/BlogDataModels/Model/ITag.cs deleted file mode 100644 index 35683f5..0000000 --- a/BlogDataModels/BlogDataModels/Model/ITag.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDataModels.Model -{ - public interface ITag : IId - { - string Name { get;} - int NewsId { get;} - } -} diff --git a/BlogDataModels/BlogDataModels/Model/IUser.cs b/BlogDataModels/BlogDataModels/Model/IUser.cs deleted file mode 100644 index e9eb4ec..0000000 --- a/BlogDataModels/BlogDataModels/Model/IUser.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDataModels.Model -{ - public interface IUser : IId - { - string Name { get;} - string DateCreate { get;} - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/BlogDatabaseImplement.csproj b/BlogDataModels/BlogDatabaseImplement/BlogDatabaseImplement.csproj index e180eaf..a629fbf 100644 --- a/BlogDataModels/BlogDatabaseImplement/BlogDatabaseImplement.csproj +++ b/BlogDataModels/BlogDatabaseImplement/BlogDatabaseImplement.csproj @@ -8,10 +8,6 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -24,4 +20,9 @@ + + + + + diff --git a/BlogDataModels/BlogDatabaseImplement/Implements/CommentStorage.cs b/BlogDataModels/BlogDatabaseImplement/Implements/CommentStorage.cs deleted file mode 100644 index c48d443..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Implements/CommentStorage.cs +++ /dev/null @@ -1,89 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.StorageContracts; -using BlogContracts.ViewModels; -using BlogDatabaseImplement.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDatabaseImplement.Implements -{ - public class CommentStorage : ICommentStorage - { - public List GetFullList() - { - using var context = new BlogDatabase(); - return context.Comments - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFilteredList(CommentSearchModel model) - { - if (string.IsNullOrEmpty(model.Text)) - { - return new(); - } - using var context = new BlogDatabase(); - return context.Comments - .Where(x => x.Text.Contains(model.Text)) - .Select(x => x.GetViewModel) - .ToList(); - } - - public CommentViewModel? GetElement(CommentSearchModel model) - { - if (string.IsNullOrEmpty(model.Text) && !model.Id.HasValue) - { - return null; - } - using var context = new BlogDatabase(); - return context.Comments - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Text) && x.Text == model.Text) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } - - public CommentViewModel? Insert(CommentBindingModel model) - { - var newComment = Comment.Create(model); - if (newComment == null) - { - return null; - } - using var context = new BlogDatabase(); - context.Comments.Add(newComment); - context.SaveChanges(); - return newComment.GetViewModel; - } - - public CommentViewModel? Update(CommentBindingModel model) - { - using var context = new BlogDatabase(); - var component = context.Comments.FirstOrDefault(x => x.Id == model.Id); - if (component == null) - { - return null; - } - component.Update(model); - context.SaveChanges(); - return component.GetViewModel; - } - - public CommentViewModel? Delete(CommentBindingModel model) - { - using var context = new BlogDatabase(); - var element = context.Comments.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Comments.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Implements/NewsStorage.cs b/BlogDataModels/BlogDatabaseImplement/Implements/NewsStorage.cs deleted file mode 100644 index 3c5e977..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Implements/NewsStorage.cs +++ /dev/null @@ -1,106 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.StorageContracts; -using BlogContracts.ViewModels; -using BlogDatabaseImplement.Model; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDatabaseImplement.Implements -{ - public class NewsStorage : INewsStorage - { - public NewsViewModel? Delete(NewsBindingModel model) - { - using var context = new BlogDatabase(); - var element = context.News.FirstOrDefault(rec => rec.Id == - model.Id); - - if (element != null) - { - context.News.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - - } - - public NewsViewModel? GetElement(NewsSearchModel model) - { - if (string.IsNullOrEmpty(model.Title) && - !model.Id.HasValue) - { - return null; - } - using var context = new BlogDatabase(); - return context.News - .Include(x => x.Tags) - .ThenInclude(x => x.Tag) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Title) && - x.Title == model.Title) || - (model.Id.HasValue && x.Id == - model.Id)) - ?.GetViewModel; - } - - public List GetFilteredList(NewsSearchModel model) - { - if (string.IsNullOrEmpty(model.Title)) - { - return new(); - } - using var context = new BlogDatabase(); - return context.News - .Include(x => x.Tags) - .ThenInclude(x => x.Tag) - .Where(x => x.Title.Contains(model.Title)) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFullList() - { - using var context = new BlogDatabase(); - return context.News - .Include(x => x.User) - .Include(x => x.Tags) - .ThenInclude(x => x.Tag) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - - public NewsViewModel? Insert(NewsBindingModel model) - { - using var context = new BlogDatabase(); - var newNews = News.Create(context, model); - if (newNews == null) - { - return null; - } - context.News.Add(newNews); - context.SaveChanges(); - return newNews.GetViewModel; - } - - public NewsViewModel? Update(NewsBindingModel model) - { - using var context = new BlogDatabase(); - var element = context.News - .FirstOrDefault(x => x.Id == model.Id); - if (element == null) - { - return null; - } - element.Update(model); - context.SaveChanges(); - return element.GetViewModel; - } - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Implements/TagStorage.cs b/BlogDataModels/BlogDatabaseImplement/Implements/TagStorage.cs deleted file mode 100644 index b201db2..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Implements/TagStorage.cs +++ /dev/null @@ -1,96 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.ViewModels; -using BlogDatabaseImplement.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDatabaseImplement.Implements -{ - public class TagStorage - { - public List GetFullList() - { - using var context = new BlogDatabase(); - return context.Tags.Select(x => x.GetViewModel).ToList(); - } - - public List GetFilteredList(TagSearchModel model) - { - using var context = new BlogDatabase(); - if (model.Id.HasValue) - { - return context.Tags - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - else if (model.Name != null) - { - return context.Tags - .Where(x => x.Name == model.Name) - .Select(x => x.GetViewModel) - .ToList(); - } - else - { - return new(); - } - } - - public TagViewModel? GetElement(TagSearchModel model) - { - if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) - { - return null; - } - using var context = new BlogDatabase(); - return context.Tags - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) - || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; - } - - public TagViewModel? Insert(TagBindingModel model) - { - var newTag = Tag.Create(model); - if (newTag == null) - { - return null; - } - using var context = new BlogDatabase(); - context.Tags.Add(newTag); - context.SaveChanges(); - return newTag.GetViewModel; - } - - public TagViewModel? Update(TagBindingModel model) - { - using var context = new BlogDatabase(); - var Tag = context.Tags.FirstOrDefault(x => x.Id == model.Id); - if (Tag == null) - { - return null; - } - Tag.Update(model); - context.SaveChanges(); - return Tag.GetViewModel; - } - - public TagViewModel? Delete(TagBindingModel model) - { - using var context = new BlogDatabase(); - var element = context.Tags.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Tags.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Implements/UserStorage.cs b/BlogDataModels/BlogDatabaseImplement/Implements/UserStorage.cs deleted file mode 100644 index c825689..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Implements/UserStorage.cs +++ /dev/null @@ -1,89 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.SearchModels; -using BlogContracts.StorageContracts; -using BlogContracts.ViewModels; -using BlogDatabaseImplement.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDatabaseImplement.Implements -{ - public class UserStorage : IUserStorage - { - public List GetFullList() - { - using var context = new BlogDatabase(); - return context.Users - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFilteredList(UserSearchModel model) - { - if (string.IsNullOrEmpty(model.Name)) - { - return new(); - } - using var context = new BlogDatabase(); - return context.Users - .Where(x => x.Name.Contains(model.Name)) - .Select(x => x.GetViewModel) - .ToList(); - } - - public UserViewModel? GetElement(UserSearchModel model) - { - if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) - { - return null; - } - using var context = new BlogDatabase(); - return context.Users - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } - - public UserViewModel? Insert(UserBindingModel model) - { - var newUser = User.Create(model); - if (newUser == null) - { - return null; - } - using var context = new BlogDatabase(); - context.Users.Add(newUser); - context.SaveChanges(); - return newUser.GetViewModel; - } - - public UserViewModel? Update(UserBindingModel model) - { - using var context = new BlogDatabase(); - var component = context.Users.FirstOrDefault(x => x.Id == model.Id); - if (component == null) - { - return null; - } - component.Update(model); - context.SaveChanges(); - return component.GetViewModel; - } - - public UserViewModel? Delete(UserBindingModel model) - { - using var context = new BlogDatabase(); - var element = context.Users.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Users.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Migrations/20230518164254_Start.Designer.cs b/BlogDataModels/BlogDatabaseImplement/Migrations/20230518164254_Start.Designer.cs deleted file mode 100644 index e6d87d3..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Migrations/20230518164254_Start.Designer.cs +++ /dev/null @@ -1,197 +0,0 @@ -// -using BlogDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace BlogDatabaseImplement.Migrations -{ - [DbContext(typeof(BlogDatabase))] - [Migration("20230518164254_Start")] - partial class Start - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("BlogDatabaseImplement.Model.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("NewsId") - .HasColumnType("integer"); - - b.Property("Text") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("NewsId"); - - b.ToTable("Comments"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.News", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Text") - .IsRequired() - .HasColumnType("text"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("News"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.NewsTag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("NewsId") - .HasColumnType("integer"); - - b.Property("TagId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("NewsId"); - - b.HasIndex("TagId"); - - b.ToTable("NewsTags"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.Tag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("NewsId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("Tags"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("DateCreate") - .IsRequired() - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.Comment", b => - { - b.HasOne("BlogDatabaseImplement.Model.News", "News") - .WithMany("Comments") - .HasForeignKey("NewsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("News"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.News", b => - { - b.HasOne("BlogDatabaseImplement.Model.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.NewsTag", b => - { - b.HasOne("BlogDatabaseImplement.Model.News", "News") - .WithMany("Tags") - .HasForeignKey("NewsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlogDatabaseImplement.Model.Tag", "Tag") - .WithMany("News") - .HasForeignKey("TagId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("News"); - - b.Navigation("Tag"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.News", b => - { - b.Navigation("Comments"); - - b.Navigation("Tags"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.Tag", b => - { - b.Navigation("News"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Migrations/20230518164254_Start.cs b/BlogDataModels/BlogDatabaseImplement/Migrations/20230518164254_Start.cs deleted file mode 100644 index fc4c6d7..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Migrations/20230518164254_Start.cs +++ /dev/null @@ -1,150 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace BlogDatabaseImplement.Migrations -{ - /// - public partial class Start : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Tags", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "text", nullable: false), - NewsId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Tags", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Users", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "text", nullable: false), - DateCreate = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Users", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "News", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Title = table.Column(type: "text", nullable: false), - Text = table.Column(type: "text", nullable: false), - UserId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_News", x => x.Id); - table.ForeignKey( - name: "FK_News_Users_UserId", - column: x => x.UserId, - principalTable: "Users", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Comments", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Text = table.Column(type: "text", nullable: false), - NewsId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Comments", x => x.Id); - table.ForeignKey( - name: "FK_Comments_News_NewsId", - column: x => x.NewsId, - principalTable: "News", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "NewsTags", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - NewsId = table.Column(type: "integer", nullable: false), - TagId = table.Column(type: "integer", nullable: false), - Count = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_NewsTags", x => x.Id); - table.ForeignKey( - name: "FK_NewsTags_News_NewsId", - column: x => x.NewsId, - principalTable: "News", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_NewsTags_Tags_TagId", - column: x => x.TagId, - principalTable: "Tags", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Comments_NewsId", - table: "Comments", - column: "NewsId"); - - migrationBuilder.CreateIndex( - name: "IX_News_UserId", - table: "News", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_NewsTags_NewsId", - table: "NewsTags", - column: "NewsId"); - - migrationBuilder.CreateIndex( - name: "IX_NewsTags_TagId", - table: "NewsTags", - column: "TagId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Comments"); - - migrationBuilder.DropTable( - name: "NewsTags"); - - migrationBuilder.DropTable( - name: "News"); - - migrationBuilder.DropTable( - name: "Tags"); - - migrationBuilder.DropTable( - name: "Users"); - } - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Migrations/BlogDatabaseModelSnapshot.cs b/BlogDataModels/BlogDatabaseImplement/Migrations/BlogDatabaseModelSnapshot.cs deleted file mode 100644 index 975f13e..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Migrations/BlogDatabaseModelSnapshot.cs +++ /dev/null @@ -1,194 +0,0 @@ -// -using BlogDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -#nullable disable - -namespace BlogDatabaseImplement.Migrations -{ - [DbContext(typeof(BlogDatabase))] - partial class BlogDatabaseModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.5") - .HasAnnotation("Relational:MaxIdentifierLength", 63); - - NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - - modelBuilder.Entity("BlogDatabaseImplement.Model.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("NewsId") - .HasColumnType("integer"); - - b.Property("Text") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("NewsId"); - - b.ToTable("Comments"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.News", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Text") - .IsRequired() - .HasColumnType("text"); - - b.Property("Title") - .IsRequired() - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("News"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.NewsTag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("NewsId") - .HasColumnType("integer"); - - b.Property("TagId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("NewsId"); - - b.HasIndex("TagId"); - - b.ToTable("NewsTags"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.Tag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("NewsId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("Tags"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.User", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("DateCreate") - .IsRequired() - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Users"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.Comment", b => - { - b.HasOne("BlogDatabaseImplement.Model.News", "News") - .WithMany("Comments") - .HasForeignKey("NewsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("News"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.News", b => - { - b.HasOne("BlogDatabaseImplement.Model.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("User"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.NewsTag", b => - { - b.HasOne("BlogDatabaseImplement.Model.News", "News") - .WithMany("Tags") - .HasForeignKey("NewsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlogDatabaseImplement.Model.Tag", "Tag") - .WithMany("News") - .HasForeignKey("TagId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("News"); - - b.Navigation("Tag"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.News", b => - { - b.Navigation("Comments"); - - b.Navigation("Tags"); - }); - - modelBuilder.Entity("BlogDatabaseImplement.Model.Tag", b => - { - b.Navigation("News"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Model/Comment.cs b/BlogDataModels/BlogDatabaseImplement/Model/Comment.cs deleted file mode 100644 index 3f42bfd..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Model/Comment.cs +++ /dev/null @@ -1,54 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.ViewModels; -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDatabaseImplement.Model -{ - public class Comment : IComment - { - [Required] - public string Text { get; set; } = string.Empty; - [Required] - public int NewsId { get; set; } - [Required] - public int Id { get; set; } - public virtual News News { get; set; } - public static Comment? Create(CommentBindingModel model) - { - if (model == null) - { - return null; - } - return new Comment() - { - Id = model.Id, - Text = model.Text, - NewsId = model.NewsId, - }; - } - - public void Update(CommentBindingModel model) - { - if (model == null) - { - return; - } - Text = model.Text; - NewsId = model.NewsId; - } - - public CommentViewModel GetViewModel => new() - { - Id = Id, - Text = Text, - NewsId = NewsId - }; - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Model/News.cs b/BlogDataModels/BlogDatabaseImplement/Model/News.cs deleted file mode 100644 index 2380db7..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Model/News.cs +++ /dev/null @@ -1,109 +0,0 @@ -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.ComponentModel.DataAnnotations.Schema; -using BlogContracts.BindingModel; - -namespace BlogDatabaseImplement.Model -{ - public class News : INews - { - public string Title { get; set; } = string.Empty; - - public string Text { get; set; } = string.Empty; - - public int UserId { get; set; } - - public int Id { get; set; } - public virtual User User { get; set; } - - private Dictionary? _NewsTag = null; - [NotMapped] - public Dictionary NewsTag - { - get - { - if (_NewsTag == null) - { - _NewsTag = Tags.ToDictionary(recPC => recPC.TagId, recPC => (recPC.Tag as ITag, recPC.Count)); - - } - return _NewsTag; - - } - } - [ForeignKey("NewsId")] - public virtual List Tags { get; set; } = new(); - - [ForeignKey("NewsId")] - public virtual List Comments { get; set; } = new(); - - - public static News Create(BlogDatabase context, NewsBindingModel model) - { - var news = new News() - { - Id = model.Id, - Title = model.Title, - Text = model.Text, - UserId = model.UserId - }; - - news.Tags = model.NewsTag.Select(x => new NewsTag - { - Tag = context.Tags.First(y => y.Id == x.Key), - Count = x.Value.Item2 - }).ToList(); - - return news; - } - - - public void Update(NewsBindingModel model) - { - Title = model.Title; - Text = model.Text; - UserId = model.UserId; - } - public BlogContracts.ViewModels.NewsViewModel GetViewModel => new() - { - Id = Id, - Title = Title, - Text = Text, - UserId = UserId - }; - - public void UpdateTags(BlogDatabase context, NewsBindingModel model) - { - var NewsTags = context.NewsTags.Where(rec => rec.NewsId == model.Id).ToList(); - if (NewsTags != null && NewsTags.Count > 0) - { // удалили те, которых нет в модели - context.NewsTags.RemoveRange(NewsTags.Where(rec => !model.NewsTag.ContainsKey(rec.TagId))); - context.SaveChanges(); - // обновили количество у существующих записей - foreach (var updateTag in NewsTags) - { - updateTag.Count = model.NewsTag[updateTag.TagId].Item2; - model.NewsTag.Remove(updateTag.TagId); - } - context.SaveChanges(); - } - var News = context.News.First(x => x.Id == Id); - foreach (var pc in model.NewsTag) - { - context.NewsTags.Add(new NewsTag - { - News = News, - Tag = context.Tags.First(x => x.Id == pc.Key), - Count = pc.Value.Item2 - }); - context.SaveChanges(); - } - _NewsTag = null; - } - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Model/NewsTag.cs b/BlogDataModels/BlogDatabaseImplement/Model/NewsTag.cs deleted file mode 100644 index c5c3fb9..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Model/NewsTag.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDatabaseImplement.Model -{ - public class NewsTag - { - public int Id { get; set; } - [Required] - public int NewsId { get; set; } - - [Required] - public int TagId { get; set; } - - public virtual News News{ get; set; } = new(); - [Required] - public int Count { get; set; } - public virtual Tag Tag { get; set; } = new(); - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Model/Tag.cs b/BlogDataModels/BlogDatabaseImplement/Model/Tag.cs deleted file mode 100644 index 56fdfe0..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Model/Tag.cs +++ /dev/null @@ -1,68 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.ViewModels; -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlogDatabaseImplement.Model -{ - public class Tag : ITag - { - [Required] - public string Name { get; set; } = string.Empty; - [Required] - public int NewsId { get; set; } - [Required] - public int Id { get; set; } - - [ForeignKey("TagId")] - public virtual List News { get; set; } = new(); - - public static Tag? Create(TagBindingModel model) - { - if (model == null) - { - return null; - } - return new Tag() - { - Id = model.Id, - Name = model.Name, - NewsId = model.NewsId, - - }; - } - - public static Tag Create(TagViewModel model) - { - return new Tag - { - Id = model.Id, - Name = model.Name, - NewsId = model.NewsId, - }; - } - - public void Update(TagBindingModel model) - { - if (model == null) - { - return; - } - Name = model.Name; - NewsId = model.NewsId; - } - - public TagViewModel GetViewModel => new() - { - Id = Id, - Name = Name, - NewsId = NewsId - }; - } -} diff --git a/BlogDataModels/BlogDatabaseImplement/Model/User.cs b/BlogDataModels/BlogDatabaseImplement/Model/User.cs deleted file mode 100644 index b0de901..0000000 --- a/BlogDataModels/BlogDatabaseImplement/Model/User.cs +++ /dev/null @@ -1,58 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.ViewModels; -using BlogDataModels.Model; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - - -namespace BlogDatabaseImplement.Model -{ - public class User : IUser - { - [Required] - public string Name { get; set; } = string.Empty; - - public string DateCreate { get; set; } = string.Empty; - [Required] - public int Id { get; set; } - - [ForeignKey("UserId")] - List News { get; set; } = new(); - - public static User? Create(UserBindingModel model) - { - if (model == null) - { - return null; - } - return new User() - { - Id = model.Id, - Name = model.Name, - DateCreate = model.DateCreate - }; - } - - public void Update(UserBindingModel model) - { - if (model == null) - { - return; - } - Name = model.Name; - DateCreate = model.DateCreate; - } - - public UserViewModel GetViewModel => new() - { - Id = Id, - Name = Name, - DateCreate = DateCreate - }; - } -} diff --git a/BlogDataModels/BlogViewModel/BlogViewModel.csproj b/BlogDataModels/BlogViewModel/BlogViewModel.csproj index 2d239b4..b1c5e67 100644 --- a/BlogDataModels/BlogViewModel/BlogViewModel.csproj +++ b/BlogDataModels/BlogViewModel/BlogViewModel.csproj @@ -19,7 +19,6 @@ - diff --git a/BlogDataModels/BlogViewModel/FormMain.Designer.cs b/BlogDataModels/BlogViewModel/FormMain.Designer.cs deleted file mode 100644 index f7e5180..0000000 --- a/BlogDataModels/BlogViewModel/FormMain.Designer.cs +++ /dev/null @@ -1,126 +0,0 @@ -namespace BlogViewModel -{ - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.MenuStrip = new System.Windows.Forms.MenuStrip(); - this.пользователиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.тегиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.комментарииРаботыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.новостиToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.письмаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.MenuStrip.SuspendLayout(); - this.SuspendLayout(); - // - // dataGridView - // - this.dataGridView.BackgroundColor = System.Drawing.SystemColors.Control; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 43); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(1108, 467); - this.dataGridView.TabIndex = 2; - // - // MenuStrip - // - this.MenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.пользователиToolStripMenuItem, - this.тегиToolStripMenuItem, - this.комментарииРаботыToolStripMenuItem, - this.новостиToolStripMenuItem1, - this.письмаToolStripMenuItem}); - this.MenuStrip.Location = new System.Drawing.Point(0, 0); - this.MenuStrip.Name = "MenuStrip"; - this.MenuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3); - this.MenuStrip.Size = new System.Drawing.Size(1132, 30); - this.MenuStrip.TabIndex = 3; - this.MenuStrip.Text = "menuStrip1"; - // - // пользователиToolStripMenuItem - // - this.пользователиToolStripMenuItem.Name = "пользователиToolStripMenuItem"; - this.пользователиToolStripMenuItem.Size = new System.Drawing.Size(121, 24); - this.пользователиToolStripMenuItem.Text = "Пользователь"; - this.пользователиToolStripMenuItem.Click += new System.EventHandler(this.пользователиToolStripMenuItem_Click); - // - // тегиToolStripMenuItem - // - this.тегиToolStripMenuItem.Name = "тегиToolStripMenuItem"; - this.тегиToolStripMenuItem.Size = new System.Drawing.Size(54, 24); - this.тегиToolStripMenuItem.Text = "Теги"; - // - // комментарииРаботыToolStripMenuItem - // - this.комментарииРаботыToolStripMenuItem.Name = "комментарииРаботыToolStripMenuItem"; - this.комментарииРаботыToolStripMenuItem.Size = new System.Drawing.Size(121, 24); - this.комментарииРаботыToolStripMenuItem.Text = "Комментарии"; - // - // новостиToolStripMenuItem1 - // - this.новостиToolStripMenuItem1.Name = "новостиToolStripMenuItem1"; - this.новостиToolStripMenuItem1.Size = new System.Drawing.Size(82, 24); - this.новостиToolStripMenuItem1.Text = "Новости"; - // - // письмаToolStripMenuItem - // - this.письмаToolStripMenuItem.Name = "письмаToolStripMenuItem"; - this.письмаToolStripMenuItem.Size = new System.Drawing.Size(14, 24); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1132, 522); - this.Controls.Add(this.MenuStrip); - this.Controls.Add(this.dataGridView); - this.Name = "FormMain"; - this.Text = "FormMain"; - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.MenuStrip.ResumeLayout(false); - this.MenuStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private DataGridView dataGridView; - private MenuStrip MenuStrip; - private ToolStripMenuItem пользователиToolStripMenuItem; - private ToolStripMenuItem тегиToolStripMenuItem; - private ToolStripMenuItem комментарииРаботыToolStripMenuItem; - private ToolStripMenuItem новостиToolStripMenuItem1; - private ToolStripMenuItem письмаToolStripMenuItem; - } -} \ No newline at end of file diff --git a/BlogDataModels/BlogViewModel/FormMain.cs b/BlogDataModels/BlogViewModel/FormMain.cs deleted file mode 100644 index a520e7d..0000000 --- a/BlogDataModels/BlogViewModel/FormMain.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace BlogViewModel -{ - public partial class FormMain : Form - { - public FormMain() - { - InitializeComponent(); - } - - private void пользователиToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormUsers)); - - if (service is FormUsers form) - { - form.ShowDialog(); - } - } - } -} diff --git a/BlogDataModels/BlogViewModel/FormMain.resx b/BlogDataModels/BlogViewModel/FormMain.resx deleted file mode 100644 index a694815..0000000 --- a/BlogDataModels/BlogViewModel/FormMain.resx +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 17, 17 - - \ No newline at end of file diff --git a/BlogDataModels/BlogViewModel/FormUser.Designer.cs b/BlogDataModels/BlogViewModel/FormUser.Designer.cs deleted file mode 100644 index b7ec7de..0000000 --- a/BlogDataModels/BlogViewModel/FormUser.Designer.cs +++ /dev/null @@ -1,123 +0,0 @@ -namespace BlogViewModel -{ - partial class FormUser - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.UserNameLabel = new System.Windows.Forms.Label(); - this.UserNameTextBox = new System.Windows.Forms.TextBox(); - this.DateCreateLabel = new System.Windows.Forms.Label(); - this.DateCreateTextBox = new System.Windows.Forms.TextBox(); - this.SaveButton = new System.Windows.Forms.Button(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // UserNameLabel - // - this.UserNameLabel.AutoSize = true; - this.UserNameLabel.Location = new System.Drawing.Point(73, 20); - this.UserNameLabel.Name = "UserNameLabel"; - this.UserNameLabel.Size = new System.Drawing.Size(84, 20); - this.UserNameLabel.TabIndex = 0; - this.UserNameLabel.Text = "Название: "; - // - // UserNameTextBox - // - this.UserNameTextBox.Location = new System.Drawing.Point(163, 17); - this.UserNameTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.UserNameTextBox.Name = "UserNameTextBox"; - this.UserNameTextBox.Size = new System.Drawing.Size(238, 27); - this.UserNameTextBox.TabIndex = 2; - // - // DateCreateLabel - // - this.DateCreateLabel.AutoSize = true; - this.DateCreateLabel.Location = new System.Drawing.Point(46, 72); - this.DateCreateLabel.Name = "DateCreateLabel"; - this.DateCreateLabel.Size = new System.Drawing.Size(121, 20); - this.DateCreateLabel.TabIndex = 3; - this.DateCreateLabel.Text = "Дата создания: "; - // - // DateCreateTextBox - // - this.DateCreateTextBox.Location = new System.Drawing.Point(163, 72); - this.DateCreateTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.DateCreateTextBox.Name = "DateCreateTextBox"; - this.DateCreateTextBox.Size = new System.Drawing.Size(238, 27); - this.DateCreateTextBox.TabIndex = 4; - // - // SaveButton - // - this.SaveButton.Location = new System.Drawing.Point(223, 120); - this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.SaveButton.Name = "SaveButton"; - this.SaveButton.Size = new System.Drawing.Size(86, 31); - this.SaveButton.TabIndex = 5; - this.SaveButton.Text = "Сохранить"; - this.SaveButton.UseVisualStyleBackColor = true; - this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); - // - // ButtonCancel - // - this.ButtonCancel.Location = new System.Drawing.Point(315, 120); - this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(86, 31); - this.ButtonCancel.TabIndex = 6; - this.ButtonCancel.Text = "Отмена"; - this.ButtonCancel.UseVisualStyleBackColor = true; - this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // FormUser - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(413, 164); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.SaveButton); - this.Controls.Add(this.DateCreateTextBox); - this.Controls.Add(this.DateCreateLabel); - this.Controls.Add(this.UserNameTextBox); - this.Controls.Add(this.UserNameLabel); - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.Name = "FormUser"; - this.Text = "Пользователь"; - this.Load += new System.EventHandler(this.FormUser_Load); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - private Label UserNameLabel; - private TextBox UserNameTextBox; - private Label DateCreateLabel; - private TextBox DateCreateTextBox; - private Button SaveButton; - private Button ButtonCancel; - } -} \ No newline at end of file diff --git a/BlogDataModels/BlogViewModel/FormUser.cs b/BlogDataModels/BlogViewModel/FormUser.cs deleted file mode 100644 index 4911725..0000000 --- a/BlogDataModels/BlogViewModel/FormUser.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using BlogContracts.BusinessLogicContracts; -using BlogContracts.SearchModels; -using BlogContracts.BindingModel; - -namespace BlogViewModel -{ - public partial class FormUser : Form - { - private readonly ILogger _logger; - private readonly IUserLogic _logic; - private int? _id; - public int Id { set { _id = value; } } - - public FormUser(ILogger logger, IUserLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - - private void FormUser_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - try - { - _logger.LogInformation("Получение компонента"); - - var view = _logic.ReadElement(new UserSearchModel - { - Id = _id.Value - }); - - if (view != null) - { - UserNameTextBox.Text = view.Name; - DateCreateTextBox.Text = view.DateCreate; - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - - private void SaveButton_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(UserNameTextBox.Text)) - { - MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - _logger.LogInformation("Сохранение компонента"); - - try - { - var model = new UserBindingModel - { - Id = _id ?? 0, - Name = UserNameTextBox.Text, - DateCreate = DateCreateTextBox.Text, - //Cost = Convert.ToDouble(CostTextBox.Text) - }; - - var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); - - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка сохранения компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } -} diff --git a/BlogDataModels/BlogViewModel/FormUser.resx b/BlogDataModels/BlogViewModel/FormUser.resx deleted file mode 100644 index f298a7b..0000000 --- a/BlogDataModels/BlogViewModel/FormUser.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/BlogDataModels/BlogViewModel/FormUsers.Designer.cs b/BlogDataModels/BlogViewModel/FormUsers.Designer.cs deleted file mode 100644 index ca7944b..0000000 --- a/BlogDataModels/BlogViewModel/FormUsers.Designer.cs +++ /dev/null @@ -1,128 +0,0 @@ -namespace BlogViewModel -{ - partial class FormUsers - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeUser() - { - this.DataGridView = new System.Windows.Forms.DataGridView(); - this.AddButton = new System.Windows.Forms.Button(); - this.ChangeButton = new System.Windows.Forms.Button(); - this.DeleteButton = new System.Windows.Forms.Button(); - this.UpdateButton = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); - this.SuspendLayout(); - // - // DataGridView - // - this.DataGridView.AllowUserToAddRows = false; - this.DataGridView.AllowUserToDeleteRows = false; - this.DataGridView.AllowUserToResizeColumns = false; - this.DataGridView.BackgroundColor = System.Drawing.SystemColors.Control; - this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.DataGridView.Dock = System.Windows.Forms.DockStyle.Left; - this.DataGridView.Location = new System.Drawing.Point(0, 0); - this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.DataGridView.Name = "DataGridView"; - this.DataGridView.ReadOnly = true; - this.DataGridView.RowHeadersVisible = false; - this.DataGridView.RowHeadersWidth = 51; - this.DataGridView.RowTemplate.Height = 25; - this.DataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; - this.DataGridView.Size = new System.Drawing.Size(630, 736); - this.DataGridView.TabIndex = 0; - // - // AddButton - // - this.AddButton.Location = new System.Drawing.Point(653, 35); - this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.AddButton.Name = "AddButton"; - this.AddButton.Size = new System.Drawing.Size(162, 60); - this.AddButton.TabIndex = 1; - this.AddButton.Text = "Добавить"; - this.AddButton.UseVisualStyleBackColor = true; - this.AddButton.Click += new System.EventHandler(this.AddButton_Click); - // - // ChangeButton - // - this.ChangeButton.Location = new System.Drawing.Point(653, 124); - this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.ChangeButton.Name = "ChangeButton"; - this.ChangeButton.Size = new System.Drawing.Size(162, 60); - this.ChangeButton.TabIndex = 2; - this.ChangeButton.Text = "Изменить"; - this.ChangeButton.UseVisualStyleBackColor = true; - this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click); - // - // DeleteButton - // - this.DeleteButton.Location = new System.Drawing.Point(653, 216); - this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.DeleteButton.Name = "DeleteButton"; - this.DeleteButton.Size = new System.Drawing.Size(162, 60); - this.DeleteButton.TabIndex = 3; - this.DeleteButton.Text = "Удалить"; - this.DeleteButton.UseVisualStyleBackColor = true; - this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click); - // - // UpdateButton - // - this.UpdateButton.Location = new System.Drawing.Point(653, 307); - this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.UpdateButton.Name = "UpdateButton"; - this.UpdateButton.Size = new System.Drawing.Size(162, 60); - this.UpdateButton.TabIndex = 4; - this.UpdateButton.Text = "Обновить"; - this.UpdateButton.UseVisualStyleBackColor = true; - this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click); - // - // FormUsers - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(829, 736); - this.Controls.Add(this.UpdateButton); - this.Controls.Add(this.DeleteButton); - this.Controls.Add(this.ChangeButton); - this.Controls.Add(this.AddButton); - this.Controls.Add(this.DataGridView); - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.Name = "FormUsers"; - this.Text = "Компоненты"; - this.Load += new System.EventHandler(this.FormUsers_Load); - ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - private DataGridView DataGridView; - private Button AddButton; - private Button ChangeButton; - private Button DeleteButton; - private Button UpdateButton; - } -} \ No newline at end of file diff --git a/BlogDataModels/BlogViewModel/FormUsers.cs b/BlogDataModels/BlogViewModel/FormUsers.cs deleted file mode 100644 index 8710c45..0000000 --- a/BlogDataModels/BlogViewModel/FormUsers.cs +++ /dev/null @@ -1,119 +0,0 @@ -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using BlogContracts.BusinessLogicContracts; -using BlogContracts.BindingModel; - -namespace BlogViewModel -{ - public partial class FormUsers : Form - { - private readonly ILogger _logger; - private readonly IUserLogic _logic; - - public FormUsers(ILogger logger, IUserLogic logic) - { - InitializeUser(); - _logger = logger; - _logic = logic; - } - - private void FormUsers_Load(object sender, EventArgs e) - { - LoadData(); - } - - private void LoadData() - { - try - { - var list = _logic.ReadList(null); - - if (list != null) - { - DataGridView.DataSource = list; - DataGridView.Columns["Id"].Visible = false; - DataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["DateCreate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - - _logger.LogInformation("Загрузка компонентов"); - - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки компонентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void AddButton_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormUser)); - - if (service is FormUser form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - private void ChangeButton_Click(object sender, EventArgs e) - { - if (DataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormUser)); - - if (service is FormUser form) - { - form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } - private void DeleteButton_Click(object sender, EventArgs e) - { - if (DataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление пользователя"); - - try - { - if (!_logic.Delete(new UserBindingModel - { - Id = id - })) - { - throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); - } - - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка удаления компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - } - private void UpdateButton_Click(object sender, EventArgs e) - { - LoadData(); - } - } -} diff --git a/BlogDataModels/BlogViewModel/FormUsers.resx b/BlogDataModels/BlogViewModel/FormUsers.resx deleted file mode 100644 index f298a7b..0000000 --- a/BlogDataModels/BlogViewModel/FormUsers.resx +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/BlogDataModels/BlogViewModel/Program.cs b/BlogDataModels/BlogViewModel/Program.cs index 4ce553c..3361c95 100644 --- a/BlogDataModels/BlogViewModel/Program.cs +++ b/BlogDataModels/BlogViewModel/Program.cs @@ -1,9 +1,4 @@ -using BlogContracts.BusinessLogicContracts; -using BlogContracts.StorageContracts; -using BlogDatabaseImplement.Implements; -using BlogDatabaseImplement.Model; -using BlogDataModels.Model; -using BusinessLogic; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; diff --git a/BlogDataModels/BusinessLogic/CommentLogic.cs b/BlogDataModels/BusinessLogic/CommentLogic.cs deleted file mode 100644 index b71e879..0000000 --- a/BlogDataModels/BusinessLogic/CommentLogic.cs +++ /dev/null @@ -1,95 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.BusinessLogicContracts; -using BlogContracts.SearchModels; -using BlogContracts.StorageContracts; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BusinessLogic -{ - public class CommentLogic : ICommentLogic - { - private readonly ICommentStorage _commentStorage; - public CommentLogic(ICommentStorage CommentStorage) - { - _commentStorage = CommentStorage ?? throw new ArgumentNullException(nameof(CommentStorage)); - } - - public bool Create(CommentBindingModel model) - { - CheckModel(model); - if (_commentStorage.Insert(model) == null) - { - return false; - } - return true; - } - - public bool Delete(CommentBindingModel model) - { - CheckModel(model); - if (_commentStorage.Delete(model) == null) - { - return false; - } - return true; - } - - public CommentViewModel? ReadElement(CommentSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - var element = _commentStorage.GetElement(model); - if (element == null) - { - return null; - } - return element; - } - - public List? ReadList(CommentSearchModel? model) - { - var list = model == null ? _commentStorage.GetFullList() : _commentStorage.GetFilteredList(model); - if (list == null) - { - return null; - } - return list; - } - - public bool Update(CommentBindingModel model) - { - CheckModel(model); - if (_commentStorage.Update(model) == null) - { - return false; - } - return true; - } - private void CheckModel(CommentBindingModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (string.IsNullOrEmpty(model.Text)) - { - throw new ArgumentException("Отсутвует текст", - nameof(model.Text)); - } - if (_commentStorage.GetElement(new CommentSearchModel - { - Text = model.Text, - }) != null) - { - throw new InvalidOperationException("Такой тег уже существует"); - } - } - } -} diff --git a/BlogDataModels/BusinessLogic/NewsLogic.cs b/BlogDataModels/BusinessLogic/NewsLogic.cs deleted file mode 100644 index 17fdb74..0000000 --- a/BlogDataModels/BusinessLogic/NewsLogic.cs +++ /dev/null @@ -1,107 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.BusinessLogicContracts; -using BlogContracts.SearchModels; -using BlogContracts.StorageContracts; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BusinessLogic -{ - public class NewsLogic : INewsLogic - { - private readonly INewsStorage _newsStorage; - public NewsLogic(INewsStorage newsStorage) - { - _newsStorage = newsStorage ?? throw new ArgumentNullException(nameof(newsStorage)); - } - - public bool Create(NewsBindingModel model) - { - CheckModel(model); - if (_newsStorage.Insert(model) == null) - { - return false; - } - return true; - } - - public bool Delete(NewsBindingModel model) - { - CheckModel(model); - if (_newsStorage.Delete(model) == null) - { - return false; - } - return true; - } - - public NewsViewModel? ReadElement(NewsSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - var element = _newsStorage.GetElement(model); - if (element == null) - { - return null; - } - return element; - } - - public List? ReadList(NewsSearchModel? model) - { - var list = model == null ? _newsStorage.GetFullList() : _newsStorage.GetFilteredList(model); - if (list == null) - { - return null; - } - return list; - } - - public bool Update(NewsBindingModel model) - { - CheckModel(model); - if (_newsStorage.Update(model) == null) - { - return false; - } - return true; - } - private void CheckModel(NewsBindingModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (string.IsNullOrEmpty(model.Title)) - { - throw new ArgumentException("Отсутвует название", - nameof(model.Title)); - } - if (string.IsNullOrEmpty(model.Text)) - { - throw new ArgumentException("Отсутвует текст", - nameof(model.Text)); - } - if (string.IsNullOrEmpty(model.UserId.ToString())) - { - throw new ArgumentException("Отсутвует автор", - nameof(model.UserId)); - } - if (_newsStorage.GetElement(new NewsSearchModel - { - Title = model.Title, - UserId = model.UserId, - - }) != null) - { - throw new InvalidOperationException("Такая новость уже существует"); - } - } - } -} diff --git a/BlogDataModels/BusinessLogic/TagLogic.cs b/BlogDataModels/BusinessLogic/TagLogic.cs deleted file mode 100644 index e66d325..0000000 --- a/BlogDataModels/BusinessLogic/TagLogic.cs +++ /dev/null @@ -1,95 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.BusinessLogicContracts; -using BlogContracts.SearchModels; -using BlogContracts.StorageContracts; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BusinessLogic -{ - public class TagLogic : ITagLogic - { - private readonly ITagStorage _tagStorage; - public TagLogic(ITagStorage TagStorage) - { - _tagStorage = TagStorage ?? throw new ArgumentNullException(nameof(TagStorage)); - } - - public bool Create(TagBindingModel model) - { - CheckModel(model); - if (_tagStorage.Insert(model) == null) - { - return false; - } - return true; - } - - public bool Delete(TagBindingModel model) - { - CheckModel(model); - if (_tagStorage.Delete(model) == null) - { - return false; - } - return true; - } - - public TagViewModel? ReadElement(TagSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - var element = _tagStorage.GetElement(model); - if (element == null) - { - return null; - } - return element; - } - - public List? ReadList(TagSearchModel? model) - { - var list = model == null ? _tagStorage.GetFullList() : _tagStorage.GetFilteredList(model); - if (list == null) - { - return null; - } - return list; - } - - public bool Update(TagBindingModel model) - { - CheckModel(model); - if (_tagStorage.Update(model) == null) - { - return false; - } - return true; - } - private void CheckModel(TagBindingModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (string.IsNullOrEmpty(model.Name)) - { - throw new ArgumentException("Отсутвует название тега", - nameof(model.Name)); - } - if (_tagStorage.GetElement(new TagSearchModel - { - Name = model.Name, - }) != null) - { - throw new InvalidOperationException("Такой тег уже существует"); - } - } - } -} diff --git a/BlogDataModels/BusinessLogic/UserLogic.cs b/BlogDataModels/BusinessLogic/UserLogic.cs deleted file mode 100644 index f5a74cc..0000000 --- a/BlogDataModels/BusinessLogic/UserLogic.cs +++ /dev/null @@ -1,100 +0,0 @@ -using BlogContracts.BindingModel; -using BlogContracts.BusinessLogicContracts; -using BlogContracts.SearchModels; -using BlogContracts.StorageContracts; -using BlogContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BusinessLogic -{ - public class UserLogic : IUserLogic - { - private readonly IUserStorage _userStorage; - public UserLogic(IUserStorage UserStorage) - { - _userStorage = UserStorage ?? throw new ArgumentNullException(nameof(UserStorage)); - } - - public bool Create(UserBindingModel model) - { - CheckModel(model); - if (_userStorage.Insert(model) == null) - { - return false; - } - return true; - } - - public bool Delete(UserBindingModel model) - { - CheckModel(model); - if (_userStorage.Delete(model) == null) - { - return false; - } - return true; - } - - public UserViewModel? ReadElement(UserSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - var element = _userStorage.GetElement(model); - if (element == null) - { - return null; - } - return element; - } - - public List? ReadList(UserSearchModel? model) - { - var list = model == null ? _userStorage.GetFullList() : _userStorage.GetFilteredList(model); - if (list == null) - { - return null; - } - return list; - } - - public bool Update(UserBindingModel model) - { - CheckModel(model); - if (_userStorage.Update(model) == null) - { - return false; - } - return true; - } - private void CheckModel(UserBindingModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (string.IsNullOrEmpty(model.Name)) - { - throw new ArgumentException("Отсутвует имя", - nameof(model.Name)); - } - if (string.IsNullOrEmpty(model.DateCreate)) - { - throw new ArgumentException("Отсутвует дата создания аккаунта", - nameof(model.DateCreate)); - } - if (_userStorage.GetElement(new UserSearchModel - { - Name = model.Name, - }) != null) - { - throw new InvalidOperationException("Такой пользователь уже существует"); - } - } - } -}