1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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 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;
- }
-
- }
- }
|