Пример #1
0
        public async Task <bool> SentInvitation(Guid topicsId, InviteeSentRequest inviteeRequest, string GetUserId)
        {
            var topicOwn = await _context.Topics
                           .Where(s => s.AppUserId.Equals(GetUserId) && s.Id.Equals(topicsId)).SingleOrDefaultAsync();

            if (topicOwn == null)
            {
                return(false);
            }

            var findUser = await _userManager.Users
                           .SingleOrDefaultAsync(s => s.UserName == inviteeRequest.UserName);

            if (findUser == null)
            {
                return(false);
            }

            var inviteeExist = await _context.Invitees
                               .AnyAsync(x => x.AppUserId.Equals(findUser.Id) && x.TopicsId.Equals(topicsId));

            if (inviteeExist)
            {
                return(false);
            }

            var inviteeSent = new Invitee
            {
                Id            = Guid.NewGuid(),
                RequestStatus = false,
                RoleStatus    = inviteeRequest.RoleStatus,
                AcceptedDate  = DateTime.Now,
                AppUserId     = findUser.Id,
                TopicsId      = topicsId
            };

            _context.Invitees.Add(inviteeSent);

            var created = await _context.SaveChangesAsync();

            var User = await _userManager.Users
                       .SingleOrDefaultAsync(s => s.Id == GetUserId);

            var newNottification = new Notification()
            {
                Id                  = Guid.NewGuid(),
                AppUserId           = findUser.Id,
                CreatedTime         = DateTime.Now,
                NotificationMessage = $"#{User.UserName} Sent Collaboration on {topicOwn.Name} ",
                Url                 = topicsId,
                ReadStatus          = false
            };

            _context.Notifications.Add(newNottification);

            await _notificationService.CreateAsync(newNottification);

            return(created > 0);
        }
        public async Task <AuthResponse> SentInvitation(Guid?topicId, InviteeSentRequest inviteeSent)
        {
            var response = await _httpService.Put <InviteeSentRequest, AuthResponse>($"{topics}/{topicId}/sentinvitee", inviteeSent);

            if (!response.Success)
            {
                throw new ApplicationException(await response.GetBody());
            }

            return(response.Response);
        }
Пример #3
0
        public async Task <IActionResult> SentInvitee([FromRoute] Guid topicsId, [FromBody] InviteeSentRequest inviteeSent)
        {
            var invitee = await _inviteeService.SentInvitation(topicsId, inviteeSent, GetUserId());

            if (!invitee)
            {
                return(Ok(new
                {
                    Error = "Not Found"
                }));
            }

            return(Ok(new
            {
                Status = "Invitation sent"
            }));
        }