diff --git a/README.md b/README.md
index 28afc38..2e0492f 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,5 @@
# VietNamHistory
The project is in the development stage
+## You can get all my materials for this project here : https://drive.google.com/drive/folders/1EUq5xxeMOWacea59xSQnLhdyWzs5yzZZ?usp=sharing
+
+## Description project at youtube: https://www.youtube.com/watch?v=NqTf46UVhHc
diff --git a/VNH.Application/Common/Contants/ConstantNofication.cs b/VNH.Application/Common/Contants/ConstantNofication.cs
new file mode 100644
index 0000000..7d3e573
--- /dev/null
+++ b/VNH.Application/Common/Contants/ConstantNofication.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace VNH.Application.Common.Contants
+{
+ public static class ConstantNofication
+ {
+ // Post
+ public static string CommentPost(string name)
+ {
+ return "[ "+name+" ]" + " đã bình luận một bài viết của bạn";
+ }
+ public static string LikePost(string name)
+ {
+ return "[ " + name + " ]" + " đã thích một bài viết của bạn";
+ }
+
+ // Forum
+ public static string CommentAnswer(string name)
+ {
+ return "[ " + name + " ]" + " đã bình luận trong câu hỏi của bạn";
+ }
+ public static string AnswerTheQuestion(string name)
+ {
+ return "[ " + name + " ]" + " đã 'trả lời' một câu hỏi của bạn";
+ }
+ public static string LikeQuestion(string name)
+ {
+ return "[ " + name + " ]" + " đã tán thành một câu hỏi của bạn";
+ }
+ public static string LikeAnswer(string name)
+ {
+ return "[ " + name + " ]" + " đã 'tán thành' một câu trả lời của bạn";
+ }
+ }
+}
diff --git a/VNH.Application/Common/Contants/ConstantUrl.cs b/VNH.Application/Common/Contants/ConstantUrl.cs
new file mode 100644
index 0000000..6be1838
--- /dev/null
+++ b/VNH.Application/Common/Contants/ConstantUrl.cs
@@ -0,0 +1,9 @@
+
+namespace VNH.Application.Common.Contants
+{
+ public static class ConstantUrl
+ {
+ public const string UrlPostDetail = "/discover/";
+ public const string UrlQuestionDetail = "/forum/";
+ }
+}
diff --git a/VNH.Application/Common/Contants/SystemConstants.cs b/VNH.Application/Common/Contants/SystemConstants.cs
index 0daafcf..b965aad 100644
--- a/VNH.Application/Common/Contants/SystemConstants.cs
+++ b/VNH.Application/Common/Contants/SystemConstants.cs
@@ -5,10 +5,13 @@ public static class SystemConstants
public const string Token = "Token";
public const string BaseAddress = "BaseAddress";
+ public const string UrlWeb = "https://tyls.fun/";
+ public const string ConnectString = "Data Source=202.92.7.204\\MSSQLSERVER2022, 1438;Initial Catalog=tyls;User Id=toiyeulichsu;Password=MheZDu9$oGbrYlL#S%ApJ^qf;TrustServerCertificate=true; ";
+
//public const string UrlWeb = "https://vuanhpham25-001-site1.gtempurl.com/";
- //public const string ConnectString = "Data Source=SQL5106.site4now.net;Initial Catalog=db_aa121e_vuanhpham25;User Id=db_aa121e_vuanhpham25_admin;Password=30102002Mai";
+ //public const string ConnectString = "Data Source=SQL5112.site4now.net;Initial Catalog=db_aa121e_vuanhpham25;User Id=db_aa121e_vuanhpham25_admin;Password=30102002Mai";
- public const string UrlWeb = "https://localhost:7138/";
- public const string ConnectString = "Data Source=.;Initial Catalog=VietNamHistory;Integrated Security=True;Encrypt=true;TrustServerCertificate=true;";
+ //public const string UrlWeb = "https://localhost:7138/";
+ //public const string ConnectString = "Data Source=.;Initial Catalog=tyls;Integrated Security=True;Encrypt=true;TrustServerCertificate=true;";
}
}
diff --git a/VNH.Application/DTOs/Catalog/ExamHistoryDto/CreateExamHistoryDto.cs b/VNH.Application/DTOs/Catalog/ExamHistoryDto/CreateExamHistoryDto.cs
index f400307..95b986f 100644
--- a/VNH.Application/DTOs/Catalog/ExamHistoryDto/CreateExamHistoryDto.cs
+++ b/VNH.Application/DTOs/Catalog/ExamHistoryDto/CreateExamHistoryDto.cs
@@ -13,7 +13,7 @@ public class CreateExamHistoryDto
public Guid MultipleChoiceId { get; set; }
public Guid UserId { get; set; }
- public int Scores { get; set; }
+ public float Scores { get; set; }
public int CompletionTime { get; set; }
diff --git a/VNH.Application/DTOs/Catalog/ExamHistoryDto/ExamHistoryResponseDto.cs b/VNH.Application/DTOs/Catalog/ExamHistoryDto/ExamHistoryResponseDto.cs
index 2e0394f..04e1455 100644
--- a/VNH.Application/DTOs/Catalog/ExamHistoryDto/ExamHistoryResponseDto.cs
+++ b/VNH.Application/DTOs/Catalog/ExamHistoryDto/ExamHistoryResponseDto.cs
@@ -15,7 +15,9 @@ public class ExamHistoryResponseDto
public UserShortDto? UserShortDto { get; set; } = new UserShortDto();
- public int Scores { get; set; }
+ public int numberQuiz { get; set; } = 0;
+
+ public float Scores { get; set; }
public int CompletionTime { get; set; }
diff --git a/VNH.Application/DTOs/Catalog/MultipleChoiceDto/CreateQuizDto.cs b/VNH.Application/DTOs/Catalog/MultipleChoiceDto/CreateQuizDto.cs
index 581558d..f52f648 100644
--- a/VNH.Application/DTOs/Catalog/MultipleChoiceDto/CreateQuizDto.cs
+++ b/VNH.Application/DTOs/Catalog/MultipleChoiceDto/CreateQuizDto.cs
@@ -10,7 +10,7 @@ namespace VNH.Application.DTOs.Catalog.MultipleChoiceDto
public class CreateQuizDto
{
public string? Id { get; set; } = Guid.NewGuid().ToString();
-
+
public string Title { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
diff --git a/VNH.Application/DTOs/Catalog/MultipleChoiceDto/MultipleChoiceResponseDto.cs b/VNH.Application/DTOs/Catalog/MultipleChoiceDto/MultipleChoiceResponseDto.cs
index 8f0d1a4..9ca7dbd 100644
--- a/VNH.Application/DTOs/Catalog/MultipleChoiceDto/MultipleChoiceResponseDto.cs
+++ b/VNH.Application/DTOs/Catalog/MultipleChoiceDto/MultipleChoiceResponseDto.cs
@@ -20,6 +20,9 @@ public class MultipleChoiceResponseDto
public DateTime? UpdatedAt { get; set; }
public int WorkTime { get; set; }
+ public int NumberQuiz { get; set; } = 0;
+
+
public UserShortDto? UserShort { get; set; } = new UserShortDto();
public List Quizs { get; set; } = new List();
diff --git a/VNH.Application/DTOs/Catalog/Notifications/NotificationDto.cs b/VNH.Application/DTOs/Catalog/Notifications/NotificationDto.cs
new file mode 100644
index 0000000..41fea2c
--- /dev/null
+++ b/VNH.Application/DTOs/Catalog/Notifications/NotificationDto.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace VNH.Application.DTOs.Catalog.Notifications
+{
+ public class NotificationDto
+ {
+ public Guid? Id { get; set; }
+ public Guid UserId { get; set; }
+ public Guid? NotificationId { get; set; } = Guid.Empty;
+ public Guid? IdObject { get; set; }
+ public string? Content { get; set; }
+ public DateTime? Date { get; set; }
+ public string? Url { get; set; }
+
+ }
+}
diff --git a/VNH.Application/Interfaces/Catalog/Documents/IDocumentService.cs b/VNH.Application/Interfaces/Catalog/Documents/IDocumentService.cs
index b6bda8b..9c90d6b 100644
--- a/VNH.Application/Interfaces/Catalog/Documents/IDocumentService.cs
+++ b/VNH.Application/Interfaces/Catalog/Documents/IDocumentService.cs
@@ -1,5 +1,6 @@
using VNH.Application.DTOs.Catalog.Document;
using VNH.Application.DTOs.Catalog.Posts;
+using VNH.Application.DTOs.Common;
using VNH.Application.DTOs.Common.ResponseNotification;
namespace VNH.Application.Interfaces.Documents
@@ -12,11 +13,12 @@ public interface IDocumentService
Task>> GetAll();
Task> Delete(string id, string email);
- Task> GetSave(DocumentFpkDto docsFpk);
+ Task> GetSave(DocumentFpkDto docsFpk);
- Task> AddOrRemoveSaveDocs(DocumentFpkDto docsFpk);
+ Task> AddOrRemoveSaveDocs(DocumentFpkDto docsFpk);
Task>> Search(string keyWord);
Task>> GetMyDocument(string userId);
Task>> GetMySave(string userId);
+ Task SaveDownloads(Guid documentId);
}
}
diff --git a/VNH.Application/Interfaces/Catalog/ExamHistory/IExamHistoryService.cs b/VNH.Application/Interfaces/Catalog/ExamHistory/IExamHistoryService.cs
index e7fa8eb..d62757a 100644
--- a/VNH.Application/Interfaces/Catalog/ExamHistory/IExamHistoryService.cs
+++ b/VNH.Application/Interfaces/Catalog/ExamHistory/IExamHistoryService.cs
@@ -12,10 +12,9 @@ public interface IExamHistoryService
{
Task> Create(CreateExamHistoryDto requestDto, string name);
- Task> Update(CreateExamHistoryDto requestDto, string name);
+ Task> Update(CreateExamHistoryDto requestDto, string name);
Task>> GetMyExamHistory(string id);
-
-
+ Task>> GetExamHistory(string examId);
}
}
diff --git a/VNH.Application/Interfaces/Catalog/Forum/IAnswerService.cs b/VNH.Application/Interfaces/Catalog/Forum/IAnswerService.cs
index 1480c56..eb0e3db 100644
--- a/VNH.Application/Interfaces/Catalog/Forum/IAnswerService.cs
+++ b/VNH.Application/Interfaces/Catalog/Forum/IAnswerService.cs
@@ -9,7 +9,7 @@ public interface IAnswerService
{
Task>> GetAnswer(string questionId);
- Task>> CreateAnswer(AnswerQuestionDto answer);
+ Task>> CreateAnswer(AnswerQuestionDto answer, string? id);
Task>> UpdateAnswer(AnswerQuestionDto answer);
Task> DeteleAnswer(string id);
diff --git a/VNH.Application/Interfaces/Catalog/MultipleChoices/IMultipleChoiceService.cs b/VNH.Application/Interfaces/Catalog/MultipleChoices/IMultipleChoiceService.cs
index 9015e5f..62c5966 100644
--- a/VNH.Application/Interfaces/Catalog/MultipleChoices/IMultipleChoiceService.cs
+++ b/VNH.Application/Interfaces/Catalog/MultipleChoices/IMultipleChoiceService.cs
@@ -21,6 +21,7 @@ public interface IMultipleChoiceService
Task> Delete(string id, string userId);
Task> DeleteQuizById(string id);
+ Task>> GetMyMultipleChoice(string id);
Task>> Search(string keyWord);
diff --git a/VNH.Application/Interfaces/Catalog/NotificationServices/INotificationService.cs b/VNH.Application/Interfaces/Catalog/NotificationServices/INotificationService.cs
new file mode 100644
index 0000000..5cc4032
--- /dev/null
+++ b/VNH.Application/Interfaces/Catalog/NotificationServices/INotificationService.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VNH.Application.DTOs.Catalog.Notifications;
+using VNH.Application.DTOs.Common.ResponseNotification;
+using VNH.Domain.Entities;
+
+namespace VNH.Application.Implement.Catalog.NotificationServices
+{
+ public interface INotificationService
+ {
+ Task>> GetAll(string userId);
+ Task> Add(string title);
+ Task AddNotificationDetail(NotificationDto notification);
+ Task> Update(NotificationDto notification);
+ }
+}
diff --git a/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs b/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs
index b671a43..e2d781f 100644
--- a/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs
+++ b/VNH.Application/Interfaces/Catalog/Posts/IPostService.cs
@@ -23,7 +23,7 @@ public interface IPostService
Task> GetSave(PostFpkDto postFpk);
Task>> GetPostByTag(string tag);
Task>> GetComment(string postId);
- Task>> CreateComment(CommentPostDto comment);
+ Task>> CreateComment(CommentPostDto comment, string userId);
Task>> UpdateComment(CommentPostDto comment);
Task>> DeteleComment(string id);
Task>> GetMyPostSaved(string id);
diff --git a/VNH.Application/Interfaces/Common/IImageService.cs b/VNH.Application/Interfaces/Common/IImageService.cs
index 3414e8a..a229109 100644
--- a/VNH.Application/Interfaces/Common/IImageService.cs
+++ b/VNH.Application/Interfaces/Common/IImageService.cs
@@ -10,6 +10,7 @@ namespace VNH.Application.Interfaces.Common
public interface IImageService
{
Task SaveFile(IFormFile file);
+ Task SaveImageArticle(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
index b4978f1..06e4b20 100644
--- a/VNH.Application/Interfaces/Common/IStorageService.cs
+++ b/VNH.Application/Interfaces/Common/IStorageService.cs
@@ -5,6 +5,7 @@ public interface IStorageService
{
string GetFileUrl(string fileName);
Task SaveFileAsync(Stream mediaBinaryStream, string fileName);
+ Task SaveImageFileAsync(Stream mediaBinaryStream, string fileName);
Task DeleteFileAsync(string fileName);
Task SaveDocFileAsync(Stream mediaBinaryStream, string fileName);
Task DeleteDocFileAsync(string fileName);
diff --git a/VNH.Application/Mappers/NotifiMapper.cs b/VNH.Application/Mappers/NotifiMapper.cs
new file mode 100644
index 0000000..581f0b2
--- /dev/null
+++ b/VNH.Application/Mappers/NotifiMapper.cs
@@ -0,0 +1,20 @@
+using AutoMapper;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VNH.Application.DTOs.Catalog.MultipleChoiceDto;
+using VNH.Domain.Entities;
+using VNH.Domain;
+using VNH.Application.DTOs.Catalog.Notifications;
+
+namespace VNH.Application.Mappers
+{
+ public class NotifiMapper : Profile
+ {
+ public NotifiMapper() {
+ CreateMap().ReverseMap();
+ }
+ }
+}
diff --git a/VNH.Application/VNH.Application.csproj b/VNH.Application/VNH.Application.csproj
index ced845f..44a16ec 100644
--- a/VNH.Application/VNH.Application.csproj
+++ b/VNH.Application/VNH.Application.csproj
@@ -16,7 +16,6 @@
-
diff --git a/VNH.Domain/Entities/Document.cs b/VNH.Domain/Entities/Document.cs
index 460a268..1cecb55 100644
--- a/VNH.Domain/Entities/Document.cs
+++ b/VNH.Domain/Entities/Document.cs
@@ -18,10 +18,7 @@ public Document()
[Key]
public Guid Id { get; set; }
- [Required]
- [StringLength(255)]
public string Title { get; set; }
- [StringLength(500)]
public string Description { get; set; }
public string SubId { get; set; }
public bool IsDeleted { get; set; } = false;
@@ -32,6 +29,8 @@ public Document()
public DateTime CreatedAt { get; set; }
[Column(TypeName = "datetime")]
public DateTime? UpdatedAt { get; set; }
+ public long ViewNumber { get; set; }
+ public int DownloadNumber { get; set; }
[ForeignKey("UserId")]
[InverseProperty("Documents")]
diff --git a/VNH.Domain/Entities/ExamHistory.cs b/VNH.Domain/Entities/ExamHistory.cs
index cd10938..264bd40 100644
--- a/VNH.Domain/Entities/ExamHistory.cs
+++ b/VNH.Domain/Entities/ExamHistory.cs
@@ -20,24 +20,14 @@ public partial class ExamHistory
public Guid UserId { get; set; }
- public int Scores { get; set; }
-
+ public float Scores { get; set; }
public int CompletionTime { get; set; }
[Column(TypeName = "datetime")]
public DateTime StarDate { get; set; }
-
-
- [ForeignKey("MultipleChoiceId")]
+ [InverseProperty("ExamHistory")]
public virtual MultipleChoice MultipleChoice { get; set; }
-
-
-
-
-
-
-
}
}
diff --git a/VNH.Domain/Entities/ExamHistoryMultipleChoice.cs b/VNH.Domain/Entities/ExamHistoryMultipleChoice.cs
new file mode 100644
index 0000000..e3391ef
--- /dev/null
+++ b/VNH.Domain/Entities/ExamHistoryMultipleChoice.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace VNH.Domain.Entities
+{
+ public class ExamHistoryMultipleChoice
+ {
+ [Key]
+ public Guid Id { get; set; }
+ public Guid ExamHistoryId { get; set; }
+ public ExamHistory ExamHistory { get; set; }
+
+ public Guid MultipleChoiceId { get; set; }
+ public MultipleChoice MultipleChoice { get; set; }
+ }
+}
diff --git a/VNH.Domain/Entities/MultipleChoice.cs b/VNH.Domain/Entities/MultipleChoice.cs
index de83823..adbbf76 100644
--- a/VNH.Domain/Entities/MultipleChoice.cs
+++ b/VNH.Domain/Entities/MultipleChoice.cs
@@ -12,42 +12,29 @@ namespace VNH.Domain.Entities
[Table("MultipleChoise")]
public partial class MultipleChoice
{
-
[Key]
public Guid Id { get; set; }
public string Title { get; set; }
- [StringLength(500)]
public string Description { get; set; }
- [StringLength(500)]
[Column(TypeName = "datetime")]
public DateTime CreatedAt { get; set; } = DateTime.Now;
-
[Column(TypeName = "datetime")]
public DateTime? UpdatedAt { get; set; }
public int WorkTime { get; set; }
-
public Guid UserId { get; set; }
-
-
-
[InverseProperty("MultipleChoice")]
public virtual ICollection Quiz { get; set; }
-
[ForeignKey("UserId")]
public virtual User User { get; set; }
[InverseProperty("MultipleChoice")]
- public virtual ExamHistory ExamHistories { get; set; }
-
-
-
-
+ public virtual ICollection ExamHistory { get; set; }
}
}
diff --git a/VNH.Domain/Entities/NotificationDetail.cs b/VNH.Domain/Entities/NotificationDetail.cs
index 143b3db..a01e9b1 100644
--- a/VNH.Domain/Entities/NotificationDetail.cs
+++ b/VNH.Domain/Entities/NotificationDetail.cs
@@ -15,8 +15,10 @@ public class NotificationDetail
public Guid Id { get; set; }
public Guid NotificationId { get; set; }
public Guid UserId { get; set; }
+ public Guid? IdObject { get; set; }
public string? Content { get; set; }
public DateTime Date { get; set; }
+ public string? Url { get; set; }
public Confirm IsRead { get; set; }
diff --git a/VNH.Domain/Entities/Post.cs b/VNH.Domain/Entities/Post.cs
index 55eac0e..93714b1 100644
--- a/VNH.Domain/Entities/Post.cs
+++ b/VNH.Domain/Entities/Post.cs
@@ -20,7 +20,7 @@ public Post()
[Key]
[StringLength(255)]
public string Id { get; set; }
- [StringLength(300)]
+ [StringLength(500)]
public string SubId { get; set; } = string.Empty;
[StringLength(255)]
public string Title { get; set; }
diff --git a/VNH.Domain/Entities/Question.cs b/VNH.Domain/Entities/Question.cs
index 795e5b1..a00a004 100644
--- a/VNH.Domain/Entities/Question.cs
+++ b/VNH.Domain/Entities/Question.cs
@@ -17,7 +17,6 @@ public Question()
[Key]
public Guid Id { get; set; }
- [StringLength(500)]
public string Title { get; set; }
public string SubId { get; set; }
public string Content { get; set; }
diff --git a/VNH.Infrastructure/DependencyInjectionInfrastructure.cs b/VNH.Infrastructure/DependencyInjectionInfrastructure.cs
index 5e07495..7aa7ad0 100644
--- a/VNH.Infrastructure/DependencyInjectionInfrastructure.cs
+++ b/VNH.Infrastructure/DependencyInjectionInfrastructure.cs
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Identity;
-using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using VNH.Application.Services.Catalog.Users;
@@ -38,6 +37,8 @@
using VNH.Infrastructure.Implement.Catalog.ExamHistorys;
using VNH.Application.Interfaces.Catalog.NewsHistory;
using VNH.Infrastructure.Implement.Catalog.NewsHistory;
+using VNH.Application.Implement.Catalog.NotificationServices;
+using VNH.Infrastructure.Implement.Catalog.NotificationServices;
namespace VNH.Infrastructure
{
@@ -127,6 +128,7 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi
services.AddScoped();
services.AddScoped();
services.AddScoped();
+ services.AddScoped();
services.AddSignalR();
diff --git a/VNH.Infrastructure/Implement/Catalog/Documents/DocumentService.cs b/VNH.Infrastructure/Implement/Catalog/Documents/DocumentService.cs
index de7a457..5fa1964 100644
--- a/VNH.Infrastructure/Implement/Catalog/Documents/DocumentService.cs
+++ b/VNH.Infrastructure/Implement/Catalog/Documents/DocumentService.cs
@@ -14,6 +14,7 @@
using VNH.Infrastructure.Implement.Common;
using DocumentFormat.OpenXml.Office2010.Excel;
using VNH.Application.DTOs.Catalog.Posts;
+using VNH.Application.DTOs.Common;
namespace VNH.Infrastructure.Implement.Catalog.Documents
{
@@ -78,25 +79,23 @@ public async Task> Update(CreateDocumentDto reques
{
var user = await _userManager.FindByEmailAsync(name);
- var updateDocument = _dataContext.Documents
- .FirstOrDefault(x => x.SubId.Equals(requestDto.SubId));
+ var updateDocument = _dataContext.Documents.FirstOrDefault(x => x.SubId.Equals(requestDto.SubId));
if (updateDocument is null)
{
return new ApiErrorResult("Lỗi :Tài liệu không được cập nhập (không tìm thấy tài liệu)");
}
- if (updateDocument.FileName != string.Empty)
- {
- await _storageService.DeleteDocFileAsync(updateDocument.FileName);
- }
updateDocument.Title = requestDto.Title;
string formattedDateTime = DateTime.Now.ToString("HHmmss.fff") + HandleCommon.GenerateRandomNumber().ToString();
var Id = HandleCommon.SanitizeString(updateDocument.Title);
updateDocument.SubId = Id.Trim().Replace(" ", "-") + "-" + formattedDateTime;
- updateDocument.FilePath = await _document.SaveFile(requestDto.FileName, updateDocument.SubId);
+ if (requestDto.FileName is not null)
+ {
+ await _storageService.DeleteDocFileAsync(updateDocument.FileName);
+ updateDocument.FilePath = await _document.SaveFile(requestDto.FileName, updateDocument.SubId);
+ }
updateDocument.UpdatedAt = DateTime.Now;
updateDocument.Description = requestDto.Description;
updateDocument.FileName = updateDocument.SubId;
-
try
{
_dataContext.Documents.Update(updateDocument);
@@ -159,16 +158,21 @@ public async Task> Detail(string Id)
}
var user = await _userManager.FindByIdAsync(document
.UserId.ToString());
+
var documentResponse = _mapper.Map(document);
documentResponse.FileName = document.FileName;
- documentResponse
- .UserShort = new()
+
+ documentResponse.ViewNumber += 1;
+ document.ViewNumber += 1;
+
+ documentResponse.UserShort = new()
{
FullName = user.Fullname,
Id = user.Id,
Image = user.Image
};
+ _dataContext.Documents.Update(document);
await _dataContext.SaveChangesAsync();
return new ApiSuccessResult(documentResponse);
}
@@ -193,20 +197,25 @@ await _storageService.DeleteFileAsync(document.FileName
return new ApiSuccessResult("Đã xóa tài liệu");
}
- public async Task> GetSave(DocumentFpkDto docsFpk)
+ public async Task> GetSave(DocumentFpkDto docsFpk)
{
var docs = _dataContext.Documents.First(x => x.SubId.Equals(docsFpk.DocumentId));
var check = await _dataContext.DocumentSaves.Where(x => x.DocumentId.Equals(docs.Id) && x.UserId == Guid.Parse(docsFpk.UserId)).FirstOrDefaultAsync();
- var reuslt = check != null;
- return new ApiSuccessResult(reuslt);
+ var numberSave = await _dataContext.DocumentSaves.Where(x => x.DocumentId.Equals(docs.Id)).CountAsync();
+
+ if (check != null)
+ {
+ return new ApiSuccessResult(new() { Check = true, Quantity = numberSave });
+ }
+ return new ApiSuccessResult(new() { Check = false, Quantity = numberSave});
}
- public async Task> AddOrRemoveSaveDocs(DocumentFpkDto docsFpk)
+ public async Task> AddOrRemoveSaveDocs(DocumentFpkDto docsFpk)
{
var docs = await _dataContext.Documents.FirstOrDefaultAsync(x => x.SubId.Equals(docsFpk.DocumentId));
if (docs 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 check = _dataContext.DocumentSaves.Where(x => x.DocumentId == docs.Id && x.UserId == Guid.Parse(docsFpk.UserId)).FirstOrDefault();
var mess = "";
@@ -221,13 +230,13 @@ public async Task> AddOrRemoveSaveDocs(DocumentFpkDto docsFpk)
};
_dataContext.DocumentSaves.Add(save);
await _dataContext.SaveChangesAsync();
- return new ApiSuccessResult(saveNumber+1);
+ return new ApiSuccessResult(new() { Check = true, Quantity = saveNumber + 1 });
}
else
{
_dataContext.DocumentSaves.Remove(check);
await _dataContext.SaveChangesAsync();
- return new ApiSuccessResult(saveNumber-1);
+ return new ApiSuccessResult(new() { Check = false, Quantity = saveNumber - 1 });
}
@@ -248,10 +257,12 @@ orderby matchCount descending
select new Document()
{
Id = document.Id,
+ UserId = document.UserId,
SubId = document.SubId,
Title = document.Title,
CreatedAt = document.CreatedAt,
UpdatedAt = document.UpdatedAt,
+ Description = document.Description
};
foreach (var document in result)
@@ -311,5 +322,18 @@ select post
}
return new ApiSuccessResult>(result);
}
+
+ public async Task SaveDownloads(Guid documentId)
+ {
+ var document = await _dataContext.Documents.FirstOrDefaultAsync(x=>!x.IsDeleted && x.Id == documentId);
+ if(document is null)
+ {
+ return;
+ }
+
+ document.ViewNumber += 1;
+ _dataContext.Documents.Update(document);
+ await _dataContext.SaveChangesAsync();
+ }
}
}
diff --git a/VNH.Infrastructure/Implement/Catalog/ExamHistorys/ExamHistoryService.cs b/VNH.Infrastructure/Implement/Catalog/ExamHistorys/ExamHistoryService.cs
index ca2efba..1046bcf 100644
--- a/VNH.Infrastructure/Implement/Catalog/ExamHistorys/ExamHistoryService.cs
+++ b/VNH.Infrastructure/Implement/Catalog/ExamHistorys/ExamHistoryService.cs
@@ -36,13 +36,18 @@ public ExamHistoryService(UserManager userManager, VietNamHistoryContext d
public async Task> Create(CreateExamHistoryDto requestDto,string name)
{
var user = await _userManager.FindByEmailAsync(name);
+ var check = await _dataContext.ExamHistories.Where(x => x.UserId.Equals(user.Id) && x.MultipleChoiceId == requestDto.MultipleChoiceId ).FirstOrDefaultAsync();
+ if (check != null)
+ {
+ return await Update(requestDto, name);
+ }
var examhistory = _mapper.Map(requestDto);
var multiples = await _dataContext.MultipleChoices.FirstOrDefaultAsync(x => x.Id.Equals(requestDto.MultipleChoiceId));
examhistory.Id = Guid.NewGuid();
examhistory.MultipleChoiceId = requestDto.MultipleChoiceId;
examhistory.UserId = requestDto.UserId;
examhistory.StarDate = requestDto.StarDate;
- examhistory.Scores = requestDto.Scores;
+ examhistory.Scores = float.Parse(requestDto.Scores.ToString());
examhistory.CompletionTime = requestDto.CompletionTime;
try
{
@@ -72,31 +77,25 @@ public async Task> Create(CreateExamHistoryDt
}
};
-
- return new ApiSuccessResult(response);
-
-
+ return new ApiSuccessResult(response);
}
catch (Exception ex)
{
- return new ApiErrorResult("Có lỗi xãy ra : " + ex.Message);
-
+ return new ApiErrorResult("Có lỗi xảy ra : " + ex.Message);
}
-
-
}
- public async Task> Update(CreateExamHistoryDto requestDto,string name)
+ public async Task> Update(CreateExamHistoryDto requestDto,string name)
{
var user = await _userManager.FindByEmailAsync(name);
- var updateExamHistory = _dataContext.ExamHistories.First(x => x.Id.Equals(requestDto.Id));
+ var updateExamHistory = await _dataContext.ExamHistories.FirstOrDefaultAsync(x => x.MultipleChoiceId.Equals(requestDto.MultipleChoiceId) && x.UserId.Equals(requestDto.UserId));
if (updateExamHistory is null)
{
- return new ApiErrorResult("Có lỗi xảy ra !!!");
+ return new ApiErrorResult("Có lỗi xảy ra khi cập nhập kết quả!");
}
updateExamHistory.StarDate = DateTime.Now;
- updateExamHistory.Scores = requestDto.Scores;
+ updateExamHistory.Scores = float.Parse(requestDto.Scores.ToString());
updateExamHistory.CompletionTime = requestDto.CompletionTime;
try
@@ -105,14 +104,11 @@ public async Task> Update(CreateExamHistoryDto requestDto,stri
await _dataContext.SaveChangesAsync();
var response = _mapper.Map(updateExamHistory);
- return new ApiSuccessResult("Lưu Thành công !!!");
-
+ return new ApiSuccessResult(response);
}
catch (Exception ex)
{
-
- return new ApiErrorResult("Lỗi : " + ex.Message);
-
+ return new ApiErrorResult("Lỗi : " + ex.Message);
}
}
@@ -120,40 +116,69 @@ public async Task> Update(CreateExamHistoryDto requestDto,stri
public async Task>> GetMyExamHistory(string id)
{
Guid userId = Guid.Parse(id);
- var users = await _dataContext.User.Where(x => !x.IsDeleted).ToListAsync();
- var examHistories = await(
- from examhis in _dataContext.ExamHistories
- join ex in _dataContext.ExamHistories on examhis.UserId equals userId
- where examhis.UserId == userId
- select ex
- ).ToListAsync();
-
-
+ var user = await _dataContext.User.Where(x => !x.IsDeleted && x.Id == userId).FirstOrDefaultAsync();
+ if(user == null)
+ {
+ return new ApiErrorResult>("Tài khoản không tồn tại");
+ }
+ var examHistories = await _dataContext.ExamHistories.Where(x=>x.UserId.Equals(userId)).ToListAsync();
+ //var examHistories = await (
+ // from examhis in _dataContext.ExamHistories
+ // join ex in _dataContext.ExamHistories on examhis.UserId equals userId
+ // where examhis.UserId == userId
+ // select ex
+ // ).ToListAsync();
+ var users = await _dataContext.User.Where(x => !x.IsDeleted).ToListAsync();
var result = new List();
foreach(var item in examHistories)
{
- var exs = _mapper.Map(item);
- var userShort = users.First(x=>x.Id == item.UserId);
+ var examhistory = _mapper.Map(item);
+ var userShort = users.FirstOrDefault(x=>x.Id == item.UserId);
var multis = await _dataContext.MultipleChoices.FirstOrDefaultAsync(x => x.Id.Equals(item.MultipleChoiceId));
- var rsp = _mapper.Map(multis);
+
+ var exam = _mapper.Map(multis);
if (userShort is not null)
{
- exs.UserShortDto.FullName = userShort.Fullname;
- exs.UserShortDto.Id = userShort.Id;
- exs.UserShortDto.Image = userShort.Image;
+ examhistory.UserShortDto.FullName = userShort.Fullname;
+ examhistory.UserShortDto.Id = userShort.Id;
+ examhistory.UserShortDto.Image = userShort.Image;
}
- exs.multipleChoiceResponseDto = rsp;
-
-
- result.Add(exs);
-
+ examhistory.numberQuiz = await _dataContext.Quizzes.Where(x=>x.MultipleChoiceId == multis.Id).CountAsync();
+ examhistory.multipleChoiceResponseDto = exam;
+ result.Add(examhistory);
}
return new ApiSuccessResult>(result);
}
+ public async Task>> GetExamHistory(string examId)
+ {
+ var examhistories = await _dataContext.ExamHistories.Where(x => x.MultipleChoiceId.ToString().Equals(examId)).ToListAsync();
+
+ var users = await _dataContext.User.Where(x => !x.IsDeleted).ToListAsync();
+ var result = new List();
+ foreach (var item in examhistories)
+ {
+ var examhistory = _mapper.Map(item);
+ var userShort = users.FirstOrDefault(x => x.Id == item.UserId);
+ var multis = await _dataContext.MultipleChoices.FirstOrDefaultAsync(x => x.Id.Equals(item.MultipleChoiceId));
+ var exam = _mapper.Map(multis);
+ if (userShort is not null)
+ {
+ examhistory.UserShortDto.FullName = userShort.Fullname;
+ examhistory.UserShortDto.Id = userShort.Id;
+ examhistory.UserShortDto.Image = userShort.Image;
+ }
+ examhistory.numberQuiz = await _dataContext.Quizzes.Where(x => x.MultipleChoiceId == multis.Id).CountAsync();
+ examhistory.multipleChoiceResponseDto = exam;
+
+ result.Add(examhistory);
+ }
+
+ return new ApiSuccessResult>(result);
+ }
}
}
diff --git a/VNH.Infrastructure/Implement/Catalog/Forum/AnswerService.cs b/VNH.Infrastructure/Implement/Catalog/Forum/AnswerService.cs
index d44516d..ade44e5 100644
--- a/VNH.Infrastructure/Implement/Catalog/Forum/AnswerService.cs
+++ b/VNH.Infrastructure/Implement/Catalog/Forum/AnswerService.cs
@@ -1,11 +1,16 @@
using AutoMapper;
+using DocumentFormat.OpenXml.Office2010.Excel;
+using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
+using VNH.Application.Common.Contants;
using VNH.Application.DTOs.Catalog.Forum.Answer;
+using VNH.Application.DTOs.Catalog.Notifications;
using VNH.Application.DTOs.Catalog.Users;
using VNH.Application.DTOs.Common;
using VNH.Application.DTOs.Common.ResponseNotification;
+using VNH.Application.Implement.Catalog.NotificationServices;
using VNH.Application.Interfaces.Catalog.Forum;
using VNH.Domain;
using VNH.Infrastructure.Presenters;
@@ -19,16 +24,16 @@ public class AnswerService : IAnswerService
private readonly VietNamHistoryContext _dataContext;
private readonly IHubContext _answerHubContext;
private readonly IMapper _mapper;
-
+ private readonly INotificationService _notificationService;
public AnswerService(UserManager userManager, IHubContext answerHubContext,
- IMapper mapper,
- VietNamHistoryContext vietNamHistoryContext)
+ IMapper mapper, VietNamHistoryContext vietNamHistoryContext, INotificationService notificationService)
{
_userManager = userManager;
_dataContext = vietNamHistoryContext;
_mapper = mapper;
_answerHubContext = answerHubContext;
+ _notificationService = notificationService;
}
private UserShortDto? GetUserShort(List users, Guid? IdUser)
@@ -111,7 +116,7 @@ public async Task>> GetAnswer(string questionI
- public async Task>> CreateAnswer(AnswerQuestionDto answer)
+ public async Task>> CreateAnswer(AnswerQuestionDto answer, string? id)
{
var question = await _dataContext.Questions.FirstOrDefaultAsync(x => x.Id.Equals(Guid.Parse(answer.QuestionId)) && !x.IsDeleted);
if (question == null)
@@ -121,10 +126,23 @@ public async Task>> CreateAnswer(AnswerQuestio
Answer answerQuestion = _mapper.Map(answer);
answerQuestion.QuestionId = question.Id;
- answerQuestion.CreatedAt = DateTime.Now;
+
_dataContext.Answers.Add(answerQuestion);
await _dataContext.SaveChangesAsync();
+ var user = await _dataContext.User.FirstOrDefaultAsync(x => x.Id.ToString().Equals(id) && !x.IsDeleted);
+ var noti = new NotificationDto()
+ {
+ Id = Guid.NewGuid(),
+ UserId = user.Id,
+ IdObject = question.Id,
+ Content = ConstantNofication.AnswerTheQuestion(user?.Fullname ?? ""),
+ Date = DateTime.Now,
+ Url = ConstantUrl.UrlQuestionDetail,
+ NotificationId = Guid.NewGuid()
+ };
+ await _notificationService.AddNotificationDetail(noti);
+
var answers = await GetAnswer(answer.QuestionId);
await _answerHubContext.Clients.All.SendAsync("ReceiveAnswer", answers);
@@ -192,7 +210,6 @@ public async Task> CreateSubAnswer(SubAnswerQuestionDto subAns
}
SubAnswer sub = _mapper.Map(subAnswer);
sub.PreAnswerId = answer.Id;
- sub.CreatedAt = DateTime.Now;
_dataContext.SubAnswers.Add(sub);
await _dataContext.SaveChangesAsync();
@@ -287,6 +304,21 @@ public async Task> VoteConfirmByUser(AnswerFpkDto answe
AnswerId = Guid.Parse(answer.AnswerId),
UserId = Guid.Parse(answer.UserId)
};
+
+ var ans = await _dataContext.Answers.FirstOrDefaultAsync(x => !x.IsDeleted && x.Id.ToString() == answer.AnswerId);
+ var user = await _dataContext.User.FirstOrDefaultAsync(x => x.Id.ToString().Equals(ans.AuthorId) && !x.IsDeleted);
+ var noti = new NotificationDto()
+ {
+ Id = Guid.NewGuid(),
+ UserId = user.Id,
+ IdObject = Guid.Parse(answer.QuestionId),
+ Content = ConstantNofication.CommentAnswer(user?.Fullname ?? ""),
+ Date = DateTime.Now,
+ Url = ConstantUrl.UrlQuestionDetail,
+ NotificationId = Guid.NewGuid()
+ };
+ await _notificationService.AddNotificationDetail(noti);
+
_dataContext.AnswerVotes.Add(answerVote);
await _dataContext.SaveChangesAsync();
var numberVote = await _dataContext.AnswerVotes.Where(x => x.AnswerId == Guid.Parse(answer.AnswerId)).CountAsync();
diff --git a/VNH.Infrastructure/Implement/Catalog/Forum/QuestionService.cs b/VNH.Infrastructure/Implement/Catalog/Forum/QuestionService.cs
index df1cdf7..d1ec637 100644
--- a/VNH.Infrastructure/Implement/Catalog/Forum/QuestionService.cs
+++ b/VNH.Infrastructure/Implement/Catalog/Forum/QuestionService.cs
@@ -1,11 +1,16 @@
using AutoMapper;
+using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Hosting;
using Microsoft.IdentityModel.Tokens;
+using VNH.Application.Common.Contants;
using VNH.Application.DTOs.Catalog.Forum.Question;
+using VNH.Application.DTOs.Catalog.Notifications;
using VNH.Application.DTOs.Catalog.Posts;
using VNH.Application.DTOs.Common;
using VNH.Application.DTOs.Common.ResponseNotification;
+using VNH.Application.Implement.Catalog.NotificationServices;
using VNH.Application.Interfaces.Catalog.Forum;
using VNH.Domain;
using VNH.Infrastructure.Implement.Common;
@@ -18,15 +23,17 @@ public class QuestionService : IQuestionService
private readonly UserManager _userManager;
private readonly VietNamHistoryContext _dataContext;
+ private readonly INotificationService _notificationService;
private readonly IMapper _mapper;
public QuestionService(UserManager userManager,
- IMapper mapper,
+ IMapper mapper, INotificationService notificationService,
VietNamHistoryContext vietNamHistoryContext)
{
_userManager = userManager;
_dataContext = vietNamHistoryContext;
_mapper = mapper;
+ _notificationService = notificationService;
}
@@ -167,7 +174,7 @@ public async Task> Detail(string Id)
question.ViewNumber += 1;
questionResponse.ViewNumber += 1;
questionResponse.SaveNumber = await _dataContext.QuestionSaves.Where(x => x.QuestionId.Equals(question.Id)).CountAsync();
- questionResponse.CommentNumber = await _dataContext.Answers.Where(x => x.QuestionId.Equals(question.Id)).CountAsync();
+ questionResponse.CommentNumber = await _dataContext.Answers.Where(x => x.QuestionId.Equals(question.Id) && !x.IsDeleted).CountAsync();
questionResponse.LikeNumber = await _dataContext.QuestionLikes.Where(x => x.QuestionId.Equals(question.Id)).CountAsync();
_dataContext.Questions.Update(question);
@@ -184,7 +191,7 @@ public async Task>> GetAll()
foreach (var item in questions)
{
var question = _mapper.Map(item);
- question.CommentNumber = await _dataContext.Answers.Where(x => x.QuestionId.ToString() == question.Id).CountAsync();
+ question.CommentNumber = await _dataContext.Answers.Where(x => x.QuestionId.ToString() == question.Id && !x.IsDeleted).CountAsync();
question.SaveNumber = await _dataContext.QuestionSaves.Where(x => x.QuestionId.ToString() == question.Id).CountAsync();
question.LikeNumber = await _dataContext.QuestionLikes.Where(x => x.QuestionId.ToString() == question.Id).CountAsync();
@@ -248,7 +255,7 @@ public async Task> AddOrRemoveSaveQuestion(QuestionFpkD
}
- public async Task> GetSave(QuestionFpkDto questionFpk)
+ public async Task> GetSave(QuestionFpkDto questionFpk)
{
var question = await _dataContext.Questions.FirstOrDefaultAsync(x => x.Id.Equals(Guid.Parse(questionFpk.QuestionId)) && !x.IsDeleted);
var number = await _dataContext.QuestionSaves.Where(x => x.QuestionId.Equals(question.Id)).CountAsync();
@@ -355,12 +362,25 @@ public async Task> AddOrUnLikeQuestion(QuestionFpkDto q
var likeNumber = await _dataContext.QuestionLikes.Where(x => x.QuestionId == question.Id).CountAsync();
if (check is null)
{
+ var user = await _dataContext.User.FirstOrDefaultAsync(x => !x.IsDeleted && x.Id == question.AuthorId);
var like = new QuestionLike()
{
Id = Guid.NewGuid(),
QuestionId = question.Id,
UserId = Guid.Parse(questionFpk.UserId)
};
+ var noti = new NotificationDto()
+ {
+ Id = Guid.NewGuid(),
+ UserId = question.AuthorId ?? Guid.NewGuid(),
+ IdObject = question.Id,
+ Content = ConstantNofication.LikeQuestion(user?.Fullname ?? ""),
+ Date = DateTime.Now,
+ Url = ConstantUrl.UrlQuestionDetail,
+ NotificationId = Guid.NewGuid()
+ };
+ await _notificationService.AddNotificationDetail(noti);
+
_dataContext.QuestionLikes.Add(like);
await _dataContext.SaveChangesAsync();
return new ApiSuccessResult(new() { Check = true, Quantity = likeNumber + 1 });
@@ -377,6 +397,7 @@ public async Task> AddOrUnLikeQuestion(QuestionFpkDto q
public async Task>> GetMyQuestion(string id)
{
var questions = await _dataContext.Questions.Where(x => x.AuthorId.Equals(Guid.Parse(id)) && !x.IsDeleted).ToListAsync();
+ var user = await _dataContext.User.Where(x => !x.IsDeleted && x.Id.ToString().Equals(id)).FirstOrDefaultAsync();
var result = new List();
foreach (var item in questions)
{
@@ -384,6 +405,12 @@ public async Task>> GetMyQuestion(string id)
question.SaveNumber = await _dataContext.QuestionSaves.Where(x => x.QuestionId.Equals(item.Id)).CountAsync();
question.CommentNumber = await _dataContext.Answers.Where(x => x.QuestionId.Equals(item.Id)).CountAsync();
question.LikeNumber = await _dataContext.QuestionLikes.Where(x => x.QuestionId.Equals(item.Id)).CountAsync();
+ if (user is not null)
+ {
+ question.UserShort.FullName = user.Fullname;
+ question.UserShort.Id = user.Id;
+ question.UserShort.Image = user.Image;
+ }
result.Add(question);
}
@@ -459,18 +486,18 @@ orderby matchCount descending
item.UserShort.Image = userShort.Image;
}
questions.Add(item);
- }
+ }
return new ApiSuccessResult>(questions);
}
public async Task>> GetMyQuestionSaved(string id)
{
Guid userId = Guid.Parse(id);
- var users = await _dataContext.User.ToListAsync();
+ var users = await _dataContext.User.Where(x => !x.IsDeleted).ToListAsync();
var questions = await(
from questionSave in _dataContext.QuestionSaves
- join question in _dataContext.Questions on questionSave.QuestionId equals question.Id
+ join question in _dataContext.Questions.Where(x=>!x.IsDeleted) on questionSave.QuestionId equals question.Id
where questionSave.UserId == userId
select question
).ToListAsync();
@@ -486,9 +513,9 @@ select question
question.UserShort.Id = userShort.Id;
question.UserShort.Image = userShort.Image;
}
- question.SaveNumber = await _dataContext.QuestionSaves.Where(x => x.QuestionId.Equals(question.Id)).CountAsync();
- question.CommentNumber = await _dataContext.Answers.Where(x => x.QuestionId.Equals(question.Id)).CountAsync();
- question.LikeNumber = await _dataContext.QuestionLikes.Where(x => x.QuestionId.Equals(question.Id)).CountAsync();
+ question.SaveNumber = await _dataContext.QuestionSaves.Where(x => x.QuestionId.Equals(item.Id)).CountAsync();
+ question.CommentNumber = await _dataContext.Answers.Where(x => x.QuestionId.Equals(item.Id) && !x.IsDeleted).CountAsync();
+ question.LikeNumber = await _dataContext.QuestionLikes.Where(x => x.QuestionId.Equals(item.Id)).CountAsync();
result.Add(question);
}
diff --git a/VNH.Infrastructure/Implement/Catalog/MultipleChoices/MultipleChoiceService.cs b/VNH.Infrastructure/Implement/Catalog/MultipleChoices/MultipleChoiceService.cs
index ff93fb4..fbd54d4 100644
--- a/VNH.Infrastructure/Implement/Catalog/MultipleChoices/MultipleChoiceService.cs
+++ b/VNH.Infrastructure/Implement/Catalog/MultipleChoices/MultipleChoiceService.cs
@@ -37,7 +37,7 @@ public MultipleChoiceService(UserManager userManager, VietNamHistoryContex
_mapper = mapper;
}
- public async Task> Create(CreateQuizDto requestDto,string name)
+ public async Task> Create(CreateQuizDto requestDto, string name)
{
var user = await _userManager.FindByEmailAsync(name);
var multipleChoice = new MultipleChoice();
@@ -51,7 +51,7 @@ public async Task> Create(CreateQuizDto requestDto,string name
{
_dataContext.MultipleChoices.Add(multipleChoice);
await _dataContext.SaveChangesAsync();
- foreach(var quiestion in quiz)
+ foreach (var quiestion in quiz)
{
var quizz = new Quiz()
{
@@ -70,19 +70,19 @@ public async Task> Create(CreateQuizDto requestDto,string name
QuizId = quizz.Id,
isCorrect = quizanswer.isCorrect
};
-
+
_dataContext.QuizAnswers.Add(answer);
}
}
await _dataContext.SaveChangesAsync();
return new ApiSuccessResult("Tạo thành công");
}
- catch(Exception ex)
+ catch (Exception ex)
{
return new ApiErrorResult("Lỗi lưu : " + ex.Message);
}
-
+
}
@@ -268,32 +268,32 @@ public async Task> Detail(string id)
}
var user = await _userManager.FindByIdAsync(multipleChoice.UserId.ToString());
var response = _mapper.Map(multipleChoice);
- var quizs = await _dataContext.Quizzes.Where(x=>x.MultipleChoiceId.Equals(Guid.Parse(id))).ToListAsync();
+ var quizs = await _dataContext.Quizzes.Where(x => x.MultipleChoiceId.Equals(Guid.Parse(id))).ToListAsync();
response.WorkTime = multipleChoice.WorkTime;
-
+
foreach (var quiz in quizs)
{
var quizanswers = await _dataContext.QuizAnswers.Where(x => x.QuizId.Equals(quiz.Id)).ToListAsync();
-
+
response.Quizs.Add(new()
- {
- Id = quiz.Id,
- Content = quiz.Content,
- QuizAnswers = _mapper.Map>(quizanswers),
-
- });
-
-
-
-
+ {
+ Id = quiz.Id,
+ Content = quiz.Content,
+ QuizAnswers = _mapper.Map>(quizanswers),
+
+ });
+
+
+
+
}
- foreach(var item in response.Quizs)
+ foreach (var item in response.Quizs)
{
var quizanswers = await _dataContext.QuizAnswers.Where(x => x.QuizId.Equals(item.Id)).ToListAsync();
-
+
}
-
+
response.UserShort = new()
{
FullName = user.Fullname,
@@ -301,12 +301,12 @@ public async Task> Detail(string id)
Image = user.Image,
};
return new ApiSuccessResult(response);
- }
+ }
public async Task>> GetAll()
{
- var list = await _dataContext.MultipleChoices.OrderByDescending(x=> x.CreatedAt).ToListAsync();
+ var list = await _dataContext.MultipleChoices.OrderByDescending(x => x.CreatedAt).ToListAsync();
var users = await _dataContext.User.ToListAsync();
var quizlist = await _dataContext.Quizzes.ToListAsync();
var quizanswerList = await _dataContext.QuizAnswers.ToListAsync();
@@ -316,25 +316,27 @@ public async Task>> GetAll()
foreach (var item in list)
{
var multi = _mapper.Map(item);
- var userShort = users.First(x=> x.Id == item.UserId);
- if(userShort is not null)
+ multi.NumberQuiz = quizlist.Where(x => x.MultipleChoiceId.Equals(item.Id)).Count();
+ var userShort = users.First(x => x.Id == item.UserId);
+ if (userShort is not null)
{
multi.UserShort.FullName = userShort.Fullname;
multi.UserShort.Id = userShort.Id;
multi.UserShort.Image = userShort.Image;
}
+
result.Add(multi);
-
+
}
return new ApiSuccessResult>(result);
}
- public async Task> Update(CreateQuizDto requestDto,string name)
+ public async Task> Update(CreateQuizDto requestDto, string name)
{
var user = await _userManager.FindByEmailAsync(name);
- var updateMultipleChoice = _dataContext.MultipleChoices.First(x => x.Id.Equals(Guid.Parse(requestDto.Id)));
- if(updateMultipleChoice is null)
+ var updateMultipleChoice = await _dataContext.MultipleChoices.FirstOrDefaultAsync(x => x.Id == Guid.Parse(requestDto.Id));
+ if (updateMultipleChoice is null)
{
return new ApiErrorResult("Lỗi :Không được cập nhập (không tìm thấy bài thi nào)");
}
@@ -344,11 +346,11 @@ public async Task> Update(CreateQuizDto requestDto,string name
updateMultipleChoice.UpdatedAt = DateTime.Now;
try
{
- _dataContext.MultipleChoices.Update(updateMultipleChoice);
+ _dataContext.MultipleChoices.Update(updateMultipleChoice);
await _dataContext.SaveChangesAsync();
return new ApiSuccessResult("Cập nhập bài thi thành công");
}
- catch(Exception ex)
+ catch (Exception ex)
{
return new ApiErrorResult("Lỗi lưu bài thi : " + ex.Message);
@@ -358,16 +360,16 @@ public async Task> Update(CreateQuizDto requestDto,string name
public async Task> UpdateQuizById(QuizDto requestDto)
{
- var updateQuiz = _dataContext.Quizzes.First(x => x.Id.Equals(requestDto.Id));
- if(updateQuiz is null)
+ var updateQuiz = _dataContext.Quizzes.First(x => x.Id.Equals(requestDto.Id));
+ if (updateQuiz is null)
{
return new ApiErrorResult("Lỗi :Không được cập nhập (không tìm thấy câu hỏi nào)");
}
updateQuiz.Content = requestDto.Content;
- foreach(var item in requestDto.QuizAnswers)
+ foreach (var item in requestDto.QuizAnswers)
{
- var updateQuizAnswer = _dataContext.QuizAnswers.First(x=>x.Id.Equals(item.Id));
- if(updateQuizAnswer != null)
+ var updateQuizAnswer = _dataContext.QuizAnswers.First(x => x.Id.Equals(item.Id));
+ if (updateQuizAnswer != null)
{
updateQuizAnswer.Content = item.Content;
updateQuizAnswer.isCorrect = item.isCorrect;
@@ -383,7 +385,7 @@ public async Task> UpdateQuizById(QuizDto requestDto)
return new ApiSuccessResult(response);
}
- catch(Exception ex) {
+ catch (Exception ex) {
return new ApiErrorResult("Lỗi lưu câu hỏi : " + ex.Message);
}
@@ -392,64 +394,106 @@ public async Task> UpdateQuizById(QuizDto requestDto)
public async Task> Delete(string id, string userId)
{
- var multiple = await _dataContext.MultipleChoices.FirstOrDefaultAsync(x => x.Id.Equals(Guid.Parse(id)) && x.UserId.Equals(Guid.Parse(userId)));
- if(multiple is null)
+ var multiple = await _dataContext.MultipleChoices
+ .FirstOrDefaultAsync(x => x.Id.Equals(Guid.Parse(id)) && x.UserId.Equals(Guid.Parse(userId)));
+
+ if (multiple is null)
{
return new ApiErrorResult("Không tìm thấy bài thi");
}
- var quizs = await _dataContext.Quizzes.ToListAsync();
- var quizsAnswer = await _dataContext.QuizAnswers.ToListAsync();
- foreach(var item in quizs)
+ var multipleChoiceId = multiple.Id;
+
+ // Xoá lịch sử bài thi
+ var examHistoriesToDelete = _dataContext.ExamHistories
+ .Where(x => x.MultipleChoiceId == multipleChoiceId)
+ .ToList();
+
+ if (examHistoriesToDelete.Any())
{
- if(item.MultipleChoiceId.Equals(id))
- {
- foreach(var item1 in quizsAnswer)
- {
- if(item1.QuizId.Equals(item.Id))
- {
- _dataContext.QuizAnswers.Remove(item1);
- await _dataContext.SaveChangesAsync();
- }
- }
- _dataContext.Quizzes.Remove(item);
- await _dataContext.SaveChangesAsync();
- }
+ _dataContext.ExamHistories.RemoveRange(examHistoriesToDelete);
}
+ // Xoá câu trả lời của từng câu hỏi
+ var quizIdsToDelete = _dataContext.Quizzes
+ .Where(x => x.MultipleChoiceId.Equals(multipleChoiceId))
+ .Select(x => x.Id)
+ .ToList();
+
+ var quizAnswerToDelete = _dataContext.QuizAnswers
+ .Where(x => quizIdsToDelete.Contains(x.QuizId))
+ .ToList();
+
+ if (quizAnswerToDelete.Any())
+ {
+ _dataContext.QuizAnswers.RemoveRange(quizAnswerToDelete);
+ }
+
+ // Xoá câu hỏi
+ var quizzesToDelete = _dataContext.Quizzes
+ .Where(x => x.MultipleChoiceId.Equals(multipleChoiceId))
+ .ToList();
+
+ if (quizzesToDelete.Any())
+ {
+ _dataContext.Quizzes.RemoveRange(quizzesToDelete);
+ }
+
+ // Xoá bài thi
_dataContext.MultipleChoices.Remove(multiple);
+
+ // Lưu thay đổi vào cơ sở dữ liệu
await _dataContext.SaveChangesAsync();
+
return new ApiSuccessResult("Xoá bài thi thành công");
- }
+ }
+
public async Task> DeleteQuizById(string id)
{
- var quiz = await _dataContext.Quizzes.FirstOrDefaultAsync(x=>x.Id.Equals(Guid.Parse(id)));
- if(quiz == null)
+ var quiz = await _dataContext.Quizzes.FirstOrDefaultAsync(x => x.Id.Equals(Guid.Parse(id)));
+ if (quiz == null)
{
return new ApiErrorResult("Không tìm thấy câu hỏi");
}
var quizanswers = await _dataContext.QuizAnswers.ToListAsync();
- foreach(var item in quizanswers)
+ foreach (var item in quizanswers)
{
- if(item.QuizId.Equals(id))
+ if (item.QuizId.Equals(id))
{
_dataContext.QuizAnswers.Remove(item);
await _dataContext.SaveChangesAsync();
}
}
_dataContext.Quizzes.Remove(quiz);
- await _dataContext.SaveChangesAsync();
+ await _dataContext.SaveChangesAsync();
return new ApiSuccessResult("Xoá câu hỏi thành công");
}
+ public async Task>> GetMyMultipleChoice(string id)
+ {
+ var list = await _dataContext.MultipleChoices.Where(x => x.UserId.Equals(Guid.Parse(id)) ).ToListAsync();
+
+ var result = new List();
+ var user = await _dataContext.User.Where(x => !x.IsDeleted && x.Id.ToString().Equals(id)).FirstOrDefaultAsync();
+ foreach( var item in list)
+ {
+ var multi = _mapper.Map(item);
+
+ result.Add(multi);
+ }
+ return new ApiSuccessResult>(result);
+
+ }
+
+
public async Task>> Search(string keyWord)
{
var multiples = new List();
- var users = await _dataContext.Users.ToListAsync();
- string[] searchKeywords = keyWord.ToLower().Split(',');
+ var users = await _dataContext.Users.Where(x=>!x.IsDeleted).ToListAsync();
+ string[] searchKeywords = keyWord.ToLower().Split(' ');
var result = from multiple in _dataContext.MultipleChoices as IEnumerable
let titleWords = multiple.Title.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
let searchPhrases = HandleCommon.GenerateSearchPhrases(searchKeywords)
@@ -467,17 +511,23 @@ orderby matchCount descending
WorkTime = multiple.WorkTime,
UserId = multiple.UserId,
};
- foreach(var multi in result)
+
+ if(result.Count() > 0 )
{
- var item = _mapper.Map(multi);
- var userShort = users.First(x=>x.Id == multi.UserId);
- if(userShort is not null)
+ var quizlist = await _dataContext.Quizzes.ToListAsync();
+ foreach (var multi in result)
{
- item.UserShort.FullName = userShort.Fullname;
- item.UserShort.Id = userShort.Id;
- item.UserShort.Image = userShort.Image;
+ var item = _mapper.Map(multi);
+ var userShort = users.FirstOrDefault(x => x.Id == multi.UserId);
+ item.NumberQuiz = quizlist.Where(x => x.MultipleChoiceId.Equals(multi.Id)).Count();
+ if (userShort is not null)
+ {
+ item.UserShort.FullName = userShort.Fullname;
+ item.UserShort.Id = userShort.Id;
+ item.UserShort.Image = userShort.Image;
+ }
+ multiples.Add(item);
}
- multiples.Add(item);
}
return new ApiSuccessResult>(multiples);
diff --git a/VNH.Infrastructure/Implement/Catalog/NotificationServices/NotificationService.cs b/VNH.Infrastructure/Implement/Catalog/NotificationServices/NotificationService.cs
new file mode 100644
index 0000000..c9593ea
--- /dev/null
+++ b/VNH.Infrastructure/Implement/Catalog/NotificationServices/NotificationService.cs
@@ -0,0 +1,91 @@
+using AutoMapper;
+using Microsoft.AspNetCore.SignalR;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using VNH.Application.DTOs.Catalog.Notifications;
+using VNH.Application.DTOs.Common.ResponseNotification;
+using VNH.Application.Implement.Catalog.NotificationServices;
+using VNH.Domain.Entities;
+using VNH.Domain.Enums;
+using VNH.Infrastructure.Presenters;
+using VNH.Infrastructure.Presenters.Migrations;
+
+namespace VNH.Infrastructure.Implement.Catalog.NotificationServices
+{
+ public class NotificationService : INotificationService
+ {
+ private readonly VietNamHistoryContext _dataContext;
+ private readonly IHubContext _notiHubContext;
+ private readonly IMapper _mapper;
+ public NotificationService(VietNamHistoryContext vietNamHistoryContext, IHubContext chatSignalR,
+ IMapper mapper )
+ {
+ _dataContext = vietNamHistoryContext;
+ _notiHubContext = chatSignalR;
+ _mapper = mapper;
+ }
+ public async Task> Add(string title)
+ {
+ var noti = new Notification()
+ {
+ Title = title,
+ Id = Guid.NewGuid(),
+ Date = DateTime.Now,
+ };
+ _dataContext.Notifications.Add(noti);
+ await _dataContext.SaveChangesAsync();
+
+ return new ApiSuccessResult(new());
+ }
+
+ public async Task AddNotificationDetail(NotificationDto notification)
+ {
+ var noti = await _dataContext.Notifications.FirstOrDefaultAsync();
+ if (noti == null)
+ {
+ return;
+ }
+ var notificationDetail = new NotificationDetail()
+ {
+ Id = Guid.NewGuid(),
+ NotificationId = noti.Id,
+ UserId = notification.UserId,
+ Content = notification.Content,
+ Url = notification.Url,
+ Date = DateTime.Now,
+ IsRead = Confirm.No,
+ IdObject = notification.IdObject
+ };
+
+ _dataContext.NotificationDetails.Add(notificationDetail);
+ await _dataContext.SaveChangesAsync();
+ await _notiHubContext.Clients.Group(notification.UserId.ToString()).SendAsync("ReceiveNoti", notification);
+ }
+
+ public async Task>> GetAll(string userId)
+ {
+ var notidetails = await _dataContext.NotificationDetails.Where(x => x.UserId == Guid.Parse(userId)).ToListAsync();
+ if (notidetails.Any())
+ {
+ List result = new();
+ foreach (var item in notidetails)
+ {
+ var notificationDetail = new NotificationDto();
+ notificationDetail = _mapper.Map(item);
+ result.Add(notificationDetail);
+ }
+ return new ApiSuccessResult>(result);
+ }
+ return new ApiSuccessResult>(new());
+ }
+
+ public Task> Update(NotificationDto notification)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs b/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs
index 3939e22..25e496c 100644
--- a/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs
+++ b/VNH.Infrastructure/Implement/Catalog/Posts/PostService.cs
@@ -1,13 +1,18 @@
using AutoMapper;
+using DocumentFormat.OpenXml.Spreadsheet;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
+using VNH.Application.Common.Contants;
+using VNH.Application.DTOs.Catalog.Notifications;
using VNH.Application.DTOs.Catalog.Posts;
using VNH.Application.DTOs.Catalog.Users;
using VNH.Application.DTOs.Common;
using VNH.Application.DTOs.Common.ResponseNotification;
+using VNH.Application.Implement.Catalog.NotificationServices;
using VNH.Application.Interfaces.Common;
using VNH.Application.Interfaces.Posts;
using VNH.Domain;
@@ -26,10 +31,11 @@ public class PostService : IPostService
private readonly IStorageService _storageService;
private readonly IHubContext _commentHubContext;
private readonly IMapper _mapper;
+ private readonly INotificationService _notificationService;
public PostService(UserManager userManager, IMapper mapper, IImageService image,
VietNamHistoryContext vietNamHistoryContext, IStorageService storageService,
- IHubContext chatSignalR)
+ IHubContext chatSignalR, INotificationService notificationService)
{
_userManager = userManager;
_mapper = mapper;
@@ -37,6 +43,7 @@ public PostService(UserManager userManager, IMapper mapper, IImageService
_dataContext = vietNamHistoryContext;
_storageService = storageService;
_commentHubContext = chatSignalR;
+ _notificationService = notificationService;
}
public async Task> Create(CreatePostDto requestDto, string name)
{
@@ -279,14 +286,27 @@ public async Task> AddOrUnLikePost(PostFpkDto postFpk)
var likeNumber = await _dataContext.PostLikes.Where(x => x.PostId == post.Id).CountAsync();
if (check is null)
{
+ var user = await _dataContext.User.FirstOrDefaultAsync(x => !x.IsDeleted && x.Id == Guid.Parse(postFpk.UserId));
var like = new PostLike()
{
Id = Guid.NewGuid(),
PostId = post.Id,
UserId = Guid.Parse(postFpk.UserId)
};
+ var noti = new NotificationDto()
+ {
+ Id = Guid.NewGuid(),
+ UserId = post.UserId,
+ IdObject = Guid.Parse(post.Id),
+ Content = ConstantNofication.LikePost(user?.Fullname ?? ""),
+ Date = DateTime.Now,
+ Url = ConstantUrl.UrlPostDetail,
+ NotificationId = Guid.NewGuid()
+ };
+
_dataContext.PostLikes.Add(like);
await _dataContext.SaveChangesAsync();
+ await _notificationService.AddNotificationDetail(noti);
return new ApiSuccessResult(new() { Check = true, Quantity = likeNumber + 1});
} else
{
@@ -460,7 +480,7 @@ public async Task>> GetComment(string postId)
.FirstOrDefault();
}
- public async Task>> CreateComment(CommentPostDto comment)
+ public async Task>> CreateComment(CommentPostDto comment, string userId)
{
var post = await _dataContext.Posts.FirstOrDefaultAsync(x=>x.SubId.Equals(comment.PostId) && !x.IsDeleted);
if (post == null)
@@ -470,6 +490,25 @@ public async Task>> CreateComment(CommentPostDto
PostComment postComment = _mapper.Map(comment);
postComment.PostId = post.Id;
postComment.UpdatedAt = DateTime.Now;
+
+ if (userId != post.UserId.ToString())
+ {
+ var user = await _dataContext.User.FirstOrDefaultAsync(x => x.Id.ToString().Equals(userId) && !x.IsDeleted);
+ var noti = new NotificationDto()
+ {
+ Id = Guid.NewGuid(),
+ UserId = post.UserId,
+ IdObject = Guid.Parse(post.Id),
+ Content = ConstantNofication.CommentPost(user?.Fullname ?? ""),
+ Date = DateTime.Now,
+ Url = ConstantUrl.UrlPostDetail,
+ NotificationId = Guid.NewGuid()
+ };
+
+ await _notificationService.AddNotificationDetail(noti);
+ }
+
+
_dataContext.PostComments.Add(postComment);
await _dataContext.SaveChangesAsync();
var comments = await GetComment(comment.PostId);
@@ -518,6 +557,7 @@ public async Task>> GetMyPostSaved(string id)
{
Guid userId = Guid.Parse(id);
var users = await _dataContext.User.Where(x => !x.IsDeleted).ToListAsync();
+ var topics = await _dataContext.Topics.ToListAsync();
var posts = await (
from postSave in _dataContext.PostSaves
@@ -537,6 +577,7 @@ select post
post.UserShort.Id = userShort.Id;
post.UserShort.Image = userShort.Image;
}
+ post.TopicName = topics.FirstOrDefault(x => x.Id == item.TopicId)?.Title ?? "";
result.Add(post);
}
return new ApiSuccessResult>(result);
@@ -545,12 +586,22 @@ public async Task>> GetMyPost(string id)
{
var posts = await _dataContext.Posts.Where(x=>x.UserId.Equals(Guid.Parse(id)) && !x.IsDeleted).ToListAsync();
var result = new List();
+ var topics = await _dataContext.Topics.ToListAsync();
+ var user = await _dataContext.User.Where(x => !x.IsDeleted && x.Id.ToString().Equals(id)).FirstOrDefaultAsync();
+
foreach (var item in posts)
{
var post = _mapper.Map(item);
post.SaveNumber = await _dataContext.PostSaves.Where(x => x.PostId.Equals(post.Id)).CountAsync();
post.CommentNumber = await _dataContext.PostComments.Where(x => x.PostId.Equals(post.Id)).CountAsync();
post.LikeNumber = await _dataContext.PostLikes.Where(x => x.PostId.Equals(post.Id)).CountAsync();
+ post.TopicName = topics.FirstOrDefault(x => x.Id == item.TopicId)?.Title ?? "";
+ if (user is not null)
+ {
+ post.UserShort.FullName = user.Fullname;
+ post.UserShort.Id = user.Id;
+ post.UserShort.Image = user.Image;
+ }
result.Add(post);
}
diff --git a/VNH.Infrastructure/Implement/Common/ImageService.cs b/VNH.Infrastructure/Implement/Common/ImageService.cs
index e79e2e1..a7d84bc 100644
--- a/VNH.Infrastructure/Implement/Common/ImageService.cs
+++ b/VNH.Infrastructure/Implement/Common/ImageService.cs
@@ -12,6 +12,7 @@ namespace VNH.Infrastructure.Implement.Common
public class ImageService : IImageService
{
private const string USER_CONTENT_FOLDER_NAME = "Images";
+ private const string USER_IMAGE_FOLDER_NAME = "ArticleImages";
private readonly string URL = SystemConstants.UrlWeb;
private readonly IStorageService _storageService;
public ImageService(IStorageService storageService)
@@ -25,6 +26,13 @@ public async Task SaveFile(IFormFile file)
await _storageService.SaveFileAsync(file.OpenReadStream(), fileName);
return URL + USER_CONTENT_FOLDER_NAME + "/" + fileName;
}
+ public async Task SaveImageArticle(IFormFile file)
+ {
+ var originalFileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName?.Trim('"');
+ var fileName = $"{Guid.NewGuid()}{Path.GetExtension(originalFileName)}";
+ await _storageService.SaveImageFileAsync(file.OpenReadStream(), fileName);
+ return URL + USER_IMAGE_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
index 722a286..2e6420c 100644
--- a/VNH.Infrastructure/Implement/Common/StorageService.cs
+++ b/VNH.Infrastructure/Implement/Common/StorageService.cs
@@ -6,14 +6,17 @@ namespace VNH.Infrastructure.Implement.Common
public class StorageService : IStorageService
{
private readonly string _userContentFolder;
+ private readonly string _userImageFolder;
private readonly string _userDocFolder;
private const string USER_CONTENT_FOLDER_NAME = "Images";
private const string USER_DOC_FOLDER_NAME = "Documents";
+ private const string USER_IMAGE_FOLDER_NAME = "ArticleImages";
public StorageService(IWebHostEnvironment webHostEnvironment)
{
_userContentFolder = Path.Combine(webHostEnvironment.WebRootPath, USER_CONTENT_FOLDER_NAME);
_userDocFolder = Path.Combine(webHostEnvironment.WebRootPath, USER_DOC_FOLDER_NAME);
+ _userImageFolder = Path.Combine(webHostEnvironment.WebRootPath, USER_IMAGE_FOLDER_NAME);
}
public string GetFileUrl(string fileName)
@@ -27,6 +30,12 @@ public async Task SaveFileAsync(Stream mediaBinaryStream, string fileName)
using var output = new FileStream(filePath, FileMode.Create);
await mediaBinaryStream.CopyToAsync(output);
}
+ public async Task SaveImageFileAsync(Stream mediaBinaryStream, string fileName)
+ {
+ var filePath = Path.Combine(_userImageFolder, fileName);
+ using var output = new FileStream(filePath, FileMode.Create);
+ await mediaBinaryStream.CopyToAsync(output);
+ }
public async Task SaveDocFileAsync(Stream mediaBinaryStream, string fileName)
{
var filePath = Path.Combine(_userDocFolder, fileName);
@@ -35,8 +44,7 @@ public async Task SaveDocFileAsync(Stream mediaBinaryStream, string fileName)
}
public async Task DeleteFileAsync(string fileName)
{
- string name = Path.GetFileName(new Uri(fileName).LocalPath);
- var filePath = Path.Combine(_userContentFolder, name);
+ var filePath = Path.Combine(_userContentFolder, fileName);
if (File.Exists(filePath))
{
await Task.Run(() => File.Delete(filePath));
@@ -44,8 +52,7 @@ public async Task DeleteFileAsync(string fileName)
}
public async Task DeleteDocFileAsync(string fileName)
{
- string name = Path.GetFileName(new Uri(fileName).LocalPath);
- var filePath = Path.Combine(_userDocFolder, name);
+ var filePath = Path.Combine(_userDocFolder, fileName);
if (File.Exists(filePath))
{
await Task.Run(() => File.Delete(filePath));
diff --git a/VNH.Infrastructure/Migrations/20231129161341_init.Designer.cs b/VNH.Infrastructure/Migrations/20231129161341_init.Designer.cs
deleted file mode 100644
index 9448718..0000000
--- a/VNH.Infrastructure/Migrations/20231129161341_init.Designer.cs
+++ /dev/null
@@ -1,1877 +0,0 @@
-//
-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("20231129161341_init")]
- partial class init
- {
- ///
- protected override void BuildTargetModel(ModelBuilder modelBuilder)
- {
-#pragma warning disable 612, 618
- modelBuilder
- .HasAnnotation("ProductVersion", "7.0.13")
- .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("CreatedAt")
- .HasColumnType("datetime");
-
- b.Property("MostConfirm")
- .HasColumnType("bit");
-
- b.Property("QuestionId")
- .HasColumnType("uniqueidentifier");
-
- b.Property("UpdatedAt")
- .HasColumnType("datetime");
-
- 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