public IActionResult Invite([FromBody] InviteDto invite)
        {
            var userId = Guid.NewGuid();

            _unitOfWork.UserRepository.Add(new User
            {
                Id       = userId,
                Email    = invite.Email,
                Password = Guid.NewGuid().ToString().ToSha256(),
                Status   = UserStatus.Prepared,
                Roles    = invite.Roles.Select(roleName => new UserRole
                {
                    UserId = userId,
                    RoleId = roleName.GetId()
                }).ToArray(),
                Profile = new Profile
                {
                    Id = userId
                }
            });

            _unitOfWork.Save();

            return(Ok(new { userId }));
        }
        public async Task <ResultWrapper <InviteOutDto> > CreateInvite(InviteDto newInvite, TokenDto token)
        {
            if (!TokenValidation.ValidateToken(token, _unitOfWork))
            {
                List <ErrorResult> errors = new List <ErrorResult>();
                errors.Add(new ErrorResult(401, "Invalid token."));
                _unitOfWork.tokenRepo.Remove(_unitOfWork.tokenRepo.Find(tk => tk.token.Equals(token.AccessToken)).FirstOrDefault());
                return(new ResultWrapper <InviteOutDto>(null, errors));
            }

            var invite = GetInvite(newInvite);

            if (invite != null)
            {
                invite.State = newInvite.State;
            }
            else
            {
                invite = Mapper.Map <Invite>(newInvite);
                _unitOfWork.InviteRepo.AddAsync(invite);
            }

            await _unitOfWork.InviteRepo.SaveAsync();

            var eventI = await _unitOfWork.EventRepo.GetAsync(invite.EventId);

            var user = await _unitOfWork.UserRepo.GetAsync(invite.UserId);

            return(new ResultWrapper <InviteOutDto>(ConvertInviteToOutInvite(user, eventI, invite.State), null));
        }
Beispiel #3
0
 public static Invite ToModel(this InviteDto invite) =>
 new Invite
 {
     Id        = Guid.Parse(invite.Id),
     UserId    = Guid.Parse(invite.UserId),
     MeetingId = Guid.Parse(invite.MeetingId)
 };
Beispiel #4
0
        public IActionResult InviteUserWithEmail([FromBody] InviteDto invite)
        {
            Guid g;

            g = Guid.NewGuid();
            pm.InvitationForProject(invite.Id, g.ToString());
            es.SendEmail(invite.Email, "WorkFlow invite", g.ToString());
            return(Ok(invite));
        }
Beispiel #5
0
        public async Task <InviteDto> GetInviteStatus(string inviteUrl)
        {
            var html = await _http.GetHtml($"{inviteUrl}", headers);

            // if data contains empty team id indicates invalid
            var inviteValid = !html.Contains("data-team_id=\"\"");
            var inviteDto   = new InviteDto(inviteValid);

            return(inviteDto);
        }
        public async Task <IActionResult> SendInvite(InviteDto inviteDto)
        {
            //Not able to send invite. Followed by errors.
            var invite = _mapper.Map <Invite>(inviteDto);

            await _inviteService.InsertInvite(invite, User);

            //SEND EMAIL
            inviteDto = _mapper.Map <InviteDto>(invite);

            var response = new ApiResponse <InviteDto>(inviteDto);

            return(Ok(response));
        }
        public async Task <bool> DeleteInvite(InviteDto inviteToDelete, TokenDto token)
        {
            if (!TokenValidation.ValidateToken(token, _unitOfWork))
            {
                List <ErrorResult> error = new List <ErrorResult>();
                _unitOfWork.tokenRepo.Remove(_unitOfWork.tokenRepo.Find(tk => tk.token.Equals(token.AccessToken)).FirstOrDefault());
                error.Add(new ErrorResult(401, "Invalid token."));
                return(false);
            }


            Invite deleteInvite = _unitOfWork.InviteRepo.Find(i => i.UserId == inviteToDelete.UserId && i.EventId == inviteToDelete.EventId).FirstOrDefault();

            _unitOfWork.InviteRepo.Remove(deleteInvite);

            return(await _unitOfWork.InviteRepo.SaveAsync() > 0);
        }
        public async Task <JsonResult> CreateInvite([FromBody] InviteDto invite, [FromHeader] string token)
        {
            if (invite == null || string.IsNullOrEmpty(token))
            {
                Response.StatusCode = 400;
                return(new JsonResult("Bad Request"));
            }

            TokenDto tk = new TokenDto {
                AccessToken = token
            };

            var response = await _inviteService.CreateInvite(invite, tk);

            if (response.Errors != null)
            {
                Response.StatusCode = 401;
                return(new JsonResult(response.Errors));
            }

            Response.StatusCode = 200;
            return(new JsonResult(response.Result));
        }
        public async Task <JsonResult> DeleteInvite(int eventId, int userId, [FromHeader] string token)
        {
            InviteDto inviteToDelete = new InviteDto
            {
                EventId = eventId,
                UserId  = userId
            };

            TokenDto tk = new TokenDto
            {
                AccessToken = token
            };

            bool isDeleted = await this._inviteService.DeleteInvite(inviteToDelete, tk);

            if (!isDeleted)
            {
                Response.StatusCode = 401;
                return(new JsonResult(isDeleted));
            }

            Response.StatusCode = 200;
            return(new JsonResult(isDeleted));
        }
 private Invite GetInvite(InviteDto newInvite)
 {
     return(_unitOfWork.InviteRepo.Find(iv => iv.UserId == newInvite.UserId && iv.EventId == newInvite.EventId).FirstOrDefault());
 }