diff --git a/VNH.Application/Common/Contants/SystemConstants.cs b/VNH.Application/Common/Contants/SystemConstants.cs index 2434fca..e713378 100644 --- a/VNH.Application/Common/Contants/SystemConstants.cs +++ b/VNH.Application/Common/Contants/SystemConstants.cs @@ -1,18 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace VNH.Application.Common.Contants +namespace VNH.Application.Common.Contants { public static class SystemConstants { public const string Token = "Token"; public const string BaseAddress = "BaseAddress"; - public const string UrlWeb = "https://vuanhpham25-001-site1.gtempurl.com/"; - //// public const string UrlWeb = "https://localhost:7138/"; - public const string ConnectString = "Data Source=SQL5110.site4now.net;Initial Catalog=db_aa121e_vuanhpham25;User Id=db_aa121e_vuanhpham25_admin;Password=30102002Mai"; - public const string ConnectStringDevelop = "Data Source=.;Initial Catalog=VietNamHistory_2;Integrated Security=True;Encrypt=true;TrustServerCertificate=true;"; + // public const string UrlWeb = "https://vuanhpham25-001-site1.gtempurl.com/"; + public const string UrlWeb = "https://localhost:7138/"; + // public const string ConnectString = "Data Source=SQL5111.site4now.net;Initial Catalog=db_aa121e_vuanhpham25;User Id=db_aa121e_vuanhpham25_admin;Password=30102002Mai"; + public const string ConnectString = "Data Source=.;Initial Catalog=VietNamHistory_2;Integrated Security=True;Encrypt=true;TrustServerCertificate=true;"; } } diff --git a/VNH.Application/DTOs/Catalog/Posts/CreatePostDto.cs b/VNH.Application/DTOs/Catalog/Posts/CreatePostDto.cs index 3d1b309..477efee 100644 --- a/VNH.Application/DTOs/Catalog/Posts/CreatePostDto.cs +++ b/VNH.Application/DTOs/Catalog/Posts/CreatePostDto.cs @@ -1,15 +1,16 @@ using Microsoft.AspNetCore.Http; +using System.ComponentModel.DataAnnotations; namespace VNH.Application.DTOs.Catalog.Posts { public class CreatePostDto { - public string Id { get; set; } = string.Empty; - public string Title { get; set; } - public string Content { get; set; } - public IFormFile Image { get; set; } + public string? Id { get; set; } = Guid.NewGuid().ToString(); + public string Title { get; set; } = string.Empty; + public string Content { get; set; } = string.Empty; + public IFormFile? Image { get; set; } public Guid TopicId { get; set; } - public List Tag { get; set; } + public List? Tag { get; set; } } } \ No newline at end of file diff --git a/VNH.Application/DTOs/Catalog/Posts/PostResponsetDto.cs b/VNH.Application/DTOs/Catalog/Posts/PostResponseDto.cs similarity index 91% rename from VNH.Application/DTOs/Catalog/Posts/PostResponsetDto.cs rename to VNH.Application/DTOs/Catalog/Posts/PostResponseDto.cs index 540376d..fa493f8 100644 --- a/VNH.Application/DTOs/Catalog/Posts/PostResponsetDto.cs +++ b/VNH.Application/DTOs/Catalog/Posts/PostResponseDto.cs @@ -7,9 +7,10 @@ namespace VNH.Application.DTOs.Catalog.Posts { - public class PostResponsetDto + public class PostResponseDto { public string Id { get; set; } = string.Empty; + public string SubId { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public string Content { get; set; } = string.Empty; public string Image { get; set; } = string.Empty; diff --git a/VNH.Application/DTOs/Catalog/Posts/ReportPostDto.cs b/VNH.Application/DTOs/Catalog/Posts/ReportPostDto.cs index 4d93656..c3797f6 100644 --- a/VNH.Application/DTOs/Catalog/Posts/ReportPostDto.cs +++ b/VNH.Application/DTOs/Catalog/Posts/ReportPostDto.cs @@ -3,7 +3,7 @@ namespace VNH.Application.DTOs.Catalog.Posts { public class ReportPostDto { - public string PostId { get; set; } = string.Empty; + public string PostId { get; set; } public Guid UserId { get; set; } public Guid ReportId { get; set; } public string Description { get; set; } = string.Empty; diff --git a/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs b/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs index 1875aec..53efb56 100644 --- a/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs +++ b/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs @@ -5,15 +5,18 @@ namespace VNH.Application.Interfaces.Posts { public interface IPostService { - Task> Create(CreatePostDto requestDto, string name); - Task> Update(CreatePostDto requestDto, string name); - Task> Detail(string Id); - Task>> GetAll(); - Task> Delete(string id); + Task> Create(CreatePostDto requestDto, string name); + Task> Update(CreatePostDto requestDto, string name); + Task> Detail(string Id); + Task>> GetAll(); + Task> Delete(string id, string email); + Task> DeleteAdmin(string id); + Task> AddOrUnLikePost(string id, string userId); Task> AddOrRemoveSavePost(string postId, string userId); Task> ReportPost(ReportPostDto reportPostDto); Task> GetReport(); + } } \ No newline at end of file diff --git a/VNH.Application/Mappers/PostMapper.cs b/VNH.Application/Mappers/PostMapper.cs index 4554ee8..138a7df 100644 --- a/VNH.Application/Mappers/PostMapper.cs +++ b/VNH.Application/Mappers/PostMapper.cs @@ -11,7 +11,7 @@ public PostMapper() CreateMap() .ForMember(dest => dest.Image, opt => opt.Ignore()); - CreateMap() + CreateMap() .ForMember(dest => dest.Image, opt => opt.Ignore()); CreateMap().ReverseMap(); diff --git a/VNH.Application/VNH.Application.csproj b/VNH.Application/VNH.Application.csproj index dae9d99..ced845f 100644 --- a/VNH.Application/VNH.Application.csproj +++ b/VNH.Application/VNH.Application.csproj @@ -11,6 +11,7 @@ + diff --git a/VNH.Domain/Entities/Post.cs b/VNH.Domain/Entities/Post.cs index c68604e..d4faacb 100644 --- a/VNH.Domain/Entities/Post.cs +++ b/VNH.Domain/Entities/Post.cs @@ -23,16 +23,17 @@ public Post() [Key] [StringLength(255)] public string Id { get; set; } - [Required] + [StringLength(300)] + public string SubId { get; set; } = string.Empty; [StringLength(255)] public string Title { get; set; } public string Content { get; set; } public Guid TopicId { get; set; } [Column(TypeName = "datetime")] - public DateTime? CreatedAt { get; set; } + public DateTime CreatedAt { get; set; } [Column(TypeName = "datetime")] public DateTime? UpdatedAt { get; set; } - public Guid? UserId { get; set; } + public Guid UserId { get; set; } public string Image { get; set; } = string.Empty; public int ViewNumber { get; set; } diff --git a/VNH.Infrastructure/Implement/Catalog/Account/AccountService.cs b/VNH.Infrastructure/Implement/Catalog/Account/AccountService.cs index adcda7b..55c118c 100644 --- a/VNH.Infrastructure/Implement/Catalog/Account/AccountService.cs +++ b/VNH.Infrastructure/Implement/Catalog/Account/AccountService.cs @@ -169,6 +169,7 @@ public async Task> Register(RegisterRequest request) { Id = Guid.NewGuid(), UserName = request.Email, + Fullname = request.Email, Email = request.Email, NumberConfirm = confirmNumber, LockoutEnabled = false diff --git a/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs b/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs index 9847ae9..afc4f38 100644 --- a/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs +++ b/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs @@ -3,8 +3,10 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Hosting; +using Microsoft.IdentityModel.Tokens; using System.Globalization; using System.Text; +using System.Text.RegularExpressions; using VNH.Application.DTOs.Catalog.HashTags; using VNH.Application.DTOs.Catalog.Posts; using VNH.Application.DTOs.Catalog.Users; @@ -34,7 +36,7 @@ public PostService(UserManager userManager, IMapper mapper, IImageService _dataContext = vietNamHistoryContext; _storageService = storageService; } - public async Task> Create(CreatePostDto requestDto, string name) + public async Task> Create(CreatePostDto requestDto, string name) { var user = await _userManager.FindByEmailAsync(name); var post = _mapper.Map(requestDto); @@ -42,31 +44,34 @@ public async Task> Create(CreatePostDto requestDto, post.CreatedAt = DateTime.Now; post.UserId = user.Id; post.TopicId = requestDto.TopicId; - var Id = RemoveDiacritics(post.Title); - post.Id = Id.Trim().Replace(" ","-") + "-" + Guid.NewGuid().ToString(); + string formattedDateTime = post.CreatedAt.ToString("HH:mm:ss.fff-dd-MM-yyyy"); + var Id = SanitizeString(post.Title); + post.SubId = Id + "-" + formattedDateTime; try { _dataContext.Posts.Add(post); await _dataContext.SaveChangesAsync(); - foreach (var item in requestDto.Tag) + if (!requestDto.Tag.IsNullOrEmpty()) { - var tag = new Tag() - { - Id = Guid.NewGuid(), - Name = item - }; - var postTag = new PostTag() + foreach (var item in requestDto.Tag) { - PostId = post.Id, - TagId = tag.Id - }; - _dataContext.PostTags.Add(postTag); - _dataContext.Tags.Add(tag); + var tag = new Tag() + { + Id = Guid.NewGuid(), + Name = item + }; + var postTag = new PostTag() + { + PostId = post.Id, + TagId = tag.Id + }; + _dataContext.PostTags.Add(postTag); + _dataContext.Tags.Add(tag); + } + await _dataContext.SaveChangesAsync(); } - await _dataContext.SaveChangesAsync(); - - var postReponse = _mapper.Map(post); + var postReponse = _mapper.Map(post); postReponse.Image = post.Image; var useDto = new UserShortDto() @@ -93,11 +98,11 @@ public async Task> Create(CreatePostDto requestDto, var topic = await _dataContext.Topics.FirstAsync(x => x.Id == post.TopicId); postReponse.TopicName = topic.Title; - return new ApiSuccessResult(postReponse); + return new ApiSuccessResult(postReponse); } catch (Exception ex) { - return new ApiErrorResult("Lỗi lưu bài viết : " + ex.Message); + return new ApiErrorResult("Lỗi lưu bài viết : " + ex.Message); } } @@ -116,15 +121,22 @@ private static string RemoveDiacritics(string input) return stringBuilder.ToString().Normalize(NormalizationForm.FormC); } + private static string SanitizeString(string input) + { + string withoutDiacritics = RemoveDiacritics(input).Trim().Replace(" ", "-"); + string sanitizedString = Regex.Replace(withoutDiacritics, "[^a-zA-Z0-9-]", ""); + + return sanitizedString; + } - public async Task> Update(CreatePostDto requestDto, string name) + public async Task> Update(CreatePostDto requestDto, string name) { var user = await _userManager.FindByEmailAsync(name); var updatePost = _dataContext.Posts.First(x=>x.Id.Equals(requestDto.Id)); if (updatePost is null) { - return new ApiErrorResult("Lỗi :Bài viết không được cập nhập (không tìm thấy bài viết)"); + return new ApiErrorResult("Lỗi :Bài viết không được cập nhập (không tìm thấy bài viết)"); } if (updatePost.Image != string.Empty) { @@ -134,7 +146,9 @@ public async Task> Update(CreatePostDto requestDto, updatePost.UpdatedAt = DateTime.Now; updatePost.TopicId = requestDto.TopicId; updatePost.Content = requestDto.Content; - + string formattedDateTime = DateTime.Now.ToString("HH:mm:ss.fff-dd-MM-yyyy"); + var Id = SanitizeString(updatePost.Title); + updatePost.SubId = Id.Trim().Replace(" ", "-") + "-" + formattedDateTime; try { _dataContext.Posts.Update(updatePost); @@ -142,7 +156,6 @@ public async Task> Update(CreatePostDto requestDto, var tagOfPost = await _dataContext.PostTags.Where(x => x.PostId.Equals(updatePost.Id)).ToListAsync(); _dataContext.PostTags.RemoveRange(tagOfPost); - await _dataContext.SaveChangesAsync(); foreach (var item in requestDto.Tag) { @@ -161,7 +174,7 @@ public async Task> Update(CreatePostDto requestDto, } await _dataContext.SaveChangesAsync(); - var postReponse = _mapper.Map(updatePost); + var postReponse = _mapper.Map(updatePost); postReponse.Image = updatePost.Image; var useDto = new UserShortDto() @@ -188,23 +201,23 @@ public async Task> Update(CreatePostDto requestDto, var topic = await _dataContext.Topics.FirstAsync(x => x.Id == updatePost.TopicId); postReponse.TopicName = topic.Title; - return new ApiSuccessResult(postReponse); + return new ApiSuccessResult(postReponse); } catch (Exception ex) { - return new ApiErrorResult("Lỗi lưu bài viết : " + ex.Message); + return new ApiErrorResult("Lỗi lưu bài viết : " + ex.Message); } } - public async Task> Detail(string Id) + public async Task> Detail(string Id) { - var post = await _dataContext.Posts.FirstOrDefaultAsync(x=>x.Id.Equals(Id)); + var post = await _dataContext.Posts.FirstOrDefaultAsync(x=>x.SubId.Equals(Id)); if (post is null) { - return new ApiErrorResult("Không tìm thấy bài viết"); + return new ApiErrorResult("Không tìm thấy bài viết"); } var user = await _userManager.FindByIdAsync(post.UserId.ToString()); - var postResponse = _mapper.Map(post); + var postResponse = _mapper.Map(post); postResponse.Image = post.Image; var listPostTag = await _dataContext.PostTags.Where(x => x.PostId.Equals(postResponse.Id)).Select(x => x.TagId).ToListAsync(); @@ -225,27 +238,29 @@ public async Task> Detail(string Id) Id = user.Id, Image = user.Image }; - + var topic = await _dataContext.Topics.FirstAsync(x => x.Id == post.TopicId); postResponse.TopicName = topic.Title; - + postResponse.ViewNumber = post.ViewNumber += 1; postResponse.SaveNumber = await _dataContext.PostSaves.Where(x=>x.PostId.Equals(Id)).CountAsync(); postResponse.CommentNumber = await _dataContext.PostComments.Where(x => x.PostId.Equals(Id)).CountAsync(); postResponse.LikeNumber = await _dataContext.PostLikes.Where(x=>x.PostId.Equals(x.PostId)).CountAsync(); - return new ApiSuccessResult(postResponse); + _dataContext.Posts.Update(post); + await _dataContext.SaveChangesAsync(); + return new ApiSuccessResult(postResponse); } - public async Task>> GetAll() + public async Task>> GetAll() { var posts = await _dataContext.Posts.ToListAsync(); var topics = await _dataContext.Topics.ToListAsync(); var users = await _dataContext.User.ToListAsync(); - var result = new List(); + var result = new List(); foreach (var item in posts) { - var post = _mapper.Map(item); + var post = _mapper.Map(item); var userShort = users.First(x => x.Id == item.UserId); if (userShort is not null) { @@ -270,10 +285,28 @@ public async Task>> GetAll() result.Add(post); } - return new ApiSuccessResult>(result); + return new ApiSuccessResult>(result); } - public async Task> Delete(string id) + public async Task> Delete(string id, string userId) + { + var post = await _dataContext.Posts.FirstOrDefaultAsync(x => x.Id.Equals(id) && x.UserId.ToString().Equals(userId)); + if (post is null) + { + return new ApiErrorResult("Không tìm thấy bài viết"); + } + if (post.Image != string.Empty) + { + await _storageService.DeleteFileAsync(post.Image); + } + _dataContext.Posts.Remove(post); + + await _dataContext.SaveChangesAsync(); + + return new ApiSuccessResult("Đã xóa bài viết"); + } + + public async Task> DeleteAdmin(string id) { var post = await _dataContext.Posts.FirstOrDefaultAsync(x => x.Id.Equals(id)); if (post is null) @@ -375,5 +408,7 @@ public async Task> GetReport() } return results; } + + } } diff --git a/VNH.Infrastructure/Implement/Common/StorageService.cs b/VNH.Infrastructure/Implement/Common/StorageService.cs index 9214745..1989130 100644 --- a/VNH.Infrastructure/Implement/Common/StorageService.cs +++ b/VNH.Infrastructure/Implement/Common/StorageService.cs @@ -1,9 +1,4 @@ using Microsoft.AspNetCore.Hosting; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using VNH.Application.Interfaces.Common; namespace VNH.Infrastructure.Implement.Common diff --git a/VNH.Infrastructure/Migrations/20231115135948_Add_SubId_For_Post.Designer.cs b/VNH.Infrastructure/Migrations/20231115135948_Add_SubId_For_Post.Designer.cs new file mode 100644 index 0000000..026ae06 --- /dev/null +++ b/VNH.Infrastructure/Migrations/20231115135948_Add_SubId_For_Post.Designer.cs @@ -0,0 +1,1874 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using VNH.Infrastructure.Presenters.Migrations; + +#nullable disable + +namespace VNH.Infrastructure.Migrations +{ + [DbContext(typeof(VietNamHistoryContext))] + [Migration("20231115135948_Add_SubId_For_Post")] + partial class Add_SubId_For_Post + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("AppRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("nvarchar(max)"); + + b.Property("ClaimValue") + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.ToTable("UserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(max)"); + + b.Property("ProviderDisplayName") + .HasColumnType("nvarchar(max)"); + + b.Property("ProviderKey") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId"); + + b.ToTable("AppUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("UserId", "RoleId"); + + b.ToTable("UserRoles", (string)null); + + b.HasData( + new + { + UserId = new Guid("d1f771da-b318-42f8-a003-5a15614216f5"), + RoleId = new Guid("a18be9c0-aa65-4af8-bd17-00bd9344e575") + }); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("LoginProvider") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("Value") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId"); + + b.ToTable("AppUserTokens", (string)null); + }); + + modelBuilder.Entity("VNH.Domain.Answer", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("AuthorId") + .HasColumnType("uniqueidentifier"); + + b.Property("Confirm") + .HasColumnType("bit"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("MostConfirm") + .HasColumnType("bit"); + + b.Property("PubDate") + .HasColumnType("datetime"); + + b.Property("QuestionId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.HasIndex("QuestionId"); + + b.ToTable("Answer"); + }); + + modelBuilder.Entity("VNH.Domain.AnswerVote", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("AnswerId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("AnswerId"); + + b.HasIndex("UserId"); + + b.ToTable("AnswerVote"); + }); + + modelBuilder.Entity("VNH.Domain.Course", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CourseName") + .IsRequired() + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Image") + .HasColumnType("nvarchar(max)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Course"); + }); + + modelBuilder.Entity("VNH.Domain.CourseComment", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .HasMaxLength(2000) + .HasColumnType("nvarchar(2000)"); + + b.Property("CourseId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("UpdatedAt") + .HasColumnType("datetime"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.HasIndex("UserId"); + + b.ToTable("CourseComment"); + }); + + modelBuilder.Entity("VNH.Domain.CourseRating", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CourseId") + .HasColumnType("uniqueidentifier"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.HasIndex("UserId"); + + b.ToTable("CourseRating"); + }); + + modelBuilder.Entity("VNH.Domain.CourseSave", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CourseId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.HasIndex("UserId"); + + b.ToTable("CourseSave"); + }); + + modelBuilder.Entity("VNH.Domain.CourseSubComment", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .HasMaxLength(2000) + .HasColumnType("nvarchar(2000)"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("PreCommentId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdatedAt") + .HasColumnType("datetime"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("PreCommentId"); + + b.HasIndex("UserId"); + + b.ToTable("CourseSubComment"); + }); + + modelBuilder.Entity("VNH.Domain.Document", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .HasColumnType("varbinary(max)"); + + b.Property("ContentType") + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("FileName") + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("varchar(255)"); + + b.Property("Image") + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("varchar(255)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Document"); + }); + + modelBuilder.Entity("VNH.Domain.DocumentSave", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("DocumentId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("UserId"); + + b.ToTable("DocumentSave"); + }); + + modelBuilder.Entity("VNH.Domain.Entities.Notification", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Title") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Notification"); + }); + + modelBuilder.Entity("VNH.Domain.Entities.NotificationDetail", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("IsRead") + .HasColumnType("int"); + + b.Property("NotificationId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("NotificationId"); + + b.HasIndex("UserId"); + + b.ToTable("NotificationDetails"); + }); + + modelBuilder.Entity("VNH.Domain.Entities.PostTag", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PostId") + .IsRequired() + .HasColumnType("nvarchar(255)"); + + b.Property("TagId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("TagId"); + + b.ToTable("PostTags"); + }); + + modelBuilder.Entity("VNH.Domain.Exercise", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Image") + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("varchar(255)"); + + b.Property("QuizId") + .HasColumnType("uniqueidentifier"); + + b.Property("Time") + .HasColumnType("time"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("varchar(255)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime"); + + b.HasKey("Id"); + + b.ToTable("Exercise"); + }); + + modelBuilder.Entity("VNH.Domain.ExerciseDetail", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("ExerciseId") + .HasColumnType("uniqueidentifier"); + + b.Property("TestMark") + .HasColumnType("float"); + + b.Property("TestTime") + .HasColumnType("datetime"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("ExerciseId"); + + b.HasIndex("UserId"); + + b.ToTable("ExerciseDetail"); + }); + + modelBuilder.Entity("VNH.Domain.Lesson", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CourseId") + .HasColumnType("uniqueidentifier"); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("nvarchar(2000)"); + + b.Property("ExerciseId") + .HasColumnType("uniqueidentifier"); + + b.Property("Title") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UrlVideo") + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.ToTable("Lesson"); + }); + + modelBuilder.Entity("VNH.Domain.News", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Image") + .HasColumnType("text"); + + b.Property("PubDate") + .HasColumnType("datetime"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Url") + .IsRequired() + .HasMaxLength(255) + .IsUnicode(false) + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.ToTable("News"); + }); + + modelBuilder.Entity("VNH.Domain.Post", b => + { + b.Property("Id") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("Image") + .HasColumnType("nvarchar(max)"); + + b.Property("SubId") + .HasMaxLength(300) + .HasColumnType("nvarchar(300)"); + + b.Property("Title") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("TopicId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdatedAt") + .HasColumnType("datetime"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.Property("ViewNumber") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TopicId"); + + b.HasIndex("UserId"); + + b.ToTable("Post"); + }); + + modelBuilder.Entity("VNH.Domain.PostComment", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("PostId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("PostComment"); + }); + + modelBuilder.Entity("VNH.Domain.PostLike", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("PostId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("PostLike"); + }); + + modelBuilder.Entity("VNH.Domain.PostReportDetail", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Checked") + .HasColumnType("bit"); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("PostId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("ReportDate") + .HasColumnType("datetime2"); + + b.Property("ReportId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("ReportId"); + + b.HasIndex("UserId"); + + b.ToTable("PostReportDetail"); + }); + + modelBuilder.Entity("VNH.Domain.PostSave", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("PostId") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("UserId"); + + b.ToTable("PostSave"); + }); + + modelBuilder.Entity("VNH.Domain.PostSubComment", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("PreCommentId") + .HasColumnType("uniqueidentifier"); + + b.Property("UpdatedAt") + .HasColumnType("datetime"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("PreCommentId"); + + b.HasIndex("UserId"); + + b.ToTable("PostSubComment"); + }); + + modelBuilder.Entity("VNH.Domain.Question", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("AuthorId") + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("PubDate") + .HasColumnType("datetime"); + + b.Property("QuestionTagId") + .HasColumnType("uniqueidentifier"); + + b.Property("Title") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("ViewNumber") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.ToTable("Question"); + }); + + modelBuilder.Entity("VNH.Domain.QuestionLike", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("QuestionId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("QuestionId"); + + b.HasIndex("UserId"); + + b.ToTable("QuestionLike"); + }); + + modelBuilder.Entity("VNH.Domain.QuestionReportDetail", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Checked") + .HasColumnType("bit"); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("QuestionId") + .HasColumnType("uniqueidentifier"); + + b.Property("ReportDate") + .HasColumnType("datetime2"); + + b.Property("ReportId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("QuestionId"); + + b.HasIndex("ReportId"); + + b.HasIndex("UserId"); + + b.ToTable("QuestionReportDetail"); + }); + + modelBuilder.Entity("VNH.Domain.QuestionSave", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("QuestionId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("QuestionId"); + + b.HasIndex("UserId"); + + b.ToTable("QuestionSave"); + }); + + modelBuilder.Entity("VNH.Domain.QuestionTag", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("TagId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("TagId"); + + b.ToTable("QuestionTag"); + }); + + modelBuilder.Entity("VNH.Domain.Quiz", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Answer1") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Answer2") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Answer3") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Answer4") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Question") + .HasColumnType("nvarchar(max)"); + + b.Property("RightAnswer") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.HasKey("Id"); + + b.ToTable("Quiz"); + }); + + modelBuilder.Entity("VNH.Domain.Report", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.HasKey("Id"); + + b.ToTable("Report"); + + b.HasData( + new + { + Id = new Guid("d30e1353-0163-43c1-b757-7957981b0eda"), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4498), + Description = " Báo cáo này được sử dụng khi người dùng chia sẻ nội dung cá nhân của bạn mà bạn cho rằng vi phạm quyền riêng tư của bạn.", + Title = "Nội dung vi phạm quy định về quyền riêng tư" + }, + new + { + Id = new Guid("25752490-4ba5-4abb-ac3b-192205cd1b6e"), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4512), + Description = "Sử dụng khi bạn thấy nội dung bài đăng chứa lời lẽ xúc phạm, kỳ thị hoặc có tính chất đe doạ đến người khác.", + Title = "Nội dung xấu, xúc phạm, hay kỳ thị" + }, + new + { + Id = new Guid("bab1da58-6921-44b9-837f-c58d3998497b"), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4514), + Description = "Dùng khi bạn thấy nội dung chứa hình ảnh hoặc video bạo lực hoặc đội nhóm xấu, hoặc khuyến khích hành vi bạo lực.", + Title = "Chứa nội dung bạo lực hoặc đội nhóm xấu" + }, + new + { + Id = new Guid("349ed807-6107-436f-9a4c-9d6183fbc444"), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4517), + Description = "Sử dụng khi bạn thấy nội dung chứa hình ảnh tự tử hoặc khuyến khích hành vi tự gây thương tổn.", + Title = "Chứa nội dung tự tử hoặc tự gây thương tổn" + }, + new + { + Id = new Guid("c4ddb872-06c5-4779-a8a3-a55e5b2c5347"), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4519), + Description = "Sử dụng khi bạn cho rằng Nội dung vi phạm quyền sở hữu trí tuệ hoặc bản quyền, chẳng hạn như sử dụng hình ảnh hoặc video mà bạn sở hữu mà không có sự cho phép.", + Title = "Nội dung vi phạm bản quyền hoặc sở hữu trí tuệ" + }, + new + { + Id = new Guid("4a780087-9058-41c9-b84b-944d1a502010"), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4521), + Description = "Sử dụng khi bạn thấy rằng nội dung chứa thông tin sai lệch, giả mạo hoặc vi phạm quy tắc về sự thật và trung thực.", + Title = "Bài đăng chứa thông tin sai lệch hoặc giả mạo" + }, + new + { + Id = new Guid("3043c693-b3c9-453e-9876-31c943222576"), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4523), + Description = "Dùng khi bạn muốn báo cáo vì nó quá nhiều thông báo hoặc quảng cáo không mong muốn.", + Title = "Nội dung xuất hiện quá nhiều thông báo hoặc quảng cáo không mong muốn" + }); + }); + + modelBuilder.Entity("VNH.Domain.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uniqueidentifier"); + + b.Property("ConcurrencyStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .HasColumnType("nvarchar(max)"); + + b.Property("NormalizedName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + + b.HasData( + new + { + Id = new Guid("a18be9c0-aa65-4af8-bd17-00bd9344e575"), + ConcurrencyStamp = "c049643c-c9b8-41d0-8395-d3a6663aa08c", + Name = "admin", + NormalizedName = "admin" + }, + new + { + Id = new Guid("cfafcfcd-d796-43f4-8ac0-ead43bd2f18a"), + ConcurrencyStamp = "42822a68-ed12-4cf6-bcc2-89669626ce1f", + Name = "teacher", + NormalizedName = "teacher" + }, + new + { + Id = new Guid("5d4e4081-91f8-4fc0-b8eb-9860b7849604"), + ConcurrencyStamp = "3c7eb7aa-d2ef-4743-b3c5-5f4033a49e32", + Name = "student", + NormalizedName = "student" + }); + }); + + modelBuilder.Entity("VNH.Domain.Search", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Search"); + }); + + modelBuilder.Entity("VNH.Domain.SubAnswer", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("AuthorId") + .HasColumnType("uniqueidentifier"); + + b.Property("Content") + .HasColumnType("nvarchar(max)"); + + b.Property("PreAnswerId") + .HasColumnType("uniqueidentifier"); + + b.Property("PubDate") + .HasColumnType("datetime"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.HasIndex("PreAnswerId"); + + b.ToTable("SubAnswer"); + }); + + modelBuilder.Entity("VNH.Domain.Tag", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Name") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.HasKey("Id"); + + b.ToTable("Tag"); + }); + + modelBuilder.Entity("VNH.Domain.Topic", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("AuthorId") + .HasColumnType("uniqueidentifier"); + + b.Property("CreatedAt") + .HasColumnType("datetime"); + + b.Property("Title") + .HasMaxLength(255) + .HasColumnType("nvarchar(255)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime"); + + b.HasKey("Id"); + + b.HasIndex("AuthorId"); + + b.ToTable("Topic"); + }); + + modelBuilder.Entity("VNH.Domain.TopicDetail", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("PostId") + .HasColumnType("nvarchar(255)"); + + b.Property("TopicId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("PostId"); + + b.HasIndex("TopicId"); + + b.ToTable("TopicDetail"); + }); + + modelBuilder.Entity("VNH.Domain.User", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("DateOfBirth") + .HasColumnType("datetime"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("EmailConfirmed") + .HasColumnType("bit"); + + b.Property("Fullname") + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Gender") + .HasColumnType("int"); + + b.Property("Image") + .HasMaxLength(3145728) + .HasColumnType("nvarchar(max)"); + + b.Property("Introduction") + .HasColumnType("nvarchar(max)"); + + b.Property("LockoutEnabled") + .HasColumnType("bit"); + + b.Property("LockoutEnd") + .HasColumnType("datetimeoffset"); + + b.Property("NormalizedEmail") + .HasColumnType("nvarchar(max)"); + + b.Property("NormalizedUserName") + .HasColumnType("nvarchar(max)"); + + b.Property("NumberConfirm") + .HasColumnType("nvarchar(max)"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("bit"); + + b.Property("SecurityStamp") + .HasColumnType("nvarchar(max)"); + + b.Property("TwoFactorEnabled") + .HasColumnType("bit"); + + b.Property("UserName") + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("User"); + + b.HasData( + new + { + Id = new Guid("d1f771da-b318-42f8-a003-5a15614216f5"), + AccessFailedCount = 0, + ConcurrencyStamp = "e4db3b3b-2a30-41be-9af7-9376685bcb91", + DateOfBirth = new DateTime(2002, 3, 18, 0, 0, 0, 0, DateTimeKind.Local), + Email = "admin@gmail.com", + EmailConfirmed = true, + Fullname = "Lương Xuân Nhất", + Gender = 0, + Image = "", + LockoutEnabled = false, + NormalizedEmail = "onionwebdev@gmail.com", + NormalizedUserName = "admin", + PasswordHash = "AQAAAAEAACcQAAAAEB0zhlwScfiTBuzJqqT3p3s7NJWVsU53x9K+0sUJFhZjzP3yeXNagsvqaA/7vIvKiA==", + PhoneNumberConfirmed = false, + SecurityStamp = "", + TwoFactorEnabled = false, + UserName = "admin" + }); + }); + + modelBuilder.Entity("VNH.Domain.Answer", b => + { + b.HasOne("VNH.Domain.User", "Author") + .WithMany("Answers") + .HasForeignKey("AuthorId") + .HasConstraintName("FK__Answer__AuthorId__1AD3FDA4"); + + b.HasOne("VNH.Domain.Question", "Questions") + .WithMany("Answers") + .HasForeignKey("QuestionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__Answer__QuestionId__1AD3FVA4"); + + b.Navigation("Author"); + + b.Navigation("Questions"); + }); + + modelBuilder.Entity("VNH.Domain.AnswerVote", b => + { + b.HasOne("VNH.Domain.Answer", "Answer") + .WithMany("AnswerVotes") + .HasForeignKey("AnswerId") + .HasConstraintName("FK__AnswerVot__Answe__1DB06A4F"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("AnswerVotes") + .HasForeignKey("UserId") + .HasConstraintName("FK__AnswerVot__UserI__1EA48E88"); + + b.Navigation("Answer"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.Course", b => + { + b.HasOne("VNH.Domain.User", "User") + .WithMany("Courses") + .HasForeignKey("UserId") + .HasConstraintName("FK__Course__UserId__787EE5A0"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.CourseComment", b => + { + b.HasOne("VNH.Domain.Course", "Course") + .WithMany("CourseComments") + .HasForeignKey("CourseId") + .HasConstraintName("FK__CourseCom__Cours__7A672E12"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("CourseComments") + .HasForeignKey("UserId") + .HasConstraintName("FK__CourseCom__UserI__797309D9"); + + b.Navigation("Course"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.CourseRating", b => + { + b.HasOne("VNH.Domain.Course", "Course") + .WithMany("CourseRatings") + .HasForeignKey("CourseId") + .HasConstraintName("FK__CourseRat__Cours__7D439ABD"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("CourseRatings") + .HasForeignKey("UserId") + .HasConstraintName("FK__CourseRat__UserI__7E37BEF6"); + + b.Navigation("Course"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.CourseSave", b => + { + b.HasOne("VNH.Domain.Course", "Course") + .WithMany("CourseSaves") + .HasForeignKey("CourseId") + .HasConstraintName("FK__CourseSav__Cours__04E4BC85"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("CourseSaves") + .HasForeignKey("UserId") + .HasConstraintName("FK__CourseSav__UserI__03F0984C"); + + b.Navigation("Course"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.CourseSubComment", b => + { + b.HasOne("VNH.Domain.CourseComment", "PreComment") + .WithMany("CourseSubComments") + .HasForeignKey("PreCommentId") + .HasConstraintName("FK__CourseSub__PreCo__7C4F7684"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("CourseSubComments") + .HasForeignKey("UserId") + .HasConstraintName("FK__CourseSub__UserI__7B5B524B"); + + b.Navigation("PreComment"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.Document", b => + { + b.HasOne("VNH.Domain.User", "User") + .WithMany("Documents") + .HasForeignKey("UserId") + .HasConstraintName("FK__Document__UserId__0A9D95DB"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.DocumentSave", b => + { + b.HasOne("VNH.Domain.Document", "Document") + .WithMany("DocumentSaves") + .HasForeignKey("DocumentId") + .HasConstraintName("FK__DocumentS__Docum__0C85DE4D"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("DocumentSaves") + .HasForeignKey("UserId") + .HasConstraintName("FK__DocumentS__UserI__0B91BA14"); + + b.Navigation("Document"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.Entities.NotificationDetail", b => + { + b.HasOne("VNH.Domain.Entities.Notification", "Notification") + .WithMany("NotificationDetails") + .HasForeignKey("NotificationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__NotificationDetail__NotificationId__1EQ48E88"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("NotificationDetails") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__NotificationDetail__UserId__1EA48E88"); + + b.Navigation("Notification"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.Entities.PostTag", b => + { + b.HasOne("VNH.Domain.Post", "Post") + .WithMany("PostTags") + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("VNH.Domain.Tag", "Tag") + .WithMany("PostTags") + .HasForeignKey("TagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("Tag"); + }); + + modelBuilder.Entity("VNH.Domain.Exercise", b => + { + b.HasOne("VNH.Domain.Lesson", "IdNavigation") + .WithOne("Exercise") + .HasForeignKey("VNH.Domain.Exercise", "Id") + .IsRequired() + .HasConstraintName("FK__Exercise__Id__282DF8C2"); + + b.Navigation("IdNavigation"); + }); + + modelBuilder.Entity("VNH.Domain.ExerciseDetail", b => + { + b.HasOne("VNH.Domain.Exercise", "Exercise") + .WithMany("ExerciseDetails") + .HasForeignKey("ExerciseId") + .HasConstraintName("FK__ExerciseD__Exerc__02084FDA"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("ExerciseDetails") + .HasForeignKey("UserId") + .HasConstraintName("FK__ExerciseD__UserI__01142BA1"); + + b.Navigation("Exercise"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.Lesson", b => + { + b.HasOne("VNH.Domain.Course", "Course") + .WithMany("Lessons") + .HasForeignKey("CourseId") + .HasConstraintName("FK__Lesson__CourseId__7F2BE32F"); + + b.Navigation("Course"); + }); + + modelBuilder.Entity("VNH.Domain.Post", b => + { + b.HasOne("VNH.Domain.Topic", "Topic") + .WithMany("Posts") + .HasForeignKey("TopicId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__Post__TopicId__76969D2E"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("Posts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__Post__UserId__778AC167"); + + b.Navigation("Topic"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.PostComment", b => + { + b.HasOne("VNH.Domain.Post", "Post") + .WithMany("PostComments") + .HasForeignKey("PostId") + .HasConstraintName("FK__PostComme__PostI__0F624AF8"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("PostComments") + .HasForeignKey("UserId") + .HasConstraintName("FK__PostComme__UserI__10566F31"); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.PostLike", b => + { + b.HasOne("VNH.Domain.Post", "Post") + .WithMany("PostLikes") + .HasForeignKey("PostId") + .HasConstraintName("FK__PostLike__PostId__1332DBDC"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("PostLikes") + .HasForeignKey("UserId") + .HasConstraintName("FK__PostLike__UserId__14270015"); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.PostReportDetail", b => + { + b.HasOne("VNH.Domain.Post", "Post") + .WithMany("PostReportDetails") + .HasForeignKey("PostId") + .HasConstraintName("FK__PostRepor__PostI__17036CC0"); + + b.HasOne("VNH.Domain.Report", "Report") + .WithMany("PostReportDetails") + .HasForeignKey("ReportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__PostRepor__Repor__151B244E"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("PostReportDetails") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__PostRepor__UserI__160F4887"); + + b.Navigation("Post"); + + b.Navigation("Report"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.PostSave", b => + { + b.HasOne("VNH.Domain.Post", "Post") + .WithMany("PostSaves") + .HasForeignKey("PostId") + .HasConstraintName("FK__PostSave__PostId__08B54D69"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("PostSaves") + .HasForeignKey("UserId") + .HasConstraintName("FK__PostSave__UserId__09A971A2"); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.PostSubComment", b => + { + b.HasOne("VNH.Domain.PostComment", "PreComment") + .WithMany("PostSubComments") + .HasForeignKey("PreCommentId") + .HasConstraintName("FK__PostSubCo__PreCo__114A936A"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("PostSubComments") + .HasForeignKey("UserId") + .HasConstraintName("FK__PostSubCo__UserI__123EB7A3"); + + b.Navigation("PreComment"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.Question", b => + { + b.HasOne("VNH.Domain.User", "Author") + .WithMany("Questions") + .HasForeignKey("AuthorId") + .HasConstraintName("FK__Question__Author__18EBB532"); + + b.Navigation("Author"); + }); + + modelBuilder.Entity("VNH.Domain.QuestionLike", b => + { + b.HasOne("VNH.Domain.Question", "Question") + .WithMany("QuestionLikes") + .HasForeignKey("QuestionId") + .HasConstraintName("FK__QuestionL__Quest__1F98B2C1"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("QuestionLikes") + .HasForeignKey("UserId") + .HasConstraintName("FK__QuestionL__UserI__208CD6FA"); + + b.Navigation("Question"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.QuestionReportDetail", b => + { + b.HasOne("VNH.Domain.Question", "Question") + .WithMany("QuestionReportDetails") + .HasForeignKey("QuestionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__QuestionR__Quest__2180FB33"); + + b.HasOne("VNH.Domain.Report", "Report") + .WithMany("QuestionReportDetails") + .HasForeignKey("ReportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__QuestionR__Quest__22751F6C"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("QuestionReportDetails") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("FK__QuestionR__UserI__236943A5"); + + b.Navigation("Question"); + + b.Navigation("Report"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.QuestionSave", b => + { + b.HasOne("VNH.Domain.Question", "Question") + .WithMany("QuestionSaves") + .HasForeignKey("QuestionId") + .HasConstraintName("FK__QuestionS__Quest__25518C17"); + + b.HasOne("VNH.Domain.User", "User") + .WithMany("QuestionSaves") + .HasForeignKey("UserId") + .HasConstraintName("FK__QuestionS__UserI__245D67DE"); + + b.Navigation("Question"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.QuestionTag", b => + { + b.HasOne("VNH.Domain.Question", "IdNavigation") + .WithOne("QuestionTag") + .HasForeignKey("VNH.Domain.QuestionTag", "Id") + .IsRequired() + .HasConstraintName("FK__QuestionTag__Id__2739D489"); + + b.HasOne("VNH.Domain.Tag", "Tag") + .WithMany("QuestionTags") + .HasForeignKey("TagId") + .HasConstraintName("FK__QuestionT__TagId__2645B050"); + + b.Navigation("IdNavigation"); + + b.Navigation("Tag"); + }); + + modelBuilder.Entity("VNH.Domain.Quiz", b => + { + b.HasOne("VNH.Domain.Exercise", "IdNavigation") + .WithOne("Quiz") + .HasForeignKey("VNH.Domain.Quiz", "Id") + .IsRequired() + .HasConstraintName("FK__Quiz__Id__29221CFB"); + + b.Navigation("IdNavigation"); + }); + + modelBuilder.Entity("VNH.Domain.Search", b => + { + b.HasOne("VNH.Domain.User", "User") + .WithMany("Searches") + .HasForeignKey("UserId") + .HasConstraintName("FK__Search__UserId__17F790F9"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("VNH.Domain.SubAnswer", b => + { + b.HasOne("VNH.Domain.User", "Author") + .WithMany("SubAnswers") + .HasForeignKey("AuthorId") + .HasConstraintName("FK__SubAnswer__Autho__1CBC4616"); + + b.HasOne("VNH.Domain.Answer", "PreAnswer") + .WithMany("SubAnswers") + .HasForeignKey("PreAnswerId") + .HasConstraintName("FK__SubAnswer__PreAn__1BC821DD"); + + b.Navigation("Author"); + + b.Navigation("PreAnswer"); + }); + + modelBuilder.Entity("VNH.Domain.Topic", b => + { + b.HasOne("VNH.Domain.User", "Author") + .WithMany("Topics") + .HasForeignKey("AuthorId") + .HasConstraintName("FK__Topic__AuthorId__05D8E0BE"); + + b.Navigation("Author"); + }); + + modelBuilder.Entity("VNH.Domain.TopicDetail", b => + { + b.HasOne("VNH.Domain.Post", "Post") + .WithMany("TopicDetails") + .HasForeignKey("PostId") + .HasConstraintName("FK__TopicDeta__TagId__07C12930"); + + b.HasOne("VNH.Domain.Topic", "Topic") + .WithMany("TopicDetails") + .HasForeignKey("TopicId") + .HasConstraintName("FK__TopicDeta__Topic__06CD04F7"); + + b.Navigation("Post"); + + b.Navigation("Topic"); + }); + + modelBuilder.Entity("VNH.Domain.Answer", b => + { + b.Navigation("AnswerVotes"); + + b.Navigation("SubAnswers"); + }); + + modelBuilder.Entity("VNH.Domain.Course", b => + { + b.Navigation("CourseComments"); + + b.Navigation("CourseRatings"); + + b.Navigation("CourseSaves"); + + b.Navigation("Lessons"); + }); + + modelBuilder.Entity("VNH.Domain.CourseComment", b => + { + b.Navigation("CourseSubComments"); + }); + + modelBuilder.Entity("VNH.Domain.Document", b => + { + b.Navigation("DocumentSaves"); + }); + + modelBuilder.Entity("VNH.Domain.Entities.Notification", b => + { + b.Navigation("NotificationDetails"); + }); + + modelBuilder.Entity("VNH.Domain.Exercise", b => + { + b.Navigation("ExerciseDetails"); + + b.Navigation("Quiz"); + }); + + modelBuilder.Entity("VNH.Domain.Lesson", b => + { + b.Navigation("Exercise"); + }); + + modelBuilder.Entity("VNH.Domain.Post", b => + { + b.Navigation("PostComments"); + + b.Navigation("PostLikes"); + + b.Navigation("PostReportDetails"); + + b.Navigation("PostSaves"); + + b.Navigation("PostTags"); + + b.Navigation("TopicDetails"); + }); + + modelBuilder.Entity("VNH.Domain.PostComment", b => + { + b.Navigation("PostSubComments"); + }); + + modelBuilder.Entity("VNH.Domain.Question", b => + { + b.Navigation("Answers"); + + b.Navigation("QuestionLikes"); + + b.Navigation("QuestionReportDetails"); + + b.Navigation("QuestionSaves"); + + b.Navigation("QuestionTag"); + }); + + modelBuilder.Entity("VNH.Domain.Report", b => + { + b.Navigation("PostReportDetails"); + + b.Navigation("QuestionReportDetails"); + }); + + modelBuilder.Entity("VNH.Domain.Tag", b => + { + b.Navigation("PostTags"); + + b.Navigation("QuestionTags"); + }); + + modelBuilder.Entity("VNH.Domain.Topic", b => + { + b.Navigation("Posts"); + + b.Navigation("TopicDetails"); + }); + + modelBuilder.Entity("VNH.Domain.User", b => + { + b.Navigation("AnswerVotes"); + + b.Navigation("Answers"); + + b.Navigation("CourseComments"); + + b.Navigation("CourseRatings"); + + b.Navigation("CourseSaves"); + + b.Navigation("CourseSubComments"); + + b.Navigation("Courses"); + + b.Navigation("DocumentSaves"); + + b.Navigation("Documents"); + + b.Navigation("ExerciseDetails"); + + b.Navigation("NotificationDetails"); + + b.Navigation("PostComments"); + + b.Navigation("PostLikes"); + + b.Navigation("PostReportDetails"); + + b.Navigation("PostSaves"); + + b.Navigation("PostSubComments"); + + b.Navigation("Posts"); + + b.Navigation("QuestionLikes"); + + b.Navigation("QuestionReportDetails"); + + b.Navigation("QuestionSaves"); + + b.Navigation("Questions"); + + b.Navigation("Searches"); + + b.Navigation("SubAnswers"); + + b.Navigation("Topics"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/VNH.Infrastructure/Migrations/20231115135948_Add_SubId_For_Post.cs b/VNH.Infrastructure/Migrations/20231115135948_Add_SubId_For_Post.cs new file mode 100644 index 0000000..d8717a3 --- /dev/null +++ b/VNH.Infrastructure/Migrations/20231115135948_Add_SubId_For_Post.cs @@ -0,0 +1,95 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace VNH.Infrastructure.Migrations +{ + /// + public partial class Add_SubId_For_Post : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK__Post__UserId__778AC167", + table: "Post"); + + migrationBuilder.AlterColumn( + name: "UserId", + table: "Post", + type: "uniqueidentifier", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000"), + oldClrType: typeof(Guid), + oldType: "uniqueidentifier", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Title", + table: "Post", + type: "nvarchar(255)", + maxLength: 255, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(255)", + oldMaxLength: 255); + + migrationBuilder.AddColumn( + name: "SubId", + table: "Post", + type: "varchar(300)", + maxLength: 300, + nullable: true); + + + migrationBuilder.AddForeignKey( + name: "FK__Post__UserId__778AC167", + table: "Post", + column: "UserId", + principalTable: "User", + principalColumn: "Id", + onDelete: ReferentialAction.NoAction); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK__Post__UserId__778AC167", + table: "Post"); + + migrationBuilder.DropColumn( + name: "SubId", + table: "Post"); + + migrationBuilder.AlterColumn( + name: "UserId", + table: "Post", + type: "uniqueidentifier", + nullable: true, + oldClrType: typeof(Guid), + oldType: "uniqueidentifier"); + + migrationBuilder.AlterColumn( + name: "Title", + table: "Post", + type: "nvarchar(255)", + maxLength: 255, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(255)", + oldMaxLength: 255, + oldNullable: true); + + + migrationBuilder.AddForeignKey( + name: "FK__Post__UserId__778AC167", + table: "Post", + column: "UserId", + principalTable: "User", + principalColumn: "Id"); + } + } +} diff --git a/VNH.Infrastructure/Migrations/VietNamHistoryContextModelSnapshot.cs b/VNH.Infrastructure/Migrations/VietNamHistoryContextModelSnapshot.cs index bf7da57..b49c79c 100644 --- a/VNH.Infrastructure/Migrations/VietNamHistoryContextModelSnapshot.cs +++ b/VNH.Infrastructure/Migrations/VietNamHistoryContextModelSnapshot.cs @@ -589,8 +589,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Image") .HasColumnType("nvarchar(max)"); + b.Property("SubId") + .HasMaxLength(300) + .HasColumnType("nvarchar(300)"); + b.Property("Title") - .IsRequired() .HasMaxLength(255) .HasColumnType("nvarchar(255)"); @@ -600,7 +603,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("UpdatedAt") .HasColumnType("datetime"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("uniqueidentifier"); b.Property("ViewNumber") @@ -931,49 +934,49 @@ protected override void BuildModel(ModelBuilder modelBuilder) new { Id = new Guid("d30e1353-0163-43c1-b757-7957981b0eda"), - CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5927), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4498), Description = " Báo cáo này được sử dụng khi người dùng chia sẻ nội dung cá nhân của bạn mà bạn cho rằng vi phạm quyền riêng tư của bạn.", Title = "Nội dung vi phạm quy định về quyền riêng tư" }, new { Id = new Guid("25752490-4ba5-4abb-ac3b-192205cd1b6e"), - CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5947), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4512), Description = "Sử dụng khi bạn thấy nội dung bài đăng chứa lời lẽ xúc phạm, kỳ thị hoặc có tính chất đe doạ đến người khác.", Title = "Nội dung xấu, xúc phạm, hay kỳ thị" }, new { Id = new Guid("bab1da58-6921-44b9-837f-c58d3998497b"), - CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5949), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4514), Description = "Dùng khi bạn thấy nội dung chứa hình ảnh hoặc video bạo lực hoặc đội nhóm xấu, hoặc khuyến khích hành vi bạo lực.", Title = "Chứa nội dung bạo lực hoặc đội nhóm xấu" }, new { Id = new Guid("349ed807-6107-436f-9a4c-9d6183fbc444"), - CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5953), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4517), Description = "Sử dụng khi bạn thấy nội dung chứa hình ảnh tự tử hoặc khuyến khích hành vi tự gây thương tổn.", Title = "Chứa nội dung tự tử hoặc tự gây thương tổn" }, new { Id = new Guid("c4ddb872-06c5-4779-a8a3-a55e5b2c5347"), - CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5956), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4519), Description = "Sử dụng khi bạn cho rằng Nội dung vi phạm quyền sở hữu trí tuệ hoặc bản quyền, chẳng hạn như sử dụng hình ảnh hoặc video mà bạn sở hữu mà không có sự cho phép.", Title = "Nội dung vi phạm bản quyền hoặc sở hữu trí tuệ" }, new { Id = new Guid("4a780087-9058-41c9-b84b-944d1a502010"), - CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5959), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4521), Description = "Sử dụng khi bạn thấy rằng nội dung chứa thông tin sai lệch, giả mạo hoặc vi phạm quy tắc về sự thật và trung thực.", Title = "Bài đăng chứa thông tin sai lệch hoặc giả mạo" }, new { Id = new Guid("3043c693-b3c9-453e-9876-31c943222576"), - CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5961), + CreatedAt = new DateTime(2023, 11, 15, 20, 59, 47, 967, DateTimeKind.Local).AddTicks(4523), Description = "Dùng khi bạn muốn báo cáo vì nó quá nhiều thông báo hoặc quảng cáo không mong muốn.", Title = "Nội dung xuất hiện quá nhiều thông báo hoặc quảng cáo không mong muốn" }); @@ -1002,21 +1005,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) new { Id = new Guid("a18be9c0-aa65-4af8-bd17-00bd9344e575"), - ConcurrencyStamp = "157e4a93-81f2-48c6-a1a9-511f70d19c99", + ConcurrencyStamp = "c049643c-c9b8-41d0-8395-d3a6663aa08c", Name = "admin", NormalizedName = "admin" }, new { Id = new Guid("cfafcfcd-d796-43f4-8ac0-ead43bd2f18a"), - ConcurrencyStamp = "55fcc52e-27d5-4665-8967-13fe97e02ebe", + ConcurrencyStamp = "42822a68-ed12-4cf6-bcc2-89669626ce1f", Name = "teacher", NormalizedName = "teacher" }, new { Id = new Guid("5d4e4081-91f8-4fc0-b8eb-9860b7849604"), - ConcurrencyStamp = "a0e89f69-ee8c-4a09-be4d-4a9857fbc8d3", + ConcurrencyStamp = "3c7eb7aa-d2ef-4743-b3c5-5f4033a49e32", Name = "student", NormalizedName = "student" }); @@ -1202,7 +1205,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { Id = new Guid("d1f771da-b318-42f8-a003-5a15614216f5"), AccessFailedCount = 0, - ConcurrencyStamp = "16823ad9-fa17-4b28-a964-b367dc4ff5e4", + ConcurrencyStamp = "e4db3b3b-2a30-41be-9af7-9376685bcb91", DateOfBirth = new DateTime(2002, 3, 18, 0, 0, 0, 0, DateTimeKind.Local), Email = "admin@gmail.com", EmailConfirmed = true, @@ -1212,7 +1215,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) LockoutEnabled = false, NormalizedEmail = "onionwebdev@gmail.com", NormalizedUserName = "admin", - PasswordHash = "AQAAAAEAACcQAAAAEKBatixPeSdVUG7X4YQBbyiJZRsH7gYPsSCSoDGJUBmJtWNmm9381o9NNa6J4kJndQ==", + PasswordHash = "AQAAAAEAACcQAAAAEB0zhlwScfiTBuzJqqT3p3s7NJWVsU53x9K+0sUJFhZjzP3yeXNagsvqaA/7vIvKiA==", PhoneNumberConfirmed = false, SecurityStamp = "", TwoFactorEnabled = false, @@ -1451,6 +1454,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasOne("VNH.Domain.User", "User") .WithMany("Posts") .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() .HasConstraintName("FK__Post__UserId__778AC167"); b.Navigation("Topic"); diff --git a/VNH.WebAPi/Controllers/PostController.cs b/VNH.WebAPi/Controllers/PostController.cs index fa32a2a..9e797f7 100644 --- a/VNH.WebAPi/Controllers/PostController.cs +++ b/VNH.WebAPi/Controllers/PostController.cs @@ -1,8 +1,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System.Security.Claims; using VNH.Application.DTOs.Catalog.Posts; using VNH.Application.Interfaces.Posts; -using VNH.Domain; namespace VNH.WebAPi.Controllers { @@ -50,10 +50,17 @@ public async Task Detail(string id) } [HttpDelete] - [Authorize] public async Task Delete(string Id) { - var result = await _postService.Delete(Id); + var result = await _postService.Delete(Id, User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? ""); + return result is null ? BadRequest(result) : Ok(result); + } + + [HttpDelete("delete")] + [Authorize(Roles = "admin")] + public async Task DeleteAdmin(string Id) + { + var result = await _postService.DeleteAdmin(Id); return result is null ? BadRequest(result) : Ok(result); } diff --git a/VNH.WebAPi/appsettings.json b/VNH.WebAPi/appsettings.json index a59ca2c..8d5d4dd 100644 --- a/VNH.WebAPi/appsettings.json +++ b/VNH.WebAPi/appsettings.json @@ -11,8 +11,12 @@ "Issuer": "https://webapi.tedu.com.vn" }, "ConnectionStrings": { - "DataConnect": "Data Source=SQL5110.site4now.net;Initial Catalog=db_aa121e_vuanhpham25;User Id=db_aa121e_vuanhpham25_admin;Password=30102002Mai" + "DataConnect": "Data Source=.;Initial Catalog=VietNamHistory_2;Integrated Security=True;Encrypt=true;TrustServerCertificate=true;" }, + //"ConnectionStrings": { + // "DataConnect": "Data Source=SQL5111.site4now.net;Initial Catalog=db_aa121e_vuanhpham25;User Id=db_aa121e_vuanhpham25_admin;Password=30102002Mai" + //}, + "MailSettings": { "Mail": "xuannhat1932002@gmail.com", "DisplayName": "[Nguoi Ke Su]", diff --git a/VNH.WebAPi/wwwroot/Images/0b8dcf23-280d-42a4-a5e9-66c03c3ec100.jpg b/VNH.WebAPi/wwwroot/Images/0b8dcf23-280d-42a4-a5e9-66c03c3ec100.jpg new file mode 100644 index 0000000..94ac5d8 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/0b8dcf23-280d-42a4-a5e9-66c03c3ec100.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/0bfff704-5419-44b7-890a-f0eae7d0a3a5.jpg b/VNH.WebAPi/wwwroot/Images/0bfff704-5419-44b7-890a-f0eae7d0a3a5.jpg new file mode 100644 index 0000000..94ac5d8 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/0bfff704-5419-44b7-890a-f0eae7d0a3a5.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/388a0d16-aa7f-43b6-844b-1e54239a4dde.jpg b/VNH.WebAPi/wwwroot/Images/388a0d16-aa7f-43b6-844b-1e54239a4dde.jpg new file mode 100644 index 0000000..3bcd629 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/388a0d16-aa7f-43b6-844b-1e54239a4dde.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/5d1cb295-0303-407d-8503-c6cc299ccaba.webp b/VNH.WebAPi/wwwroot/Images/5d1cb295-0303-407d-8503-c6cc299ccaba.webp new file mode 100644 index 0000000..0ad6320 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/5d1cb295-0303-407d-8503-c6cc299ccaba.webp differ diff --git a/VNH.WebAPi/wwwroot/Images/5fe36804-d6f5-463c-9758-b08e84827002.jpg b/VNH.WebAPi/wwwroot/Images/5fe36804-d6f5-463c-9758-b08e84827002.jpg new file mode 100644 index 0000000..3bcd629 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/5fe36804-d6f5-463c-9758-b08e84827002.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/722cc51c-e4a3-4bfc-ac5c-9f7708cba3ba.jpg b/VNH.WebAPi/wwwroot/Images/722cc51c-e4a3-4bfc-ac5c-9f7708cba3ba.jpg new file mode 100644 index 0000000..6c50053 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/722cc51c-e4a3-4bfc-ac5c-9f7708cba3ba.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/90999f1f-7bc0-4299-9e15-515b4b666e80.jpg b/VNH.WebAPi/wwwroot/Images/90999f1f-7bc0-4299-9e15-515b4b666e80.jpg new file mode 100644 index 0000000..94ac5d8 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/90999f1f-7bc0-4299-9e15-515b4b666e80.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/9213abc8-f92e-45c6-b6a4-ba26ab11bf8f.jpg b/VNH.WebAPi/wwwroot/Images/9213abc8-f92e-45c6-b6a4-ba26ab11bf8f.jpg new file mode 100644 index 0000000..94ac5d8 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/9213abc8-f92e-45c6-b6a4-ba26ab11bf8f.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/9311869c-0250-4454-9f23-f0008ff1df25.jpg b/VNH.WebAPi/wwwroot/Images/9311869c-0250-4454-9f23-f0008ff1df25.jpg new file mode 100644 index 0000000..94ac5d8 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/9311869c-0250-4454-9f23-f0008ff1df25.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/ba338d23-206a-4860-8250-df454edaa5a9.jpg b/VNH.WebAPi/wwwroot/Images/ba338d23-206a-4860-8250-df454edaa5a9.jpg new file mode 100644 index 0000000..d38e010 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/ba338d23-206a-4860-8250-df454edaa5a9.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/c5fa9e72-b3dc-4602-b364-499a52fd4eb4.jpg b/VNH.WebAPi/wwwroot/Images/c5fa9e72-b3dc-4602-b364-499a52fd4eb4.jpg new file mode 100644 index 0000000..94ac5d8 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/c5fa9e72-b3dc-4602-b364-499a52fd4eb4.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/cfa7441c-2dba-40ec-96f1-3eab8d75038a.jpg b/VNH.WebAPi/wwwroot/Images/cfa7441c-2dba-40ec-96f1-3eab8d75038a.jpg new file mode 100644 index 0000000..94ac5d8 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/cfa7441c-2dba-40ec-96f1-3eab8d75038a.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/d150588a-521f-4566-b275-fa9672ca6c17.jpg b/VNH.WebAPi/wwwroot/Images/d150588a-521f-4566-b275-fa9672ca6c17.jpg new file mode 100644 index 0000000..94ac5d8 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/d150588a-521f-4566-b275-fa9672ca6c17.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/dd42bbfc-570f-43ee-b805-60037ad12a88.jpg b/VNH.WebAPi/wwwroot/Images/dd42bbfc-570f-43ee-b805-60037ad12a88.jpg new file mode 100644 index 0000000..8e3a875 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/dd42bbfc-570f-43ee-b805-60037ad12a88.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/eb5c7df6-3116-4a2a-afa5-9850591a5180.jpg b/VNH.WebAPi/wwwroot/Images/eb5c7df6-3116-4a2a-afa5-9850591a5180.jpg new file mode 100644 index 0000000..94ac5d8 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/eb5c7df6-3116-4a2a-afa5-9850591a5180.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/f3e712b0-0cae-45ea-a125-b76b4f755182.jpg b/VNH.WebAPi/wwwroot/Images/f3e712b0-0cae-45ea-a125-b76b4f755182.jpg new file mode 100644 index 0000000..d38e010 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/f3e712b0-0cae-45ea-a125-b76b4f755182.jpg differ diff --git a/VNH.WebAPi/wwwroot/Images/fd4345ef-b792-4b9d-a198-7d9db0d0f457.jpg b/VNH.WebAPi/wwwroot/Images/fd4345ef-b792-4b9d-a198-7d9db0d0f457.jpg new file mode 100644 index 0000000..3bcd629 Binary files /dev/null and b/VNH.WebAPi/wwwroot/Images/fd4345ef-b792-4b9d-a198-7d9db0d0f457.jpg differ