public async Task <IActionResult> Create(string email) { var trackerProfile = _userTrackingRepository.GetUserProfile(User.Identity.Name); //todo - try to find user by email, if this is a new user create a profile and send email invite var user = await _userManager.FindByEmailAsync(email); if (user != null) { //Create an invitation and send notification using application var trackeeProfile = _userTrackingRepository.GetUserProfile(user.UserName); var existing = _invitationRepository.Get(trackerProfile.UserName, trackeeProfile.Id); if (existing != null) { _logger.LogWarning("an inviate already exists"); } else { _invitationRepository.Add(new TrackingInvitation() { Status = eInvitationStatus.Invited, TrackerId = trackerProfile.Id, TrackeeId = trackeeProfile.Id, Trackee = trackeeProfile }); _mailServices.Send(User.Identity.Name, user.UserName, trackeeProfile.Id); } } else { //_userTrackingRepository. _userTrackingRepository.AddUserProfile(new UserProfile() { AvatarType = Shared.Avatar.child.ToString(), Created = DateTime.MinValue, // indicates its not created yet.. Status = "new user", UserName = email }); var trackeeProfile = _userTrackingRepository.GetUserProfile(email); //just create the profile and invitation and send an email _invitationRepository.Add(new TrackingInvitation() { email = email, Status = eInvitationStatus.Invited, TrackerId = trackerProfile.Id, TrackeeId = trackeeProfile.Id, Trackee = trackeeProfile }); _mailServices.Send(User.Identity.Name, email, trackeeProfile.Id); } // todo - move to an API call! return(RedirectToAction("Index")); }
public async Task <DTOs.Notification> Invite(DTOs.RequestJoinBand request) { var guest = await banditRepository.Get(request.Guest.Id); if (guest == null) { throw new NotFoundException("Bandit", request.Guest.Id); } var band = await bandRepository.Get(request.Band.Id); if (band == null) { throw new NotFoundException("Band", request.Band.Id); } if (!band.CanRequestToJoin(guest)) { throw new InvalidOperationException(Strings.CantRequestToJoin.Format(guest.Name, band.Name)); } var invitation = Invitation.Create(guest, band, band.Boss.Bandit); await invitationRepository.Add(invitation); var message = Notifications.RequestJoinBand(guest.Name, band.Name); await notifications.Send(message, to : band.Boss.Bandit); return(new DTOs.Notification { To = band.Boss.Bandit.Name, Title = message.Title, Content = message.Body }); }
/// <summary> /// Добавить приглашение для сотрудника /// </summary> /// <param name="employeeId">Идентификатор сотрудника</param> /// <param name="invitationDto">DTO приглашения</param> /// <returns>Идентификатор нового приглашения</returns> public async Task <Guid> AddForEmployeeAsync(Guid employeeId, InvitationDto invitationDto) { var employee = await _employeeRepository.GetAsync(employeeId); var invitation = _invitationRepository.Add(employee: employee, addedInvitation: invitationDto); await _domainContext.SaveChangesAsync(); return(invitation.Id); }
public async Task <Result <int> > Handle(CreateInvitationCommand request, CancellationToken cancellationToken) { var transaction = await _unitOfWork.BeginTransaction(cancellationToken); var meetingParticipants = new List <BuilderParticipant>(); var mcPkgs = new List <McPkg>(); var commPkgs = new List <CommPkg>(); if (request.CommPkgScope.Count > 0) { commPkgs = await GetCommPkgsToAddAsync(request.CommPkgScope, request.ProjectName); } if (request.McPkgScope.Count > 0) { mcPkgs = await GetMcPkgsToAddAsync(request.McPkgScope, request.ProjectName); } var invitation = new Invitation( _plantProvider.Plant, request.ProjectName, request.Title, request.Description, request.Type, request.StartTime, request.EndTime, request.Location, mcPkgs, commPkgs); _invitationRepository.Add(invitation); meetingParticipants = await AddParticipantsAsync(invitation, meetingParticipants, request.Participants.ToList()); await _unitOfWork.SaveChangesAsync(cancellationToken); try { invitation.MeetingId = await CreateOutlookMeeting(request, meetingParticipants, invitation); await _unitOfWork.SaveChangesAsync(cancellationToken); _unitOfWork.Commit(); return(new SuccessResult <int>(invitation.Id)); } catch (Exception e) { await transaction.RollbackAsync(cancellationToken); throw new Exception($"Error: User with oid {_currentUserProvider.GetCurrentUserOid()} could not create outlook meeting for invitation {invitation.Id}.", e); } }
public async Task <IActionResult> InviteUser(InvitationForCreationDto invitationForCreation) { if (!await _users.UserExist(invitationForCreation.UserId) || !await _users.UserExist(invitationForCreation.InvitorId) || !await _repo.OrganizationExist(invitationForCreation.OrganizationId)) { return(BadRequest("Invalid Data")); } var inviter = await _users.GetUser(invitationForCreation.InvitorId); var user = await _users.GetUser(invitationForCreation.UserId); var organization = await _repo.GetOrganization(invitationForCreation.OrganizationId); if (!await _repo.IsAdmin(organization, inviter)) { return(BadRequest("Not Authorized To Invite New Member")); } if (await _invitations.InvitationExist(organization.Id, user.Id)) { return(Conflict("Invitation Already Exist")); } Invitation invitation = new Invitation { User = user, Organization = organization, UserId = user.Id, OrganizationId = organization.Id }; await _invitations.Add(invitation); //TODO, return list of all invitations that belong to this organization var invitations = await _invitations.GetInvitationsByOrganization(organization.Id); var invitationsToReturn = new List <InvitationForListDto>(); foreach (var item in invitations) { var invitationToReturn = new InvitationForListDto { Organization = _mapper.Map <OrganizationForListDto>(item.Organization), User = _mapper.Map <UserForListDto>(item.User) }; invitationsToReturn.Add(invitationToReturn); } return(Ok(invitationsToReturn)); }
public async Task <IActionResult> InviteUser(InvitationForCreationDto invitationForCreation) { var inviterId = HttpContext.GetUserId(); var organizationId = invitationForCreation.OrganizationId; if (!await _orgs.OrganizationExistById(invitationForCreation.OrganizationId)) { return(BadRequest($"Organization with ID {organizationId} does not exist.")); } if (!await _orgs.UserInOrganization(inviterId, organizationId)) { return(BadRequest($"User with ID {inviterId} has no access to Organization with ID {organizationId}.")); } var inviter = await _users.GetUser(inviterId); if (!await _users.UserExist(invitationForCreation.UserId)) { return(BadRequest($"User with ID {invitationForCreation.UserId} does not exist.")); } var user = await _users.GetUser(invitationForCreation.UserId); var organization = await _orgs.GetOrganization(organizationId); if (!await _orgs.IsAdmin(organization, inviter)) { return(BadRequest("Not Authorized To Invite New Member")); } if (await _repo.InvitationExist(organizationId, user.Id)) { return(Conflict("Invitation Already Exist")); } Invitation invitation = new Invitation { UserId = user.Id, OrganizationId = organizationId }; await _repo.Add(invitation); //TODO, return list of all invitations that belong to this organization var invitations = await _repo.GetInvitationsByOrganization(organization.Id); return(Ok(_mapper.Map <List <InvitationForListDto> >(invitations))); }
public async Task <int> AddAsync(string url, string createdBy, string emails) { string[] emailArray = emails.Split(new string[] { "\n", "\r\n", ",", ";", " " }, StringSplitOptions.RemoveEmptyEntries); int result = 0; foreach (string email in emailArray) { string code = CreateRandomCode(6); Invitation invitation = new Invitation(); invitation.CreatedBy = createdBy; invitation.CreatedDate = DateTime.UtcNow.ToString("s"); invitation.Email = email; invitation.InvitationCode = code; result += await _invitationRepository.Add(invitation); await SendEmail(email, url, code); } return(result); }
public ActionResult Invite(string[] email) { FriendInviteView friendInviteView = GetFriendInviteView(); IDictionary <string, string> crumbs = GetCrumbs(); if (email != null) { string[] emails = email.Where(o => !string.IsNullOrEmpty(o)).ToArray(); _invitationRepository.Add(new Invitation { Email = emails, UserId = Owner.Id }); byte invitationsLeft = _invitationRepository.InvitationsLeft(Owner.Id); string message = string.Format("{0} invitation(s) send. {1} invitations remaining.", emails.Length, invitationsLeft); friendInviteView.RemainingInvitationsCount = invitationsLeft; friendInviteView.UIMessage = message; } return(View(friendInviteView, crumbs)); }