public async Task <Response> ApplyInvite(Guid userId, Guid entityId, InviteEntityType entityType) { var user = await _usersProvider.GetById(userId); switch (entityType) { case InviteEntityType.Company: await AddUserToCompany(entityId, userId, MembershipStatus.Member); break; case InviteEntityType.Team: await AddUserToTeam(entityId, userId, MembershipStatus.Member); break; case InviteEntityType.Project: await AddUserToProject(entityId, userId, MembershipStatus.Member); break; default: throw new ArgumentOutOfRangeException(nameof(entityType), entityType, null); } await _invitesService.RemoveInvite(user.Data.Email, entityId, entityType); return(new Response()); }
public async Task <Response> RemoveInvite(string email, Guid entityId, InviteEntityType inviteEntityType) { var invites = await _repository.GetInvites(entityId, inviteEntityType, new [] { email }); await _repository.DeleteInvites(invites.Select(x => x.Id)); return(new Response()); }
public async Task <Response> SendInvite(string email, Guid entityId, InviteEntityType inviteEntityType) { var invites = (await _repository.GetInvites(entityId, inviteEntityType, new [] { email })).ToList(); var mainInvite = invites.FirstOrDefault(); if (mainInvite != null) { await _emailNotificationsService.SendInviteEmail( email, mainInvite.Creator.Name, //TODO "GET NAME LATER", inviteEntityType.ToString().ToLower(), mainInvite.Code); } invites.Remove(mainInvite); await _repository.DeleteInvites(invites.Select(x => x.Id)); return(new Response()); }
public async Task <Response> InviteUsers(Guid entityId, InviteEntityType entityType, Guid authorId, IEnumerable <string> emails, bool sendMails = true) { var distinctEmails = emails.Distinct().ToList(); var existedUsersEmails = await GetExistedUsersInEntity(entityId, entityType, distinctEmails); var notExistedEmails = distinctEmails.Except(existedUsersEmails).ToList(); var existedInvites = await _invitesService.GetInvites(notExistedEmails, entityId, entityType); notExistedEmails = notExistedEmails.Except(existedInvites.Data.Select(x => x.Email)).ToList(); foreach (var email in notExistedEmails) { await _invitesService.CreateInvite(email, entityId, entityType, authorId); if (sendMails) { await _invitesService.SendInvite(email, entityId, entityType); } } return(new Response()); }
private async Task <Response <IEnumerable <InviteSimpleDTO> > > GetInvitesByEntityId(Guid entityId, InviteEntityType entityType) { var invites = await _invitesService.GetInvites(null, entityId, entityType); return(new Response <IEnumerable <InviteSimpleDTO> > { Data = invites.Data }); }
public async Task <Response <InviteDTO> > CreateInvite(string email, Guid entityId, InviteEntityType inviteEntityType, Guid authorId, string code = null) { if (string.IsNullOrEmpty(code)) { code = CodeHelper.GenerateCodeAsGuid(); } var invite = new InviteModel { Email = email, IsDeleted = false, IsSent = false, CreatedDate = DateTime.UtcNow, Code = code, EntityId = entityId, EntityType = inviteEntityType, CreatorId = authorId }; invite = await _repository.CreateInvite(invite); var mappedInvite = _mapper.Map <InviteDTO>(invite); return(new Response <InviteDTO> { Data = mappedInvite }); }
private async Task <IEnumerable <string> > GetExistedUsersInEntity(Guid entityId, InviteEntityType entityType, IEnumerable <string> emails) { List <string> result; switch (entityType) { case InviteEntityType.Company: var companyUsers = await _companiesUsersRepository.GetCompanyUsersByEmails(entityId, emails); result = companyUsers.Select(x => x.User.Email).ToList(); break; case InviteEntityType.Team: var teamUsers = await _teamsUsersRepository.GetTeamUsersByEmails(entityId, emails); result = teamUsers.Select(x => x.User.Email).ToList(); break; case InviteEntityType.Project: var projectUsers = await _projectsUsersRepository.GetProjectUsersByEmails(entityId, emails); result = projectUsers.Select(x => x.User.Email).ToList(); break; default: result = new List <string>(); break; } return(result); }