немножко подправим всё

This commit is contained in:
Ismailov_Rovshan 2023-09-06 20:32:55 +04:00
parent 9b3463f858
commit 33db1a3e68
54 changed files with 14 additions and 2910 deletions

View File

@ -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; }
}
}

View File

@ -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<int, (ITag, int)> NewsTag { get; set; } = new();
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -17,4 +17,12 @@
<ProjectReference Include="..\BlogDataModels\BlogDataModels.csproj" /> <ProjectReference Include="..\BlogDataModels\BlogDataModels.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="BindingModel\" />
<Folder Include="BusinessLogicContracts\" />
<Folder Include="SearchModels\" />
<Folder Include="StorageContracts\" />
<Folder Include="ViewModels\" />
</ItemGroup>
</Project> </Project>

View File

@ -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<CommentViewModel>? ReadList(CommentSearchModel? model);
CommentViewModel? ReadElement(CommentSearchModel model);
bool Create(CommentBindingModel model);
bool Update(CommentBindingModel model);
bool Delete(CommentBindingModel model);
}
}

View File

@ -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<NewsViewModel>? ReadList(NewsSearchModel? model);
NewsViewModel? ReadElement(NewsSearchModel model);
bool Create(NewsBindingModel model);
bool Update(NewsBindingModel model);
bool Delete(NewsBindingModel model);
}
}

View File

@ -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<TagViewModel>? ReadList(TagSearchModel? model);
TagViewModel? ReadElement(TagSearchModel model);
bool Create(TagBindingModel model);
bool Update(TagBindingModel model);
bool Delete(TagBindingModel model);
}
}

View File

@ -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<UserViewModel>? ReadList(UserSearchModel? model);
UserViewModel? ReadElement(UserSearchModel model);
bool Create(UserBindingModel model);
bool Update(UserBindingModel model);
bool Delete(UserBindingModel model);
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<CommentViewModel> GetFullList();
List<CommentViewModel> GetFilteredList(CommentSearchModel model);
CommentViewModel? GetElement(CommentSearchModel model);
CommentViewModel? Insert(CommentBindingModel model);
CommentViewModel? Update(CommentBindingModel model);
CommentViewModel? Delete(CommentBindingModel model);
}
}

View File

@ -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<NewsViewModel> GetFullList();
List<NewsViewModel> GetFilteredList(NewsSearchModel model);
NewsViewModel? GetElement(NewsSearchModel model);
NewsViewModel? Insert(NewsBindingModel model);
NewsViewModel? Update(NewsBindingModel model);
NewsViewModel? Delete(NewsBindingModel model);
}
}

View File

@ -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<TagViewModel> GetFullList();
List<TagViewModel> GetFilteredList(TagSearchModel model);
TagViewModel? GetElement(TagSearchModel model);
TagViewModel? Insert(TagBindingModel model);
TagViewModel? Update(TagBindingModel model);
TagViewModel? Delete(TagBindingModel model);
}
}

View File

@ -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<UserViewModel> GetFullList();
List<UserViewModel> GetFilteredList(UserSearchModel model);
UserViewModel? GetElement(UserSearchModel model);
UserViewModel? Insert(UserBindingModel model);
UserViewModel? Update(UserBindingModel model);
UserViewModel? Delete(UserBindingModel model);
}
}

View File

@ -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; }
}
}

View File

@ -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<int, (ITag, int)> NewsTag { get; set; } = new();
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<int, (ITag, int)> NewsTag { get; }
}
}

View File

@ -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;}
}
}

View File

@ -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;}
}
}

View File

@ -8,10 +8,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@ -24,4 +20,9 @@
<ProjectReference Include="..\BlogDataModels\BlogDataModels.csproj" /> <ProjectReference Include="..\BlogDataModels\BlogDataModels.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Implements\" />
<Folder Include="Model\" />
</ItemGroup>
</Project> </Project>

View File

@ -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<CommentViewModel> GetFullList()
{
using var context = new BlogDatabase();
return context.Comments
.Select(x => x.GetViewModel)
.ToList();
}
public List<CommentViewModel> 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;
}
}
}

View File

@ -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<NewsViewModel> 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<NewsViewModel> 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;
}
}
}

