From 6634db9ad685150df0bbce570cb9b9ad25a10a72 Mon Sep 17 00:00:00 2001 From: LuongXuanNhat Date: Fri, 10 Nov 2023 21:34:36 +0700 Subject: [PATCH] #27 | Deloy test sussces --- .../Common/Contants/SystemConstants.cs | 4 + .../DTOs/Catalog/Posts/PostResponsetDto.cs | 14 +- .../DTOs/Catalog/Users/UserUpdateDto.cs | 8 +- .../Catalog/Accounts/IAccountService.cs | 9 +- .../Interfaces/Catalog/Posts/IPostService.cs | 2 +- .../Interfaces/Common/IImageService.cs | 1 + .../Interfaces/Common/IStorageService.cs | 10 + VNH.Domain/Entities/Course.cs | 2 +- VNH.Domain/Entities/Document.cs | 4 +- VNH.Domain/Entities/News.cs | 4 +- VNH.Domain/Entities/Post.cs | 2 +- VNH.Domain/Entities/User.cs | 2 +- .../DependencyInjectionInfrastructure.cs | 6 +- .../Catalog/Account/AccountService.cs | 49 +- .../Implement/Catalog/Posts/PostService.cs | 49 +- .../Implement/Catalog/Users/UserService.cs | 15 +- .../Implement/Common/ImageService.cs | 17 + .../Implement/Common/StorageService.cs | 43 + ...9154951_Update_Image_Attribute.Designer.cs | 1869 +++++++++++++++++ .../20231109154951_Update_Image_Attribute.cs | 201 ++ .../VietNamHistoryContextModelSnapshot.cs | 50 +- .../DbContext/VietNamHistoryContext.cs | 3 +- VNH.WebAPi/.config/dotnet-tools.json | 12 + VNH.WebAPi/Controllers/AccountController.cs | 49 +- VNH.WebAPi/Program.cs | 10 +- VNH.WebAPi/VNH.WebAPi.csproj | 15 +- VNH.WebAPi/appsettings.json | 2 +- VNH.WebAPi/wwwroot/Images/facebook.png | Bin 0 -> 1891 bytes 28 files changed, 2329 insertions(+), 123 deletions(-) create mode 100644 VNH.Application/Interfaces/Common/IStorageService.cs create mode 100644 VNH.Infrastructure/Implement/Common/StorageService.cs create mode 100644 VNH.Infrastructure/Migrations/20231109154951_Update_Image_Attribute.Designer.cs create mode 100644 VNH.Infrastructure/Migrations/20231109154951_Update_Image_Attribute.cs create mode 100644 VNH.WebAPi/.config/dotnet-tools.json create mode 100644 VNH.WebAPi/wwwroot/Images/facebook.png diff --git a/VNH.Application/Common/Contants/SystemConstants.cs b/VNH.Application/Common/Contants/SystemConstants.cs index da7bc3f..2434fca 100644 --- a/VNH.Application/Common/Contants/SystemConstants.cs +++ b/VNH.Application/Common/Contants/SystemConstants.cs @@ -10,5 +10,9 @@ 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;"; } } diff --git a/VNH.Application/DTOs/Catalog/Posts/PostResponsetDto.cs b/VNH.Application/DTOs/Catalog/Posts/PostResponsetDto.cs index 19ab39d..540376d 100644 --- a/VNH.Application/DTOs/Catalog/Posts/PostResponsetDto.cs +++ b/VNH.Application/DTOs/Catalog/Posts/PostResponsetDto.cs @@ -1,4 +1,6 @@ using Microsoft.AspNetCore.Http; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using System.ComponentModel.DataAnnotations.Schema; using VNH.Application.DTOs.Catalog.HashTags; using VNH.Application.DTOs.Catalog.Users; using VNH.Domain; @@ -7,11 +9,13 @@ namespace VNH.Application.DTOs.Catalog.Posts { public class PostResponsetDto { - public string Id { get; set; } - public string Title { get; set; } - public string Content { get; set; } - public string Image { get; set; } - public string TopicName { get; set; } + public string Id { 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; + public DateTime? CreatedAt { get; set; } + public DateTime? UpdatedAt { get; set; } + public string TopicName { get; set; } = string.Empty; public List Tags { get; set; } = new List(); public UserShortDto UserShort { get; set; } = new UserShortDto(); public int ViewNumber { get; set; } = 0; diff --git a/VNH.Application/DTOs/Catalog/Users/UserUpdateDto.cs b/VNH.Application/DTOs/Catalog/Users/UserUpdateDto.cs index 67d8551..18aa13d 100644 --- a/VNH.Application/DTOs/Catalog/Users/UserUpdateDto.cs +++ b/VNH.Application/DTOs/Catalog/Users/UserUpdateDto.cs @@ -9,13 +9,13 @@ namespace VNH.Application.DTOs.Catalog.Users public class UserUpdateDto { [StringLength(100)] - public string Fullname { get; set; } = string.Empty; + public string? Fullname { get; set; } = string.Empty; [Column(TypeName = "datetime")] [DisplayFormat(DataFormatString = "{0:dd-MM-yyyy}", ApplyFormatInEditMode = true)] public DateTime? DateOfBirth { get; set; } public Gender Gender { get; set; } - public virtual string Email { get; set; } = string.Empty; - public virtual string PhoneNumber { get; set; } = string.Empty; - public virtual string Introduction { get; set; } = string.Empty; + public virtual string? Email { get; set; } = string.Empty; + public virtual string? PhoneNumber { get; set; } = string.Empty; + public virtual string? Introduction { get; set; } = string.Empty; } } diff --git a/VNH.Application/Interfaces/Catalog/Accounts/IAccountService.cs b/VNH.Application/Interfaces/Catalog/Accounts/IAccountService.cs index 18499d9..db5f365 100644 --- a/VNH.Application/Interfaces/Catalog/Accounts/IAccountService.cs +++ b/VNH.Application/Interfaces/Catalog/Accounts/IAccountService.cs @@ -13,14 +13,15 @@ namespace VNH.Application.Interfaces.Catalog.Accounts public interface IAccountService { Task> Authenticate(LoginRequest request); - Task> Register(RegisterRequest request); - Task> EmailConfirm(string numberConfirm, string email); + Task> Register(RegisterRequest request); + Task> EmailConfirm(string numberConfirm, string email); ClaimsPrincipal ValidateToken(string jwtToken); Task> ForgetPassword(string email); Task> ConfirmCode(string email); - Task> ResetPassword(ResetPassDto resetPass); + Task> ResetPassword(ResetPassDto resetPass); Task LockAccount(User user); - Task> ChangePassword(ChangePasswordDto changePasswodDto); + Task> ChangePassword(ChangePasswordDto changePasswodDto); Task> LoginExtend(string email, string name); + Task> ChangeEmail(string currentEmail ,string email); } } diff --git a/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs b/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs index 1e24b19..1875aec 100644 --- a/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs +++ b/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs @@ -9,7 +9,7 @@ public interface IPostService Task> Update(CreatePostDto requestDto, string name); Task> Detail(string Id); Task>> GetAll(); - Task> Delete(string id); + Task> Delete(string id); Task> AddOrUnLikePost(string id, string userId); Task> AddOrRemoveSavePost(string postId, string userId); diff --git a/VNH.Application/Interfaces/Common/IImageService.cs b/VNH.Application/Interfaces/Common/IImageService.cs index 47cb989..3414e8a 100644 --- a/VNH.Application/Interfaces/Common/IImageService.cs +++ b/VNH.Application/Interfaces/Common/IImageService.cs @@ -9,6 +9,7 @@ namespace VNH.Application.Interfaces.Common { public interface IImageService { + Task SaveFile(IFormFile file); Task ConvertFormFileToByteArray(IFormFile formFile); string ConvertByteArrayToString(byte[]? byteArray, Encoding encoding); byte[] CompressImage(byte[] originalImage, int KbNumber); diff --git a/VNH.Application/Interfaces/Common/IStorageService.cs b/VNH.Application/Interfaces/Common/IStorageService.cs new file mode 100644 index 0000000..ee311ef --- /dev/null +++ b/VNH.Application/Interfaces/Common/IStorageService.cs @@ -0,0 +1,10 @@ + +namespace VNH.Application.Interfaces.Common +{ + public interface IStorageService + { + string GetFileUrl(string fileName); + Task SaveFileAsync(Stream mediaBinaryStream, string fileName); + Task DeleteFileAsync(string fileName); + } +} diff --git a/VNH.Domain/Entities/Course.cs b/VNH.Domain/Entities/Course.cs index 1d1894d..16a5dfb 100644 --- a/VNH.Domain/Entities/Course.cs +++ b/VNH.Domain/Entities/Course.cs @@ -30,7 +30,7 @@ public Course() public DateTime? CreatedAt { get; set; } [Column(TypeName = "datetime")] public DateTime? UpdatedAt { get; set; } - + public string Image { get; set; } = string.Empty; [ForeignKey("UserId")] [InverseProperty("Courses")] public virtual User User { get; set; } diff --git a/VNH.Domain/Entities/Document.cs b/VNH.Domain/Entities/Document.cs index 44c0fcd..f8c4021 100644 --- a/VNH.Domain/Entities/Document.cs +++ b/VNH.Domain/Entities/Document.cs @@ -21,11 +21,11 @@ public Document() [Required] [StringLength(255)] public string Title { get; set; } - [StringLength(255)] + [StringLength(500)] public string Description { get; set; } [StringLength(255)] [Unicode(false)] - public string UrlImage { get; set; } + public string Image { get; set; } = string.Empty; [StringLength(255)] [Unicode(false)] public string FileName { get; set; } diff --git a/VNH.Domain/Entities/News.cs b/VNH.Domain/Entities/News.cs index 9c6c907..33bdae0 100644 --- a/VNH.Domain/Entities/News.cs +++ b/VNH.Domain/Entities/News.cs @@ -16,9 +16,9 @@ public partial class News [StringLength(255)] public string Title { get; set; } [Column(TypeName = "text")] - public string Description { get; set; } + public string Description { get; set; } = string.Empty; [Column(TypeName = "text")] - public string Image { get; set; } + public string Image { get; set; } = string.Empty; [Column(TypeName = "datetime")] public DateTime? PubDate { get; set; } [Required] diff --git a/VNH.Domain/Entities/Post.cs b/VNH.Domain/Entities/Post.cs index 0994ade..c68604e 100644 --- a/VNH.Domain/Entities/Post.cs +++ b/VNH.Domain/Entities/Post.cs @@ -33,7 +33,7 @@ public Post() [Column(TypeName = "datetime")] public DateTime? UpdatedAt { get; set; } public Guid? UserId { get; set; } - public byte[] Image { get; set; } + public string Image { get; set; } = string.Empty; public int ViewNumber { get; set; } [ForeignKey("TopicId")] diff --git a/VNH.Domain/Entities/User.cs b/VNH.Domain/Entities/User.cs index a34470b..f0a859c 100644 --- a/VNH.Domain/Entities/User.cs +++ b/VNH.Domain/Entities/User.cs @@ -47,7 +47,7 @@ public User() public DateTime? DateOfBirth { get; set; } public string Introduction { get; set; } public Gender Gender { get; set; } - public byte[] Image { get; set; } + public string Image { get; set; } = string.Empty; public string NumberConfirm { get; set; } // Confirm Email [InverseProperty("User")] public virtual ICollection AnswerVotes { get; set; } diff --git a/VNH.Infrastructure/DependencyInjectionInfrastructure.cs b/VNH.Infrastructure/DependencyInjectionInfrastructure.cs index 72d788c..aa356b5 100644 --- a/VNH.Infrastructure/DependencyInjectionInfrastructure.cs +++ b/VNH.Infrastructure/DependencyInjectionInfrastructure.cs @@ -108,6 +108,9 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); + //builder.AllowAnyOrigin() + // .AllowAnyHeader() + // .AllowAnyMethod(); }); }); services.AddOptions(); @@ -116,8 +119,9 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi services.Configure(mailsettings); services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/VNH.Infrastructure/Implement/Catalog/Account/AccountService.cs b/VNH.Infrastructure/Implement/Catalog/Account/AccountService.cs index a77340c..adcda7b 100644 --- a/VNH.Infrastructure/Implement/Catalog/Account/AccountService.cs +++ b/VNH.Infrastructure/Implement/Catalog/Account/AccountService.cs @@ -117,18 +117,18 @@ public async Task> ConfirmCode(string email) return new ApiSuccessResult(result); } - public async Task> EmailConfirm(string numberConfirm, string email) + public async Task> EmailConfirm(string numberConfirm, string email) { var user = await _userManager.FindByEmailAsync(email); - if (user is null) return new ApiErrorResult("Lỗi xác nhận email"); + if (user is null) return new ApiErrorResult("Lỗi xác nhận email"); if (user.NumberConfirm.Equals(numberConfirm)) { user.EmailConfirmed = true; _dataContext.User.Update(user); await _dataContext.SaveChangesAsync(); - return new ApiSuccessResult(); + return new ApiSuccessResult(); } - return new ApiErrorResult("Xác thực không thành công"); + return new ApiErrorResult("Xác thực không thành công"); } public async Task> ForgetPassword(string email) @@ -158,12 +158,12 @@ public async Task> ForgetPassword(string email) return new ApiSuccessResult(result); } - public async Task> Register(RegisterRequest request) + public async Task> Register(RegisterRequest request) { try { var user = await _userManager.FindByEmailAsync(request.Email); - if (user != null) return new ApiErrorResult("Email đã tồn tại"); + if (user != null) return new ApiErrorResult("Email đã tồn tại"); var confirmNumber = GetConfirmCode(); user = new User() { @@ -185,16 +185,16 @@ public async Task> Register(RegisterRequest request) await SendConfirmCodeToEmail(request.Email, confirmNumber); await _userManager.AddToRoleAsync(getUser, role); - return new ApiSuccessResult(); + return new ApiSuccessResult(); } } - return new ApiErrorResult("Đăng ký không thành công : Mật khẩu không hợp lệ, yêu cầu gồm có ít 6 ký tự bao gồm ký tự: Hoa, thường, số, ký tự đặc biệt "); + return new ApiErrorResult("Đăng ký không thành công : Mật khẩu không hợp lệ, yêu cầu gồm có ít 6 ký tự bao gồm ký tự: Hoa, thường, số, ký tự đặc biệt "); } catch (Exception ex) { _logger.LogError("Xảy ra lỗi trong quá trình đăng ký | ", ex.Message); - return new ApiErrorResult("Lỗi đăng ký!"); + return new ApiErrorResult("Lỗi đăng ký!"); } } @@ -310,15 +310,15 @@ public ClaimsPrincipal ValidateToken(string jwtToken) return principal; } - public async Task> ResetPassword(ResetPassDto resetPass) + public async Task> ResetPassword(ResetPassDto resetPass) { var user = await _userManager.FindByEmailAsync(resetPass.Email); - if (user is null) return new ApiErrorResult("Lỗi"); + if (user is null) return new ApiErrorResult("Lỗi"); var resetPasswordResult = await _userManager.ResetPasswordAsync(user, resetPass.Token, resetPass.Password); if (!resetPasswordResult.Succeeded) { _logger.LogError("Xảy ra lỗi trong quá trình xử lý | ", resetPasswordResult.Errors.Select(e => e.Description)); - return new ApiErrorResult("Lỗi!"); + return new ApiErrorResult("Lỗi!"); } if (user.AccessFailedCount is 5) { @@ -327,7 +327,7 @@ public async Task> ResetPassword(ResetPassDto resetPass) _dataContext.User.Update(user); await _dataContext.SaveChangesAsync(); } - return new ApiSuccessResult(); + return new ApiSuccessResult(); } public async Task LockAccount(User user) @@ -338,20 +338,20 @@ public async Task LockAccount(User user) await _dataContext.SaveChangesAsync(); } - public async Task> ChangePassword(ChangePasswordDto changePasswodDto) + public async Task> ChangePassword(ChangePasswordDto changePasswodDto) { var user = await _userManager.FindByEmailAsync(changePasswodDto.Email); var passwordCheckResult = await _userManager.CheckPasswordAsync(user, changePasswodDto.Password); if (!passwordCheckResult) { - return new ApiErrorResult("Mật khẩu hiện tại không đúng"); + return new ApiErrorResult("Mật khẩu hiện tại không đúng"); } var changePasswordResult = await _userManager.ChangePasswordAsync(user, changePasswodDto.Password, changePasswodDto.NewPassword); if (changePasswordResult.Succeeded) { - return new ApiSuccessResult(); + return new ApiSuccessResult(); } - return new ApiErrorResult("Đổi mật khẩu không thành công"); + return new ApiErrorResult("Đổi mật khẩu không thành công"); } public async Task> LoginExtend(string email, string name) @@ -367,5 +367,20 @@ public async Task> LoginExtend(string email, string name) await _signInManager.SignInAsync(user, isPersistent: false); return new ApiSuccessResult(await GetToken(user)); } + + public async Task> ChangeEmail(string currentEmail, string email) + { + var user = await _userManager.FindByEmailAsync(currentEmail); + var token = await _userManager.GenerateChangeEmailTokenAsync(user, email); + user.UserName = email; + user.NormalizedEmail = email; + user.NormalizedUserName = email; + var changeEmailResult = await _userManager.ChangeEmailAsync(user, email, token); + if (changeEmailResult.Succeeded) + { + return new ApiSuccessResult( await GetToken(user)); + } + return new ApiErrorResult("Đổi email không thành công"); + } } } diff --git a/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs b/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs index ad71381..9847ae9 100644 --- a/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs +++ b/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs @@ -2,13 +2,13 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Hosting; using System.Globalization; using System.Text; using VNH.Application.DTOs.Catalog.HashTags; using VNH.Application.DTOs.Catalog.Posts; using VNH.Application.DTOs.Catalog.Users; using VNH.Application.DTOs.Common.ResponseNotification; -using VNH.Application.Interfaces.Catalog.HashTags; using VNH.Application.Interfaces.Common; using VNH.Application.Interfaces.Posts; using VNH.Domain; @@ -22,21 +22,23 @@ public class PostService : IPostService private readonly UserManager _userManager; private readonly VietNamHistoryContext _dataContext; private readonly IImageService _image; - + private readonly IStorageService _storageService; private readonly IMapper _mapper; public PostService(UserManager userManager, IMapper mapper, IImageService image, - VietNamHistoryContext vietNamHistoryContext) { + VietNamHistoryContext vietNamHistoryContext, IStorageService storageService) + { _userManager = userManager; _mapper = mapper; _image = image; _dataContext = vietNamHistoryContext; + _storageService = storageService; } public async Task> Create(CreatePostDto requestDto, string name) { var user = await _userManager.FindByEmailAsync(name); var post = _mapper.Map(requestDto); - post.Image = await _image.ConvertFormFileToByteArray(requestDto.Image); + post.Image = await _image.SaveFile(requestDto.Image); post.CreatedAt = DateTime.Now; post.UserId = user.Id; post.TopicId = requestDto.TopicId; @@ -66,12 +68,12 @@ public async Task> Create(CreatePostDto requestDto, var postReponse = _mapper.Map(post); - postReponse.Image = _image.ConvertByteArrayToString(post.Image, Encoding.UTF8); + postReponse.Image = post.Image; var useDto = new UserShortDto() { FullName = user.Fullname, Id = user.Id, - Image = _image.ConvertByteArrayToString(user.Image, Encoding.UTF8) + Image = user.Image }; postReponse.UserShort = useDto; var listPostTag = await _dataContext.PostTags.Where(x => x.PostId.Equals(postReponse.Id)).Select(x => x.TagId).ToListAsync(); @@ -124,8 +126,11 @@ public async Task> Update(CreatePostDto requestDto, { 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)"); } - - updatePost.Image = await _image.ConvertFormFileToByteArray(requestDto.Image); + if (updatePost.Image != string.Empty) + { + await _storageService.DeleteFileAsync(updatePost.Image); + } + updatePost.Image = await _image.SaveFile(requestDto.Image); updatePost.UpdatedAt = DateTime.Now; updatePost.TopicId = requestDto.TopicId; updatePost.Content = requestDto.Content; @@ -158,12 +163,12 @@ public async Task> Update(CreatePostDto requestDto, var postReponse = _mapper.Map(updatePost); - postReponse.Image = _image.ConvertByteArrayToString(updatePost.Image, Encoding.UTF8); + postReponse.Image = updatePost.Image; var useDto = new UserShortDto() { FullName = user.Fullname, Id = user.Id, - Image = _image.ConvertByteArrayToString(user.Image, Encoding.UTF8) + Image = user.Image }; postReponse.UserShort = useDto; var listPostTag = await _dataContext.PostTags.Where(x => x.PostId.Equals(postReponse.Id)).Select(x => x.TagId).ToListAsync(); @@ -200,7 +205,7 @@ public async Task> Detail(string Id) } var user = await _userManager.FindByIdAsync(post.UserId.ToString()); var postResponse = _mapper.Map(post); - postResponse.Image = _image.ConvertByteArrayToString(post.Image, Encoding.UTF8); + postResponse.Image = post.Image; var listPostTag = await _dataContext.PostTags.Where(x => x.PostId.Equals(postResponse.Id)).Select(x => x.TagId).ToListAsync(); var tags = await _dataContext.Tags @@ -218,7 +223,7 @@ public async Task> Detail(string Id) { FullName = user.Fullname, Id = user.Id, - Image = _image.ConvertByteArrayToString(user.Image, Encoding.UTF8) + Image = user.Image }; var topic = await _dataContext.Topics.FirstAsync(x => x.Id == post.TopicId); @@ -234,17 +239,19 @@ public async Task> Detail(string Id) 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(); foreach (var item in posts) { var post = _mapper.Map(item); - var userShort = await _dataContext.User.Where(x => x.Id == item.UserId).FirstOrDefaultAsync(); + var userShort = users.First(x => x.Id == item.UserId); if (userShort is not null) { post.UserShort.FullName = userShort.Fullname; post.UserShort.Id = userShort.Id; - post.UserShort.Image = _image.ConvertByteArrayToString(userShort.Image, Encoding.UTF8); + post.UserShort.Image = userShort.Image; } var tags = await _dataContext.PostTags .Where(x => x.PostId == item.Id) @@ -258,26 +265,30 @@ public async Task>> GetAll() { post.Tags.Add(_mapper.Map(tag)); } - - post.Image = _image.ConvertByteArrayToString(item.Image, Encoding.UTF8); + post.TopicName = topics.Where(x => x.Id == item.TopicId).Select(x=>x.Title).First(); + post.Image = item.Image; result.Add(post); } return new ApiSuccessResult>(result); } - public async Task> Delete(string id) + public async Task> Delete(string id) { var post = await _dataContext.Posts.FirstOrDefaultAsync(x => x.Id.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"); + } + if (post.Image != string.Empty) + { + await _storageService.DeleteFileAsync(post.Image); } _dataContext.Posts.Remove(post); await _dataContext.SaveChangesAsync(); - return new ApiSuccessResult(true); + return new ApiSuccessResult("Đã xóa bài viết"); } public async Task> AddOrUnLikePost(string id, string userId) diff --git a/VNH.Infrastructure/Implement/Catalog/Users/UserService.cs b/VNH.Infrastructure/Implement/Catalog/Users/UserService.cs index ac55281..6f731fc 100644 --- a/VNH.Infrastructure/Implement/Catalog/Users/UserService.cs +++ b/VNH.Infrastructure/Implement/Catalog/Users/UserService.cs @@ -11,6 +11,7 @@ using AutoMapper; using VNH.Application.Interfaces.Common; using Microsoft.AspNetCore.Http; +using VNH.Infrastructure.Implement.Common; namespace VNH.Infrastructure.Implement.Catalog.Users { @@ -22,7 +23,7 @@ public class UserService : IUserService public readonly ILogger _logger; private readonly UserManager _userManager; private readonly VietNamHistoryContext _dataContext; - + private readonly IStorageService _storageService; public UserService(VietNamHistoryContext context, ILogger logger, @@ -30,7 +31,8 @@ public UserService(VietNamHistoryContext context, SignInManager signInManager, IConfiguration configuration, ISendMailService sendmailservice, - IMapper mapper, IImageService image) + IMapper mapper, IImageService image, + IStorageService storageService) { _logger = logger; _mapper = mapper; @@ -38,6 +40,7 @@ public UserService(VietNamHistoryContext context, _userManager = userManager; _sendmailservice = sendmailservice; _dataContext = context; + _storageService = storageService; } public async Task> GetUserDetail(string email) { @@ -68,13 +71,17 @@ public async Task> Update(UserUpdateDto request) public async Task> GetImage(string email) { var user = await _userManager.FindByNameAsync(email); - return new ApiSuccessResult(_image.ConvertByteArrayToString(user.Image, Encoding.UTF8)); + return new ApiSuccessResult(user.Image); } public async Task> SetImageUser(string name, IFormFile image) { var user = await _userManager.FindByNameAsync(name); - user.Image = await _image.ConvertFormFileToByteArray(image); + if (user.Image != string.Empty) + { + await _storageService.DeleteFileAsync(user.Image); + } + user.Image = await _image.SaveFile(image); _dataContext.User.Update(user); await _dataContext.SaveChangesAsync(); return new ApiSuccessResult("Cập nhập ảnh đại diện thành công"); diff --git a/VNH.Infrastructure/Implement/Common/ImageService.cs b/VNH.Infrastructure/Implement/Common/ImageService.cs index a169465..e79e2e1 100644 --- a/VNH.Infrastructure/Implement/Common/ImageService.cs +++ b/VNH.Infrastructure/Implement/Common/ImageService.cs @@ -1,13 +1,30 @@ using ImageMagick; +using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using System.Drawing.Imaging; +using System.Net.Http.Headers; using System.Text; +using VNH.Application.Common.Contants; using VNH.Application.Interfaces.Common; namespace VNH.Infrastructure.Implement.Common { public class ImageService : IImageService { + private const string USER_CONTENT_FOLDER_NAME = "Images"; + private readonly string URL = SystemConstants.UrlWeb; + private readonly IStorageService _storageService; + public ImageService(IStorageService storageService) + { + _storageService = storageService; + } + public async Task SaveFile(IFormFile file) + { + var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName?.Trim('"'); + var fileName = $"{Guid.NewGuid()}{Path.GetExtension(originalFileName)}"; + await _storageService.SaveFileAsync(file.OpenReadStream(), fileName); + return URL + USER_CONTENT_FOLDER_NAME + "/" + fileName; + } public string ConvertByteArrayToString(byte[]? byteArray, Encoding encoding) { return byteArray is not null ? Convert.ToBase64String(byteArray) : string.Empty; diff --git a/VNH.Infrastructure/Implement/Common/StorageService.cs b/VNH.Infrastructure/Implement/Common/StorageService.cs new file mode 100644 index 0000000..9214745 --- /dev/null +++ b/VNH.Infrastructure/Implement/Common/StorageService.cs @@ -0,0 +1,43 @@ +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 +{ + public class StorageService : IStorageService + { + private readonly string _userContentFolder; + private const string USER_CONTENT_FOLDER_NAME = "Images"; + + public StorageService(IWebHostEnvironment webHostEnvironment) + { + _userContentFolder = Path.Combine(webHostEnvironment.WebRootPath, USER_CONTENT_FOLDER_NAME); + } + + public string GetFileUrl(string fileName) + { + return $"/{USER_CONTENT_FOLDER_NAME}/{fileName}"; + } + + public async Task SaveFileAsync(Stream mediaBinaryStream, string fileName) + { + var filePath = Path.Combine(_userContentFolder, fileName); + using var output = new FileStream(filePath, FileMode.Create); + await mediaBinaryStream.CopyToAsync(output); + } + + public async Task DeleteFileAsync(string fileName) + { + string name = Path.GetFileName(new Uri(fileName).LocalPath); + var filePath = Path.Combine(_userContentFolder, name); + if (File.Exists(filePath)) + { + await Task.Run(() => File.Delete(filePath)); + } + } + } +} diff --git a/VNH.Infrastructure/Migrations/20231109154951_Update_Image_Attribute.Designer.cs b/VNH.Infrastructure/Migrations/20231109154951_Update_Image_Attribute.Designer.cs new file mode 100644 index 0000000..e20a279 --- /dev/null +++ b/VNH.Infrastructure/Migrations/20231109154951_Update_Image_Attribute.Designer.cs @@ -0,0 +1,1869 @@ +// +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("20231109154951_Update_Image_Attribute")] + partial class Update_Image_Attribute + { + /// + 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("Title") + .IsRequired() + .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, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5927), + 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), + 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), + 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), + 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), + 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), + 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), + 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 = "157e4a93-81f2-48c6-a1a9-511f70d19c99", + Name = "admin", + NormalizedName = "admin" + }, + new + { + Id = new Guid("cfafcfcd-d796-43f4-8ac0-ead43bd2f18a"), + ConcurrencyStamp = "55fcc52e-27d5-4665-8967-13fe97e02ebe", + Name = "teacher", + NormalizedName = "teacher" + }, + new + { + Id = new Guid("5d4e4081-91f8-4fc0-b8eb-9860b7849604"), + ConcurrencyStamp = "a0e89f69-ee8c-4a09-be4d-4a9857fbc8d3", + 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 = "16823ad9-fa17-4b28-a964-b367dc4ff5e4", + 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 = "AQAAAAEAACcQAAAAEKBatixPeSdVUG7X4YQBbyiJZRsH7gYPsSCSoDGJUBmJtWNmm9381o9NNa6J4kJndQ==", + 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") + .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/20231109154951_Update_Image_Attribute.cs b/VNH.Infrastructure/Migrations/20231109154951_Update_Image_Attribute.cs new file mode 100644 index 0000000..1986a3c --- /dev/null +++ b/VNH.Infrastructure/Migrations/20231109154951_Update_Image_Attribute.cs @@ -0,0 +1,201 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace VNH.Infrastructure.Migrations +{ + /// + public partial class Update_Image_Attribute : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "UrlImage", + table: "Document", + newName: "Image"); + + migrationBuilder.AlterColumn( + name: "Image", + table: "User", + type: "varchar(max)", + maxLength: 3145728, + nullable: true, + oldClrType: typeof(byte[]), + oldType: "varbinary(max)", + oldMaxLength: 3145728, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Image", + table: "Post", + type: "varchar(max)", + nullable: true, + oldClrType: typeof(byte[]), + oldType: "varbinary(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Document", + type: "nvarchar(500)", + maxLength: 500, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(255)", + oldMaxLength: 255, + oldNullable: true); + + migrationBuilder.AddColumn( + name: "Image", + table: "Course", + type: "varchar(max)", + nullable: true); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("25752490-4ba5-4abb-ac3b-192205cd1b6e"), + column: "CreatedAt", + value: new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5947)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("3043c693-b3c9-453e-9876-31c943222576"), + column: "CreatedAt", + value: new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5961)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("349ed807-6107-436f-9a4c-9d6183fbc444"), + column: "CreatedAt", + value: new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5953)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("4a780087-9058-41c9-b84b-944d1a502010"), + column: "CreatedAt", + value: new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5959)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("bab1da58-6921-44b9-837f-c58d3998497b"), + column: "CreatedAt", + value: new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5949)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("c4ddb872-06c5-4779-a8a3-a55e5b2c5347"), + column: "CreatedAt", + value: new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5956)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("d30e1353-0163-43c1-b757-7957981b0eda"), + column: "CreatedAt", + value: new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5927)); + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Image", + table: "Course"); + + migrationBuilder.RenameColumn( + name: "Image", + table: "Document", + newName: "UrlImage"); + + migrationBuilder.AlterColumn( + name: "Image", + table: "User", + type: "varbinary(max)", + maxLength: 3145728, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldMaxLength: 3145728, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Image", + table: "Post", + type: "varbinary(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Document", + type: "nvarchar(255)", + maxLength: 255, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(500)", + oldMaxLength: 500, + oldNullable: true); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("25752490-4ba5-4abb-ac3b-192205cd1b6e"), + column: "CreatedAt", + value: new DateTime(2023, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6217)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("3043c693-b3c9-453e-9876-31c943222576"), + column: "CreatedAt", + value: new DateTime(2023, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6229)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("349ed807-6107-436f-9a4c-9d6183fbc444"), + column: "CreatedAt", + value: new DateTime(2023, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6223)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("4a780087-9058-41c9-b84b-944d1a502010"), + column: "CreatedAt", + value: new DateTime(2023, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6227)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("bab1da58-6921-44b9-837f-c58d3998497b"), + column: "CreatedAt", + value: new DateTime(2023, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6220)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("c4ddb872-06c5-4779-a8a3-a55e5b2c5347"), + column: "CreatedAt", + value: new DateTime(2023, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6226)); + + migrationBuilder.UpdateData( + table: "Report", + keyColumn: "Id", + keyValue: new Guid("d30e1353-0163-43c1-b757-7957981b0eda"), + column: "CreatedAt", + value: new DateTime(2023, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6204)); + + } + } +} diff --git a/VNH.Infrastructure/Migrations/VietNamHistoryContextModelSnapshot.cs b/VNH.Infrastructure/Migrations/VietNamHistoryContextModelSnapshot.cs index d918508..bf7da57 100644 --- a/VNH.Infrastructure/Migrations/VietNamHistoryContextModelSnapshot.cs +++ b/VNH.Infrastructure/Migrations/VietNamHistoryContextModelSnapshot.cs @@ -195,6 +195,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Description") .HasColumnType("nvarchar(max)"); + b.Property("Image") + .HasColumnType("nvarchar(max)"); + b.Property("UpdatedAt") .HasColumnType("datetime"); @@ -328,14 +331,19 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("datetime"); b.Property("Description") - .HasMaxLength(255) - .HasColumnType("nvarchar(255)"); + .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) @@ -344,11 +352,6 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("UpdatedAt") .HasColumnType("datetime"); - b.Property("UrlImage") - .HasMaxLength(255) - .IsUnicode(false) - .HasColumnType("varchar(255)"); - b.Property("UserId") .HasColumnType("uniqueidentifier"); @@ -583,8 +586,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("CreatedAt") .HasColumnType("datetime"); - b.Property("Image") - .HasColumnType("varbinary(max)"); + b.Property("Image") + .HasColumnType("nvarchar(max)"); b.Property("Title") .IsRequired() @@ -928,49 +931,49 @@ protected override void BuildModel(ModelBuilder modelBuilder) new { Id = new Guid("d30e1353-0163-43c1-b757-7957981b0eda"), - CreatedAt = new DateTime(2023, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6204), + CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5927), 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, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6217), + CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5947), 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, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6220), + CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5949), 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, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6223), + CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5953), 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, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6226), + CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5956), 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, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6227), + CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5959), 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, 10, 30, 22, 57, 18, 543, DateTimeKind.Local).AddTicks(6229), + CreatedAt = new DateTime(2023, 11, 9, 22, 49, 50, 982, DateTimeKind.Local).AddTicks(5961), 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" }); @@ -999,21 +1002,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) new { Id = new Guid("a18be9c0-aa65-4af8-bd17-00bd9344e575"), - ConcurrencyStamp = "53d56036-6dad-4af5-bc07-50c37802f581", + ConcurrencyStamp = "157e4a93-81f2-48c6-a1a9-511f70d19c99", Name = "admin", NormalizedName = "admin" }, new { Id = new Guid("cfafcfcd-d796-43f4-8ac0-ead43bd2f18a"), - ConcurrencyStamp = "8415b1f8-a403-4e5c-8f51-6b26c9d5e831", + ConcurrencyStamp = "55fcc52e-27d5-4665-8967-13fe97e02ebe", Name = "teacher", NormalizedName = "teacher" }, new { Id = new Guid("5d4e4081-91f8-4fc0-b8eb-9860b7849604"), - ConcurrencyStamp = "072f5603-571d-4abd-aac3-9f1a63bebbf5", + ConcurrencyStamp = "a0e89f69-ee8c-4a09-be4d-4a9857fbc8d3", Name = "student", NormalizedName = "student" }); @@ -1150,9 +1153,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Gender") .HasColumnType("int"); - b.Property("Image") + b.Property("Image") .HasMaxLength(3145728) - .HasColumnType("varbinary(max)"); + .HasColumnType("nvarchar(max)"); b.Property("Introduction") .HasColumnType("nvarchar(max)"); @@ -1199,16 +1202,17 @@ protected override void BuildModel(ModelBuilder modelBuilder) { Id = new Guid("d1f771da-b318-42f8-a003-5a15614216f5"), AccessFailedCount = 0, - ConcurrencyStamp = "a724fd15-f4c5-41b9-b5ea-cc6830547381", + ConcurrencyStamp = "16823ad9-fa17-4b28-a964-b367dc4ff5e4", 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 = "AQAAAAEAACcQAAAAEMNM6h+03V7gLq621F97RFvghVMLEWUnOTU/6iUH5VpKYhA06DtBrRLe1zh5RQeIbA==", + PasswordHash = "AQAAAAEAACcQAAAAEKBatixPeSdVUG7X4YQBbyiJZRsH7gYPsSCSoDGJUBmJtWNmm9381o9NNa6J4kJndQ==", PhoneNumberConfirmed = false, SecurityStamp = "", TwoFactorEnabled = false, diff --git a/VNH.Infrastructure/Presenters/DbContext/VietNamHistoryContext.cs b/VNH.Infrastructure/Presenters/DbContext/VietNamHistoryContext.cs index c818b2d..13414bb 100644 --- a/VNH.Infrastructure/Presenters/DbContext/VietNamHistoryContext.cs +++ b/VNH.Infrastructure/Presenters/DbContext/VietNamHistoryContext.cs @@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using System; +using VNH.Application.Common.Contants; using VNH.Domain; using VNH.Domain.Entities; using VNH.Infrastructure.Presenters.DbContext; @@ -63,7 +64,7 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { - optionsBuilder.UseSqlServer("Data Source=.;Initial Catalog=VietNamHistory_2;Integrated Security=True;Encrypt=true;TrustServerCertificate=true;"); + optionsBuilder.UseSqlServer(SystemConstants.ConnectString); } } diff --git a/VNH.WebAPi/.config/dotnet-tools.json b/VNH.WebAPi/.config/dotnet-tools.json new file mode 100644 index 0000000..dbe7898 --- /dev/null +++ b/VNH.WebAPi/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "7.0.13", + "commands": [ + "dotnet-ef" + ] + } + } +} \ No newline at end of file diff --git a/VNH.WebAPi/Controllers/AccountController.cs b/VNH.WebAPi/Controllers/AccountController.cs index 814d176..33cb6f5 100644 --- a/VNH.WebAPi/Controllers/AccountController.cs +++ b/VNH.WebAPi/Controllers/AccountController.cs @@ -41,7 +41,7 @@ public async Task Login([FromBody] LoginRequest request) var userPrincipal = _account.ValidateToken(result.ResultObj); var authProperties = new AuthenticationProperties { - ExpiresUtc = DateTimeOffset.UtcNow.AddHours(12), + ExpiresUtc = DateTimeOffset.UtcNow.AddDays(15), IsPersistent = true }; @@ -53,7 +53,7 @@ await HttpContext.SignInAsync( var cacheOptions = new DistributedCacheEntryOptions() { - AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1) + AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(12) }; await _cache.SetStringAsync("my_token_key", SystemConstants.Token, cacheOptions); return Ok(result); @@ -251,11 +251,7 @@ public async Task Logout() public async Task RegisterUser([FromBody] RegisterRequest request) { var result = await _account.Register(request); - if (!result.IsSuccessed) - { - return BadRequest(result); - } - return Ok(result); + return result.IsSuccessed ? Ok(result) : BadRequest(result); } [HttpPost("EmailConfirm")] @@ -263,22 +259,14 @@ public async Task RegisterUser([FromBody] RegisterRequest request public async Task EmailConfirm(string numberConfirm) { var result = await _account.EmailConfirm(numberConfirm, User.Identity.Name); - if (!result.IsSuccessed) - { - return BadRequest(result); - } - return Ok(result); + return result.IsSuccessed ? Ok(result) : BadRequest(result); } [HttpGet("ForgetPassword")] public async Task ForgetPassword([FromQuery] string email) { var result = await _account.ForgetPassword(email); - if (!result.IsSuccessed) - { - return BadRequest(result); - } - return Ok(result); + return result.IsSuccessed ? Ok(result) : BadRequest(result); } [HttpGet("ForgetPassword/ConfirmCode")] @@ -286,35 +274,32 @@ public async Task ForgetPassword([FromQuery] string email) public async Task ConfirmCode([FromQuery] string email) { var result = await _account.ConfirmCode(email); - if (!result.IsSuccessed) - { - return BadRequest(result); - } - return Ok(result); + return result.IsSuccessed ? Ok(result) : BadRequest(result); } [HttpPost("ResetPassword")] public async Task ResetPassword(ResetPassDto resetPass) { var result = await _account.ResetPassword(resetPass); - if (!result.IsSuccessed) - { - return BadRequest(result); - } - return Ok(result); + return result.IsSuccessed ? Ok(result) : BadRequest(result); } + [HttpPost("ChangeEmail")] + [Authorize] + public async Task ChangeEmail(string email) + { + //// var token = Request.Headers["Authorization"].ToString().Replace("Bearer ", ""); + var result = await _account.ChangeEmail(User.Identity.Name, email); + return result.IsSuccessed ? Ok(result) : BadRequest(result); + } + [HttpPost("ChangePassword")] [Authorize] public async Task ChanggPassword(ChangePasswordDto changePasswodDto) { var result = await _account.ChangePassword(changePasswodDto); - if (!result.IsSuccessed) - { - return BadRequest(result); - } - return Ok(result); + return result.IsSuccessed ? Ok(result) : BadRequest(result); } diff --git a/VNH.WebAPi/Program.cs b/VNH.WebAPi/Program.cs index eef16f0..fa9c2e6 100644 --- a/VNH.WebAPi/Program.cs +++ b/VNH.WebAPi/Program.cs @@ -33,6 +33,7 @@ public static void Main(string[] args) builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); + #region SwaggerGen Configuration builder.Services.AddSwaggerGen(c => { @@ -115,18 +116,21 @@ public static void Main(string[] args) app.Use(async (context, next) => { - // Connection: RemoteIp app.Logger.LogInformation("Request RemoteIp: {RemoteIpAddress}", context.Connection.RemoteIpAddress); await next(context); }); - app.UseCors("AllowAngularDev"); + + app.UseStaticFiles(); app.UseForwardedHeaders(); - app.UseAuthentication(); + app.UseSession(); app.UseHttpsRedirection(); + app.UseRouting(); + app.UseCors("AllowAngularDev"); + app.UseAuthentication(); app.UseAuthorization(); app.MapControllers(); app.UseHttpsRedirection(); diff --git a/VNH.WebAPi/VNH.WebAPi.csproj b/VNH.WebAPi/VNH.WebAPi.csproj index feee712..cc3c28a 100644 --- a/VNH.WebAPi/VNH.WebAPi.csproj +++ b/VNH.WebAPi/VNH.WebAPi.csproj @@ -10,6 +10,15 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -22,5 +31,9 @@ - + + + + false + diff --git a/VNH.WebAPi/appsettings.json b/VNH.WebAPi/appsettings.json index 751268b..a59ca2c 100644 --- a/VNH.WebAPi/appsettings.json +++ b/VNH.WebAPi/appsettings.json @@ -11,7 +11,7 @@ "Issuer": "https://webapi.tedu.com.vn" }, "ConnectionStrings": { - "DataConnect": "Data Source=.;Initial Catalog=VietNamHistory_2;Integrated Security=True;Encrypt=true;TrustServerCertificate=true;" + "DataConnect": "Data Source=SQL5110.site4now.net;Initial Catalog=db_aa121e_vuanhpham25;User Id=db_aa121e_vuanhpham25_admin;Password=30102002Mai" }, "MailSettings": { "Mail": "xuannhat1932002@gmail.com", diff --git a/VNH.WebAPi/wwwroot/Images/facebook.png b/VNH.WebAPi/wwwroot/Images/facebook.png new file mode 100644 index 0000000000000000000000000000000000000000..eed9658dc5dbfe767143294190cb067f827f99f5 GIT binary patch literal 1891 zcmV-p2b}ncP)Dv@}L@Swh^3BkljC4d1XG4TSCmNhYP zH8E@p;w>7*AoRgY6hlyXQ3DYaLbyGULM=s2QFfP7mc7s$yXW(v-O|f;cV_p@(CY80 zJM*3I{Lj~!IkV^dmtZoU^|4A4SO}m7BxeI+CcskwxB(Oogv9||1}IF7-frjHFfG$O2}nCB`El)a20*gV7AakHqrJK%@JpN}Yhh0+jkXU4`BDH2_ut zn4>E12u=amp5We3E;d%gR3yy108`gRN)v^68K4&dOi`do4`C3$UkHA$-R}s#I^Zpvjzfv5eOGQgROKmdu$eJd|cSs725^EqiW<4WK|rv)-q+b)DINCV89AZX!%_e#r0s zW8?|j=vXEj$C}uJ!9QAKJMqafXQfTxL4!?;oOVhWh%X_C9RM!^h=-mSbs2f;W2>xq z$$4wBa5m~70DYCsZ^uS;NN`0L!Fuh>5f{&Iu z{vyI;v-=qve!0B9LrZ-cEWp5GhN<7@t4ip?yr~8EnAwL8O6^qiTI&}>jN1x_mye;=xwJXJ-mfIss^8SmxOGhUCY*nuX& zz!e3FEaiLzmlUOn3+i`gOejtTl390rbisT@02ES^%tDU0CyJCLA_@qwY*UiVLXNd3 z%T(kcP@7PtRmdSK}D&U z1RWFuKD<^%NlmA%BdKcEY6))CI{G&z7`s8J%O_hf%H?Z5@6LETZC&P^uP0ZgJSWe~ zTa9W<2LZc*)Xt3HZ@`pS0eY^onU8Xa1RIJ!Ch*VJ z$+C=n0e|tQBM+u=S`jA*&tn3v6J#LHB%dAW4+6&U33m8P+K8|Mz^Dcj5C&*0IBwfKgTnZmN$O}En3GN<+gfxb{C&SaSA^D>9_q#nDxF28NFkNN`6;^hD~ z=dI3c7@I==;^oag>eCah-*D_B8EkOX5#b32F6S)JJfaM$4K}*!(@l3{VfZ&g0l#aP zBwhf*0i$hAWWSVheyBk+{J_r1s@mZ%X#;qXr#`ld2n_&~EK}z|Cll&Jer>yv|N2l2 zUjf%34mG;AC7nIfK=1;{>j#VmiGk7J=uJ)!`CXsoI(R^#H)z`0u)DiRtR&DH0CUsD zWZU#iQSBXbS)!SlxAsx8Dcn#R$xZ2SOfg4!>Ld3GqQ%U39CXcqnPUM?65$6)ygRh9 zf%*G$OQzxJK%TC0dO;bo6zqVOZ_M#3ZNT6JAiZ5-sowTbVNcN?buYT dY9Ami{{k!JOz^ae@H_wj002ovPDHLkV1hqkY&!q| literal 0 HcmV?d00001