group
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
@@ -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; }
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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<ReadANDUpdate_CompanyDto, Company>().ReverseMap(); ;
|
||||
|
||||
|
||||
CreateMap<Company,ReadANDUpdate_CompanyDto>();
|
||||
CreateMap<Exper, Read_ExperDto>().ReverseMap();
|
||||
CreateMap<ADD_GroupDto, Group>();
|
||||
CreateMap<Group, Read_GroupDto>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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<Company> _CompanyRepository;
|
||||
private readonly IGenericRepository<Exper> _ExperRepository;
|
||||
private readonly VerificationService _VerificationService;
|
||||
private readonly IMapper _mapper;
|
||||
public async Task<ResponseBase<bool>> ADDExper(ADD_ExperDto dto, int CompanyID)
|
||||
{
|
||||
var Response = new ResponseBase<bool>();
|
||||
@@ -56,8 +58,20 @@ namespace Hushian.Application.Services
|
||||
|
||||
return Response;
|
||||
}
|
||||
//Get Info
|
||||
// Update
|
||||
public async Task<Read_ExperDto?> GetInfoExper(int ExperID)
|
||||
=> _mapper.Map<Read_ExperDto>(await _ExperRepository.Get().FirstOrDefaultAsync(w => w.ID == ExperID));
|
||||
public async Task<List<Read_ExperDto>?> GetExpersInCompany(int companyID)
|
||||
=> _mapper.Map<List<Read_ExperDto>>(await _ExperRepository.Get().Where(w => w.CompanyID == companyID).ToListAsync());
|
||||
public async Task<Read_ExperDto?> GetExpersInGroup(int GroupID)
|
||||
=> _mapper.Map<Read_ExperDto>(await _ExperRepository.Get().Where(w => w.EG.Any(a => a.GroupID == GroupID)).ToListAsync());
|
||||
public async Task<bool> 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<bool> CheckExperInCompany(int CompanyID, int ExperID)
|
||||
=>await _ExperRepository.Get().AnyAsync(w => w.ID == ExperID && w.CompanyID==CompanyID);
|
||||
public async Task<ResponseBase<bool>> ChangePasswordExperFromExper(ChangePasswordDto model, int ExperID)
|
||||
{
|
||||
ResponseBase<bool> 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;
|
||||
}
|
||||
|
120
Hushian.Application/Services/GroupService.cs
Normal file
120
Hushian.Application/Services/GroupService.cs
Normal file
@@ -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<Group> _GroupRepository;
|
||||
private readonly IGenericRepository<ExperGroup> _EGRepository;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ExperService _experService;
|
||||
public async Task<ResponseBase<bool>> NewGroup(ADD_GroupDto model, int CompanyID)
|
||||
{
|
||||
ResponseBase<bool> 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<Group>(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<List<Read_GroupDto>> GetGroupsCompany(int CompanyID)
|
||||
{
|
||||
var entity = await _GroupRepository.Get().Where(f => f.CompanyID == CompanyID).ToListAsync();
|
||||
return _mapper.Map<List<Read_GroupDto>>(entity);
|
||||
}
|
||||
public async Task UpdateGroup(Update_GroupDto model, int CompanyID)
|
||||
{
|
||||
ResponseBase<bool> 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<bool> 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<bool> 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<bool> CHeckGroupMemberCompany(int GroupID, int CompanyID)
|
||||
{
|
||||
return await _GroupRepository.Get().AnyAsync(a => a.CompanyID == CompanyID && a.ID == GroupID);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
Reference in New Issue
Block a user