View File

@ -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<TagViewModel> GetFullList()
{
using var context = new BlogDatabase();
return context.Tags.Select(x => x.GetViewModel).ToList();
}
public List<TagViewModel> 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;
}
}
}

View File

@ -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<UserViewModel> GetFullList()
{
using var context = new BlogDatabase();
return context.Users
.Select(x => x.GetViewModel)
.ToList();
}
public List<UserViewModel> 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;
}
}
}

View File

@ -1,197 +0,0 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("NewsId")
.HasColumnType("integer");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("NewsId");
b.ToTable("Comments");
});
modelBuilder.Entity("BlogDatabaseImplement.Model.News", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("News");
});
modelBuilder.Entity("BlogDatabaseImplement.Model.NewsTag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("NewsId")
.HasColumnType("integer");
b.Property<int>("TagId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("NewsId");
b.HasIndex("TagId");
b.ToTable("NewsTags");
});
modelBuilder.Entity("BlogDatabaseImplement.Model.Tag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("NewsId")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Tags");
});
modelBuilder.Entity("BlogDatabaseImplement.Model.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("DateCreate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -1,150 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace BlogDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class Start : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Tags",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
NewsId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tags", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: false),
DateCreate = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "News",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Title = table.Column<string>(type: "text", nullable: false),
Text = table.Column<string>(type: "text", nullable: false),
UserId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Text = table.Column<string>(type: "text", nullable: false),
NewsId = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
NewsId = table.Column<int>(type: "integer", nullable: false),
TagId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -1,194 +0,0 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("NewsId")
.HasColumnType("integer");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("NewsId");
b.ToTable("Comments");
});
modelBuilder.Entity("BlogDatabaseImplement.Model.News", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("News");
});
modelBuilder.Entity("BlogDatabaseImplement.Model.NewsTag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("integer");
b.Property<int>("NewsId")
.HasColumnType("integer");
b.Property<int>("TagId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("NewsId");
b.HasIndex("TagId");
b.ToTable("NewsTags");
});
modelBuilder.Entity("BlogDatabaseImplement.Model.Tag", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("NewsId")
.HasColumnType("integer");
b.HasKey("Id");
b.ToTable("Tags");
});
modelBuilder.Entity("BlogDatabaseImplement.Model.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("DateCreate")
.IsRequired()
.HasColumnType("text");
b.Property<string>("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
}
}
}

View File

@ -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
};
}
}

View File

@ -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<int, (ITag, int)>? _NewsTag = null;
[NotMapped]
public Dictionary<int, (ITag, int)> 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<NewsTag> Tags { get; set; } = new();
[ForeignKey("NewsId")]
public virtual List<Comment> 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;
}
}
}

View File

@ -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();
}
}

View File

@ -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<NewsTag> 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
};
}
}

View File

@ -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> 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
};
}
}

View File

@ -19,7 +19,6 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\BlogContracts\BlogContracts.csproj" /> <ProjectReference Include="..\BlogContracts\BlogContracts.csproj" />
<ProjectReference Include="..\BlogDatabaseImplement\BlogDatabaseImplement.csproj" /> <ProjectReference Include="..\BlogDatabaseImplement\BlogDatabaseImplement.csproj" />
<ProjectReference Include="..\BlogDataModels\BlogDataModels.csproj" />
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" /> <ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -1,126 +0,0 @@
namespace BlogViewModel
{
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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();
}
}
}
}

View File

@ -1,63 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="MenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View File

@ -1,123 +0,0 @@
namespace BlogViewModel
{
partial class FormUser
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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<FormUser> 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();
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,128 +0,0 @@
namespace BlogViewModel
{
partial class FormUsers
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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<FormUsers> 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();
}
}
}

View File

@ -1,60 +0,0 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;

View File

@ -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<CommentViewModel>? 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("Такой тег уже существует");
}
}
}
}

View File

@ -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<NewsViewModel>? 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("Такая новость уже существует");
}
}
}
}

View File

@ -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<TagViewModel>? 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("Такой тег уже существует");
}
}
}
}

View File

@ -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<UserViewModel>? 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("Такой пользователь уже существует");
}
}
}
}