diff --git a/Common/Common.csproj b/Common/Common.csproj new file mode 100644 index 0000000..125f4c9 --- /dev/null +++ b/Common/Common.csproj @@ -0,0 +1,9 @@ + + + + net9.0 + enable + enable + + + diff --git a/Common/Dtos/Auth/AuthFromCompanySideDto.cs b/Common/Dtos/Auth/AuthFromCompanySideDto.cs new file mode 100644 index 0000000..f95cc07 --- /dev/null +++ b/Common/Dtos/Auth/AuthFromCompanySideDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Auth +{ + public class AuthFromCompanySideDto + { + // username=wxper --- mobile=company + public string UserNameORMobile { get; set; } + public string PassWord { get; set; } + } +} diff --git a/Common/Dtos/Auth/AuthFromUserSideDto.cs b/Common/Dtos/Auth/AuthFromUserSideDto.cs new file mode 100644 index 0000000..6bcf3c8 --- /dev/null +++ b/Common/Dtos/Auth/AuthFromUserSideDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Auth +{ + public class AuthFromUserSideDto + { + public string? FullName { get; set; } + public string Mobile { get; set; } + } +} diff --git a/Common/Dtos/Company/CompanyContentInfo/ADD_CompanyContentInfoDto.cs b/Common/Dtos/Company/CompanyContentInfo/ADD_CompanyContentInfoDto.cs new file mode 100644 index 0000000..e86731e --- /dev/null +++ b/Common/Dtos/Company/CompanyContentInfo/ADD_CompanyContentInfoDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Company.CompanyContentInfo +{ + public class ADD_CompanyContentInfoDto + { + public string Content { get; set; } + } +} diff --git a/Common/Dtos/Company/CompanyContentInfo/ReadANDUpdate_CompanyContentInfoDto.cs b/Common/Dtos/Company/CompanyContentInfo/ReadANDUpdate_CompanyContentInfoDto.cs new file mode 100644 index 0000000..34ccc53 --- /dev/null +++ b/Common/Dtos/Company/CompanyContentInfo/ReadANDUpdate_CompanyContentInfoDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Company.CompanyContentInfo +{ + public class ReadANDUpdate_CompanyContentInfoDto + { + public int ID { get; set; } + public string Content { get; set; } + } +} diff --git a/Common/Dtos/Company/ReadANDUpdate_CompanyDto.cs b/Common/Dtos/Company/ReadANDUpdate_CompanyDto.cs new file mode 100644 index 0000000..8da92a6 --- /dev/null +++ b/Common/Dtos/Company/ReadANDUpdate_CompanyDto.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Company +{ + public class ReadANDUpdate_CompanyDto + { + public int ID { get; set; } + public string FullName { get; set; } + public string? FullNameManager { get; set; } + public string? WebSite { get; set; } + public string? Email { get; set; } + public byte[]? img { get; set; } + public bool Available { get; set; } + public bool allowBot { get; set; } + } +} diff --git a/Common/Dtos/Company/RegisterCompanyDto.cs b/Common/Dtos/Company/RegisterCompanyDto.cs new file mode 100644 index 0000000..491bd28 --- /dev/null +++ b/Common/Dtos/Company/RegisterCompanyDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Company +{ + public class RegisterCompanyDto + { + public string Mobile { get; set; } + public string Password { get; set; } + public string FullName { get; set; } + + } +} diff --git a/Common/Dtos/Conversation/ADD_ConversationDto.cs b/Common/Dtos/Conversation/ADD_ConversationDto.cs new file mode 100644 index 0000000..9865051 --- /dev/null +++ b/Common/Dtos/Conversation/ADD_ConversationDto.cs @@ -0,0 +1,11 @@ + +namespace Common.Dtos.Conversation +{ + public class ADD_ConversationDto + { + public string Question { get; set; } + public int? GroupID { get; set; } + public int CompanyID { get; set; } + public int? ExperID { get; set; } + } +} diff --git a/Common/Dtos/Conversation/ADD_ConversationItemDto.cs b/Common/Dtos/Conversation/ADD_ConversationItemDto.cs new file mode 100644 index 0000000..01a2189 --- /dev/null +++ b/Common/Dtos/Conversation/ADD_ConversationItemDto.cs @@ -0,0 +1,13 @@ + +namespace Common.Dtos.Conversation +{ + public class ADD_ConversationItemDto + { + public int ConversationID { get; set; } + public string Text { get; set; } + public string? FileName { get; set; } + public string? FileType { get; set; } + public byte[]? FileContent { get; set; } + } + +} diff --git a/Common/Dtos/Conversation/Read_ConversationDto.cs b/Common/Dtos/Conversation/Read_ConversationDto.cs new file mode 100644 index 0000000..f3e7aa0 --- /dev/null +++ b/Common/Dtos/Conversation/Read_ConversationDto.cs @@ -0,0 +1,24 @@ +using Common.Enums; + +namespace Common.Dtos.Conversation +{ + public class Read_ConversationDto + { + public int ID { get; set; } + public string Title { get; set; } + public ConversationStatus status { get; set; } + + public int? GroupID { get; set; } + public string? GroupName { get; set; } + + public int UserID { get; set; } + public string? UserFullName { get; set; } + + public int? ExperID { get; set; } + public string? ExperFullName { get; set; } + + public string Cdate { get; set; } + public string Ctime { get; set; } + public int NoReadCount { get; set; } = 0; + } +} diff --git a/Common/Dtos/Conversation/Read_ConversationItemDto.cs b/Common/Dtos/Conversation/Read_ConversationItemDto.cs new file mode 100644 index 0000000..56ad8b4 --- /dev/null +++ b/Common/Dtos/Conversation/Read_ConversationItemDto.cs @@ -0,0 +1,19 @@ +using Common.Enums; + + +namespace Common.Dtos.Conversation +{ + public class Read_ConversationItemDto + { + public int ID { get; set; } + public int ConversationID { get; set; } + public int? ExperID { get; set; } + public bool IsRead { get; set; } = false; + public string ExperName { get; set; } + public ConversationType Type { get; set; } + public string text { get; set; } + public string FileName { get; set; } + public string FileType { get; set; } + public byte[] FileContent { get; set; } + } +} diff --git a/Common/Dtos/Exper/ADD_ExperDto.cs b/Common/Dtos/Exper/ADD_ExperDto.cs new file mode 100644 index 0000000..23abe27 --- /dev/null +++ b/Common/Dtos/Exper/ADD_ExperDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Exper +{ + public class ADD_ExperDto + { + public string FullName { get; set; } + public string UserName { get; set; } + public string Password { get; set; } + } +} diff --git a/Common/Dtos/Exper/Update_ExperDto.cs b/Common/Dtos/Exper/Update_ExperDto.cs new file mode 100644 index 0000000..a703d2b --- /dev/null +++ b/Common/Dtos/Exper/Update_ExperDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Exper +{ + public class Update_ExperDto + { + public int ID { get; set; } + // For Update + public string FullName { get; set; } + + } +} diff --git a/Common/Dtos/ExperGroup/ADD_ExperGroupDto.cs b/Common/Dtos/ExperGroup/ADD_ExperGroupDto.cs new file mode 100644 index 0000000..66079b0 --- /dev/null +++ b/Common/Dtos/ExperGroup/ADD_ExperGroupDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.ExperGroup +{ + public class ADD_ExperGroupDto + { + public int ExperID { get; set; } + public int GroupID { get; set; } + } +} diff --git a/Common/Dtos/ExperGroup/Read_ExperGroupDto.cs b/Common/Dtos/ExperGroup/Read_ExperGroupDto.cs new file mode 100644 index 0000000..15f8192 --- /dev/null +++ b/Common/Dtos/ExperGroup/Read_ExperGroupDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.ExperGroup +{ + public class Read_ExperGroupDto + { + public int ExperID { get; set; } + public string ExperName { get; set; } + public int GroupID { get; set; } + public string GroupName { get; set; } + } +} diff --git a/Common/Dtos/Group/ADD_GroupDto.cs b/Common/Dtos/Group/ADD_GroupDto.cs new file mode 100644 index 0000000..a678bd7 --- /dev/null +++ b/Common/Dtos/Group/ADD_GroupDto.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Group +{ + public class ADD_GroupDto + { + public string Name { get; set; } + public byte[]? img { get; set; } + public string? Info { get; set; } + public bool Available { get; set; } = true; + } +} diff --git a/Common/Dtos/Group/Read_GroupDto.cs b/Common/Dtos/Group/Read_GroupDto.cs new file mode 100644 index 0000000..e46b9ff --- /dev/null +++ b/Common/Dtos/Group/Read_GroupDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos.Group +{ + public class Read_GroupDto + { + public int ID { get; set; } + public string Name { get; set; } + public byte[]? img { get; set; } + public string? Info { get; set; } + public bool Available { get; set; } + + } +} diff --git a/Common/Dtos/Read_UserDto.cs b/Common/Dtos/Read_UserDto.cs new file mode 100644 index 0000000..e65a538 --- /dev/null +++ b/Common/Dtos/Read_UserDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Dtos +{ + public class Read_UserDto + { + // CompanyUser OR Exper OR User + public int ID { get; set; } + public string? FullName { get; set; } + public string? UserName { get; set; } + public string? Mobile { get; set; } + } +} diff --git a/Common/Enums/ConversationStatus.cs b/Common/Enums/ConversationStatus.cs new file mode 100644 index 0000000..b0dd3f2 --- /dev/null +++ b/Common/Enums/ConversationStatus.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Enums +{ + public enum ConversationStatus + { + InProgress, Finished + } +} diff --git a/Common/Enums/ConversationType.cs b/Common/Enums/ConversationType.cs new file mode 100644 index 0000000..04394a7 --- /dev/null +++ b/Common/Enums/ConversationType.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Common.Enums +{ + public enum ConversationType + { + EU = 1, UE = 2 + } +} diff --git a/Hushian.Application/Contracts/IGenericRepository.cs b/Hushian.Application/Contracts/IGenericRepository.cs new file mode 100644 index 0000000..fc51f21 --- /dev/null +++ b/Hushian.Application/Contracts/IGenericRepository.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Application.Contracts.Persistence +{ + public interface IGenericRepository where T : class + { + IQueryable Get(); + Task ADD(T entity); + Task> ADD(ICollection entities); + Task ADDBool(T entity); + Task UPDATE(T entity); + Task> UPDATE(ICollection entities); + Task UPDATEBool(T entity); + Task DELETE(T entity); + Task DELETE(ICollection entities); + } +} diff --git a/Hushian.Application/Hushian.Application.csproj b/Hushian.Application/Hushian.Application.csproj new file mode 100644 index 0000000..dc59d4f --- /dev/null +++ b/Hushian.Application/Hushian.Application.csproj @@ -0,0 +1,14 @@ + + + + net9.0 + enable + enable + + + + + + + + diff --git a/Hushian.Domain/Abstracts/BaseEntity.cs b/Hushian.Domain/Abstracts/BaseEntity.cs new file mode 100644 index 0000000..f7881b5 --- /dev/null +++ b/Hushian.Domain/Abstracts/BaseEntity.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Domain.Abstracts +{ + public interface BaseEntity + { + public int ID { get; set; } + public DateTime Cdatetime { get; set; } + } +} diff --git a/Hushian.Domain/Entites/Company.cs b/Hushian.Domain/Entites/Company.cs new file mode 100644 index 0000000..77c4a73 --- /dev/null +++ b/Hushian.Domain/Entites/Company.cs @@ -0,0 +1,41 @@ +using Hushian.Domain.Abstracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Domain.Entites +{ + public class Company : BaseEntity + { + #region Key + public int ID { get; set; } + #endregion + + #region Fild + public DateTime Cdatetime + { get; set; } = DateTime.Now; + public string Password { get; set; } + public string FullName { get; set; } + public string? FullNameManager { get; set; } + public string Mobile { get; set; } + public string? WebSite { get; set; } + public string? Email { get; set; } + public byte[]? img { get; set; } + public bool Available { get; set; } = true; + public bool allowBot { get; set; } = true; + #endregion + + #region Navigation + public ICollection Groups { get; set; } + = new List(); + public ICollection Expers { get; set; } + = new List(); + public ICollection Conversations { get; set; } + = new List(); + public ICollection CompanyContentInfos { get; set; } + = new List(); + #endregion + } +} diff --git a/Hushian.Domain/Entites/CompanyContentInfo.cs b/Hushian.Domain/Entites/CompanyContentInfo.cs new file mode 100644 index 0000000..278d6a8 --- /dev/null +++ b/Hushian.Domain/Entites/CompanyContentInfo.cs @@ -0,0 +1,29 @@ +using Hushian.Domain.Abstracts; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Domain.Entites +{ + public class CompanyContentInfo : BaseEntity + { + #region Key + public int ID { get; set; } + public int CompanyID { get; set; } + #endregion + + #region Fild + public string Content { get; set; } + public DateTime Cdatetime + { get; set; } = DateTime.Now; + #endregion + + #region Navigation + [ForeignKey("CompanyID")] + public Company company { get; set; } + #endregion + } +} diff --git a/Hushian.Domain/Entites/Conversation.cs b/Hushian.Domain/Entites/Conversation.cs new file mode 100644 index 0000000..a3de414 --- /dev/null +++ b/Hushian.Domain/Entites/Conversation.cs @@ -0,0 +1,40 @@ +using Common.Enums; +using Hushian.Domain.Abstracts; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Domain.Entites +{ + public class Conversation : BaseEntity + { + #region Key + public int ID { get; set; } + public int CompanyID { get; set; } + public int UserID { get; set; } + public int? GroupID { get; set; } + #endregion + + #region Fild + public string Title { get; set; } + public ConversationStatus Status { get; set; } + public DateTime? FinishedDateTime { get; set; } + public DateTime Cdatetime + { get; set; } = DateTime.Now; + #endregion + + #region Navigation + [ForeignKey("CompanyID")] + public Company Company { get; set; } + [ForeignKey("UserID")] + public User User { get; set; } + [ForeignKey("GroupID")] + public Group? Group { get; set; } + public ICollection conversationItems { get; set; } + = new List(); + #endregion + } +} diff --git a/Hushian.Domain/Entites/ConversationItem.cs b/Hushian.Domain/Entites/ConversationItem.cs new file mode 100644 index 0000000..b37286b --- /dev/null +++ b/Hushian.Domain/Entites/ConversationItem.cs @@ -0,0 +1,41 @@ +using Common.Enums; +using Hushian.Domain.Abstracts; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Domain.Entites +{ + public class ConversationItem : BaseEntity + { + #region Key + public int ID { get; set; } + public int ConversationID { get; set; } + public string? ExperID { get; set; } + #endregion + + #region Fild + public bool IsRead { get; set; } = false; + public ConversationType Type { get; set; } + public string Text { get; set; } + public string? FileName { get; set; } + public string? FileType { get; set; } + public byte[]? FileContent { get; set; } + public DateTime? ReadDateTime { get; set; } + public DateTime Cdatetime + { get; set; } = DateTime.Now; + #endregion + + #region Navigation + [ForeignKey("ConversationID")] + public Conversation conversation { get; set; } + + [ForeignKey("ExperID")] + public Exper? Exper { get; set; } + #endregion + + } +} diff --git a/Hushian.Domain/Entites/Exper.cs b/Hushian.Domain/Entites/Exper.cs new file mode 100644 index 0000000..86bc4ce --- /dev/null +++ b/Hushian.Domain/Entites/Exper.cs @@ -0,0 +1,35 @@ +using Hushian.Domain.Abstracts; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Domain.Entites +{ + public class Exper : BaseEntity + { + #region Key + public int ID { get; set; } + public int CompanyID { get; set; } + #endregion + + #region Fild + public DateTime Cdatetime + { get; set; } = DateTime.Now; + + public string FullName { get; set; } + public string UserName { get; set; } + public string Password { get; set; } + public bool Available { get; set; } = true; + #endregion + + #region Navigation + [ForeignKey("CompanyID")] + public Company Company { get; set; } + public ICollection EG { get; set; } + = new List(); + #endregion + } +} diff --git a/Hushian.Domain/Entites/ExperGroup.cs b/Hushian.Domain/Entites/ExperGroup.cs new file mode 100644 index 0000000..0072ce7 --- /dev/null +++ b/Hushian.Domain/Entites/ExperGroup.cs @@ -0,0 +1,30 @@ +using Hushian.Domain.Abstracts; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Domain.Entites +{ + public class ExperGroup + { + #region Key + public int ExperID { get; set; } + public int GroupID { get; set; } + #endregion + + #region Fild + public DateTime Cdatetime + { get; set; } = DateTime.Now; + #endregion + + #region Navigation + [ForeignKey("ExperID")] + public Exper Exper { get; set; } + [ForeignKey("GroupID")] + public Group Group { get; set; } + #endregion + } +} diff --git a/Hushian.Domain/Entites/Group.cs b/Hushian.Domain/Entites/Group.cs new file mode 100644 index 0000000..677949b --- /dev/null +++ b/Hushian.Domain/Entites/Group.cs @@ -0,0 +1,31 @@ +using Hushian.Domain.Abstracts; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Domain.Entites +{ + public class Group:BaseEntity + { + #region Key + public int ID { get; set; } + public int CompanyID { get; set; } + #endregion + + #region Fild + public DateTime Cdatetime + { get; set; } = DateTime.Now; + public string Name { get; set; } + #endregion + + #region Navigation + [ForeignKey("CompanyID")] + public Company Company { get; set; } + public ICollection EG { get; set; } + = new List(); + #endregion + } +} diff --git a/Hushian.Domain/Entites/User.cs b/Hushian.Domain/Entites/User.cs new file mode 100644 index 0000000..2c13034 --- /dev/null +++ b/Hushian.Domain/Entites/User.cs @@ -0,0 +1,28 @@ +using Hushian.Domain.Abstracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Domain.Entites +{ + public class User:BaseEntity + { + #region Key + public int ID { get; set; } + #endregion + + #region Fild + public DateTime Cdatetime + { get; set; } = DateTime.Now; + public string? FullName { get; set; } + public string Mobile { get; set; } + #endregion + + #region Navigation + public ICollection Conversations { get; set; } + = new List(); + #endregion + } +} diff --git a/Hushian.Domain/Hushian.Domain.csproj b/Hushian.Domain/Hushian.Domain.csproj new file mode 100644 index 0000000..f62bbce --- /dev/null +++ b/Hushian.Domain/Hushian.Domain.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/Hushian.sln b/Hushian.sln index d788417..00aad12 100644 --- a/Hushian.sln +++ b/Hushian.sln @@ -3,10 +3,52 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.13.35818.85 d17.13 MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hushian.Application", "Hushian.Application\Hushian.Application.csproj", "{E080DBF2-2DD1-4F88-A091-483C6793E112}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hushian.Domain", "Hushian.Domain\Hushian.Domain.csproj", "{1D284010-6533-44B4-A1BC-CE0AA0F90BFE}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hushian.Infrastructure", "Infrastructure\Infrastructure\Hushian.Infrastructure.csproj", "{E2FC6095-8D42-4DD6-9425-8343B73CB452}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hushian.Persistence", "Infrastructure\Persistence\Hushian.Persistence.csproj", "{05D292C2-BB17-4524-B1F2-8A2B6B213C6A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common\Common.csproj", "{5E4ECC9D-90EB-4A5E-9308-99E359978FAE}" +EndProject Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E080DBF2-2DD1-4F88-A091-483C6793E112}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E080DBF2-2DD1-4F88-A091-483C6793E112}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E080DBF2-2DD1-4F88-A091-483C6793E112}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E080DBF2-2DD1-4F88-A091-483C6793E112}.Release|Any CPU.Build.0 = Release|Any CPU + {1D284010-6533-44B4-A1BC-CE0AA0F90BFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D284010-6533-44B4-A1BC-CE0AA0F90BFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D284010-6533-44B4-A1BC-CE0AA0F90BFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D284010-6533-44B4-A1BC-CE0AA0F90BFE}.Release|Any CPU.Build.0 = Release|Any CPU + {E2FC6095-8D42-4DD6-9425-8343B73CB452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E2FC6095-8D42-4DD6-9425-8343B73CB452}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E2FC6095-8D42-4DD6-9425-8343B73CB452}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E2FC6095-8D42-4DD6-9425-8343B73CB452}.Release|Any CPU.Build.0 = Release|Any CPU + {05D292C2-BB17-4524-B1F2-8A2B6B213C6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {05D292C2-BB17-4524-B1F2-8A2B6B213C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {05D292C2-BB17-4524-B1F2-8A2B6B213C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {05D292C2-BB17-4524-B1F2-8A2B6B213C6A}.Release|Any CPU.Build.0 = Release|Any CPU + {5E4ECC9D-90EB-4A5E-9308-99E359978FAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5E4ECC9D-90EB-4A5E-9308-99E359978FAE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5E4ECC9D-90EB-4A5E-9308-99E359978FAE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5E4ECC9D-90EB-4A5E-9308-99E359978FAE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {E2FC6095-8D42-4DD6-9425-8343B73CB452} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + {05D292C2-BB17-4524-B1F2-8A2B6B213C6A} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F0E59B62-9EDF-47DC-AAFD-F841443D0AAE} EndGlobalSection diff --git a/Infrastructure/Infrastructure/Hushian.Infrastructure.csproj b/Infrastructure/Infrastructure/Hushian.Infrastructure.csproj new file mode 100644 index 0000000..125f4c9 --- /dev/null +++ b/Infrastructure/Infrastructure/Hushian.Infrastructure.csproj @@ -0,0 +1,9 @@ + + + + net9.0 + enable + enable + + + diff --git a/Infrastructure/Persistence/GenericRepository.cs b/Infrastructure/Persistence/GenericRepository.cs new file mode 100644 index 0000000..201074e --- /dev/null +++ b/Infrastructure/Persistence/GenericRepository.cs @@ -0,0 +1,124 @@ +using Hushian.Application.Contracts.Persistence; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Security.Principal; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Persistence.Repositories +{ + public class GenericRepository : IGenericRepository where T : class + { + private readonly HushianDbContext _context; + private readonly DbSet _query; + + public GenericRepository(HushianDbContext context) + { + _context = context; + _query = _context.Set(); + } + public async Task ADD(T entity) + { + try + { + await _context.AddAsync(entity); + if ((await _context.SaveChangesAsync() == 1)) + return entity; + + return null; + } + catch (Exception e) + { + return null; + } + } + public async Task ADDBool(T entity) + { + await _context.AddAsync(entity); + return (await _context.SaveChangesAsync() == 1); + } + public async Task> ADD(ICollection entities) + { + try + { + await _context.AddRangeAsync(entities); + if ((await _context.SaveChangesAsync() == entities.Count())) + return entities; + + return null; + } + catch (Exception e) + { + return null; + } + } + public async Task UPDATE(T entity) + { + try + { + _context.Entry(entity).State = EntityState.Modified; + if ((await _context.SaveChangesAsync() == 1)) + return entity; + return null; + } + catch (Exception e) + { + return null; + } + } + public async Task UPDATEBool(T entity) + { + _context.Entry(entity).State = EntityState.Modified; + return (await _context.SaveChangesAsync() == 1); + } + public async Task> UPDATE(ICollection entities) + { + try + { + foreach (var entity in entities) + _context.Entry(entity).State = EntityState.Modified; + + if ((await _context.SaveChangesAsync()) == entities.Count()) + return entities; + return null; + } + catch (Exception e) + { + return null; + } + } + public async Task DELETE(T entity) + { + try + { + _context.Set().Remove(entity); + return (await _context.SaveChangesAsync() == 1); + + } + catch (Exception e) + { + return false; + } + } + public async Task DELETE(ICollection entities) + { + try + { + _context.Set().RemoveRange(entities); + return (await _context.SaveChangesAsync() == entities.Count()); + + } + catch (Exception e) + { + return false; + } + } + public IQueryable Get() + { + //No track + return _query.AsNoTracking().AsQueryable(); + } + } +} diff --git a/Infrastructure/Persistence/Hushian.Persistence.csproj b/Infrastructure/Persistence/Hushian.Persistence.csproj new file mode 100644 index 0000000..f641ed8 --- /dev/null +++ b/Infrastructure/Persistence/Hushian.Persistence.csproj @@ -0,0 +1,21 @@ + + + + net9.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/Infrastructure/Persistence/HushianDbContext.cs b/Infrastructure/Persistence/HushianDbContext.cs new file mode 100644 index 0000000..59c51d9 --- /dev/null +++ b/Infrastructure/Persistence/HushianDbContext.cs @@ -0,0 +1,36 @@ +using Hushian.Domain.Entites; +using Microsoft.EntityFrameworkCore; + + +namespace Hushian.Persistence +{ + public class HushianDbContext : DbContext + { + public HushianDbContext(DbContextOptions options) + :base(options) + { + + } + + #region Table + public DbSet Companies { get; set; } + public DbSet Conversations { get; set; } + public DbSet ConversationItems { get; set; } + public DbSet Groups { get; set; } + public DbSet Expers { get; set; } + public DbSet EG { get; set; } + public DbSet Users { get; set; } + #endregion + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().HasKey(c => new { c.ExperID, c.GroupID }); + + modelBuilder + .ApplyConfigurationsFromAssembly(typeof(HushianDbContext).Assembly); + } + + + + } +} diff --git a/Infrastructure/Persistence/PersistenceServicesRegistration.cs b/Infrastructure/Persistence/PersistenceServicesRegistration.cs new file mode 100644 index 0000000..e7be65f --- /dev/null +++ b/Infrastructure/Persistence/PersistenceServicesRegistration.cs @@ -0,0 +1,30 @@ + + +using Hushian.Application.Contracts.Persistence; +using Hushian.Persistence.Repositories; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using System.Reflection; +using Microsoft.EntityFrameworkCore; + +namespace Hushian.Persistence +{ + public static class PersistenceServicesRegistration + { + public static IServiceCollection ConfigurePersistenceServices(this IServiceCollection services, + IConfiguration configuration) + { + services.AddDbContext(options => + { + options.UseSqlServer(configuration + .GetConnectionString("MainConnectionString")); + }); + services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>)); + + + return services; + } + + + } +}