123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using Microsoft.AspNetCore.Identity;
- using Microsoft.AspNetCore.WebUtilities;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using MTWorkHR.Application.Identity;
- using MTWorkHR.Application.Mapper;
- using MTWorkHR.Application.Models;
- using MTWorkHR.Core.Global;
- using MTWorkHR.Core.IRepositories;
- using MTWorkHR.Core.UnitOfWork;
- using MTWorkHR.Infrastructure.Entities;
- using MTWorkHR.Application.Services.Interfaces;
- using MTWorkHR.Core.Email;
- using MTWorkHR.Core.Entities;
- using MTWorkHR.Infrastructure.UnitOfWorks;
- namespace MTWorkHR.Application.Services
- {
- public class TeamService : BaseService<Team, TeamDto, TeamDto>, ITeamService
- {
- private readonly IUnitOfWork _unitOfWork;
-
- public TeamService(IUnitOfWork unitOfWork):base(unitOfWork)
- {
- _unitOfWork = unitOfWork;
- }
- public override async Task<TeamDto> GetById(long id)
- {
- var entity = await _unitOfWork.Team.GetByIdWithAllChildren(id);
- var response = MapperObject.Mapper.Map<TeamDto>(entity);
- return response;
- }
- public override async Task<TeamDto> Create(TeamDto input)
- {
- var entity = MapperObject.Mapper.Map<Team>(input);
- if (entity is null)
- {
- throw new AppException(ExceptionEnum.MapperIssue);
- }
- var task = await _unitOfWork.Team.AddAsync(entity);
- await _unitOfWork.CompleteAsync();
- var response = MapperObject.Mapper.Map<TeamDto>(task);
- return response;
- }
- public async Task<bool> AssignAdminManager(TeamUserDto teamUser)
- {
- var result = false;
- var team = await _unitOfWork.Team.GetByIdWithAllChildren(teamUser.TeamId);
- if (team?.TeamUsers != null)
- {
- var foundUser = team.TeamUsers.FirstOrDefault(u => u.AssignedUserId == teamUser.AssignedUserId);
- if (foundUser != null)
- {
- foundUser.IsAdmin = teamUser.IsAdmin;
- }
- else
- {
- team.TeamUsers.Add(new TeamUser { IsAdmin = teamUser.IsAdmin, AssignedUserId = teamUser.AssignedUserId});
- }
- }
- else if (team != null)
- {
- team.TeamUsers = new List<TeamUser> { new TeamUser { IsAdmin = teamUser.IsAdmin, AssignedUserId = teamUser.AssignedUserId } };
- }
- await _unitOfWork.CompleteAsync();
-
- return result;
- }
-
- }
- }
|