diff --git a/Common/Dtos/Exper/Read_ExperDto.cs b/Common/Dtos/Exper/Read_ExperDto.cs index 2451f1c..7ed5cd2 100644 --- a/Common/Dtos/Exper/Read_ExperDto.cs +++ b/Common/Dtos/Exper/Read_ExperDto.cs @@ -11,7 +11,6 @@ namespace Common.Dtos.Exper public int ID { get; set; } public string FullName { get; set; } public string UserName { get; set; } - public string Password { get; set; } public bool Available { get; set; } } } diff --git a/Common/Dtos/Exper/Update_ExperDto.cs b/Common/Dtos/Exper/Update_ExperDto.cs index 73a3217..d489c4d 100644 --- a/Common/Dtos/Exper/Update_ExperDto.cs +++ b/Common/Dtos/Exper/Update_ExperDto.cs @@ -8,8 +8,6 @@ namespace Common.Dtos.Exper { public class Update_ExperDto { - //From User and CompanyManager - public int ID { get; set; } // For Update public string FullName { get; set; } diff --git a/Common/Dtos/Group/ADD_GroupDto.cs b/Common/Dtos/Group/ADD_GroupDto.cs index a678bd7..f7c8b55 100644 --- a/Common/Dtos/Group/ADD_GroupDto.cs +++ b/Common/Dtos/Group/ADD_GroupDto.cs @@ -11,6 +11,5 @@ namespace Common.Dtos.Group public string Name { get; set; } public byte[]? img { get; set; } public string? Info { get; set; } - public bool Available { get; set; } = true; } } diff --git a/Hushian.Application/MappingProfile.cs b/Hushian.Application/MappingProfile.cs index f048d35..00c035f 100644 --- a/Hushian.Application/MappingProfile.cs +++ b/Hushian.Application/MappingProfile.cs @@ -1,5 +1,7 @@ using AutoMapper; using Common.Dtos.Company; +using Common.Dtos.Exper; +using Common.Dtos.Group; using Hushian.Domain.Entites; @@ -11,8 +13,10 @@ namespace Hushian.Application public MappingProfile(/*IUserService userService*/) { - CreateMap().ReverseMap(); ; - - + CreateMap(); + CreateMap().ReverseMap(); + CreateMap(); + CreateMap(); + } } } diff --git a/Hushian.Application/Services/ExperService.cs b/Hushian.Application/Services/ExperService.cs index fd84708..08e1c20 100644 --- a/Hushian.Application/Services/ExperService.cs +++ b/Hushian.Application/Services/ExperService.cs @@ -1,4 +1,5 @@ -using Common.Dtos; +using AutoMapper; +using Common.Dtos; using Common.Dtos.Exper; using Hushian.Application.Contracts.Persistence; using Hushian.Application.Models; @@ -18,6 +19,7 @@ namespace Hushian.Application.Services private readonly IGenericRepository _CompanyRepository; private readonly IGenericRepository _ExperRepository; private readonly VerificationService _VerificationService; + private readonly IMapper _mapper; public async Task> ADDExper(ADD_ExperDto dto, int CompanyID) { var Response = new ResponseBase(); @@ -56,8 +58,20 @@ namespace Hushian.Application.Services return Response; } - //Get Info - // Update + public async Task GetInfoExper(int ExperID) + => _mapper.Map(await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID)); + public async Task?> GetExpersInCompany(int companyID) + => _mapper.Map>(await _ExperRepository.Get().Where(w => w.CompanyID == companyID).ToListAsync()); + public async Task GetExpersInGroup(int GroupID) + => _mapper.Map(await _ExperRepository.Get().Where(w => w.EG.Any(a => a.GroupID == GroupID)).ToListAsync()); + public async Task UpdateExper(Update_ExperDto model, int ExperID) + { + var exper = await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID); + exper.FullName = model.FullName; + return await _ExperRepository.UPDATEBool(exper); + } + public async Task CheckExperInCompany(int CompanyID, int ExperID) + =>await _ExperRepository.Get().AnyAsync(w => w.ID == ExperID && w.CompanyID==CompanyID); public async Task> ChangePasswordExperFromExper(ChangePasswordDto model, int ExperID) { ResponseBase Response = new(); @@ -72,8 +86,8 @@ namespace Hushian.Application.Services exper.Password = model.NewPassWord.GetHash(); Response.Value = await _ExperRepository.UPDATEBool(exper); if (!Response.Value) Response.Errors.Add("خطا در ذخیره سازی"); - else Response.Success = true; - + else Response.Success = true; + } return Response; } diff --git a/Hushian.Application/Services/GroupService.cs b/Hushian.Application/Services/GroupService.cs new file mode 100644 index 0000000..6bcf6f0 --- /dev/null +++ b/Hushian.Application/Services/GroupService.cs @@ -0,0 +1,120 @@ +using AutoMapper; +using Common.Dtos.Exper; +using Common.Dtos.Group; +using Hushian.Application.Contracts.Persistence; +using Hushian.Application.Models; +using Hushian.Application.Validation; +using Hushian.Domain.Entites; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Hushian.Application.Services +{ + public class GroupService + { + private readonly IGenericRepository _GroupRepository; + private readonly IGenericRepository _EGRepository; + private readonly IMapper _mapper; + private readonly ExperService _experService; + public async Task> NewGroup(ADD_GroupDto model, int CompanyID) + { + ResponseBase Response = new(); + if (!model.Name.IsOnlyPersianLetters()) + Response.Errors.Add("نام باید کاملا به صورت فارسی باشد"); + else if (!string.IsNullOrEmpty(model.Info) && !model.Info.IsOnlyPersianLetters()) + Response.Errors.Add("توضیحات باید کاملا به صورت فارسی باشد"); + else if (model.img != null && !model.img.IsValidImage()) + Response.Errors.Add("تصویر نمی تواند از 5 مگ بیشتر باشد"); + else + { + var nGroup = _mapper.Map(model); + nGroup.CompanyID = CompanyID; + Response.Value = await _GroupRepository.ADDBool(nGroup); + if (Response.Value) Response.Success = true; + + else + { + Response.Errors.Add("خطا در ذخیره سازی"); + } + + } + return Response; + } + public async Task> GetGroupsCompany(int CompanyID) + { + var entity = await _GroupRepository.Get().Where(f => f.CompanyID == CompanyID).ToListAsync(); + return _mapper.Map>(entity); + } + public async Task UpdateGroup(Update_GroupDto model, int CompanyID) + { + ResponseBase Response = new(); + if (!model.Name.IsOnlyPersianLetters()) + Response.Errors.Add("نام باید کاملا به صورت فارسی باشد"); + else if (!string.IsNullOrEmpty(model.Info) && !model.Info.IsOnlyPersianLetters()) + Response.Errors.Add("توضیحات باید کاملا به صورت فارسی باشد"); + else if (model.img != null && !model.img.IsValidImage()) + Response.Errors.Add("تصویر نمی تواند از 5 مگ بیشتر باشد"); + else + { + try + { + var entity = await _GroupRepository.Get().FirstOrDefaultAsync(f => f.ID == model.ID && f.CompanyID == CompanyID); + entity.Name = model.Name; + entity.Info = model.Info; + entity.img = model.img; + + Response.Value = await _GroupRepository.UPDATEBool(entity); + if (Response.Value) + Response.Success = true; + else + { + Response.Errors.Add("خطا در ذخیره سازی"); + } + } + catch (Exception ex) + { + Response.Errors.Add("خطای سیستمی"); + } + } + } + public async Task ChangeAvailableGroup(ChangeAvailable_GroupDto model, int CompanyID) + { + try + { + var entity = await _GroupRepository.Get().FirstOrDefaultAsync(f => f.ID == model.ID && f.CompanyID == CompanyID); + entity.Available = model.Available; + return await _GroupRepository.UPDATEBool(entity); + + } + catch (Exception ex) + { + return false; + } + } + public async Task JoinExperInGroup(int GroupID, int ExperID, int CompanyID) + { + if (await CHeckGroupMemberCompany(GroupID,CompanyID)) + { + if (await _experService.CheckExperInCompany(CompanyID,ExperID)) + { + return await _EGRepository.ADDBool(new ExperGroup() + { + ExperID = ExperID, + GroupID = GroupID + }); + } + } + return false; + } + + public async Task CHeckGroupMemberCompany(int GroupID, int CompanyID) + { + return await _GroupRepository.Get().AnyAsync(a => a.CompanyID == CompanyID && a.ID == GroupID); + } + + } +} diff --git a/Hushian.Domain/Entites/Group.cs b/Hushian.Domain/Entites/Group.cs index 677949b..c83a90a 100644 --- a/Hushian.Domain/Entites/Group.cs +++ b/Hushian.Domain/Entites/Group.cs @@ -19,6 +19,9 @@ namespace Hushian.Domain.Entites public DateTime Cdatetime { get; set; } = DateTime.Now; public string Name { get; set; } + public byte[]? img { get; set; } + public string? Info { get; set; } + public bool Available { get; set; } #endregion #region Navigation