public async Task <AuthResponse> RemoveInvitation(Guid?topicId, InviteeAcceptRequest inviteeAccept) { var response = await _httpService.Put <InviteeAcceptRequest, AuthResponse>($"{topics}/{topicId}/acceptinvitee", inviteeAccept); if (!response.Success) { throw new ApplicationException(await response.GetBody()); } return(response.Response); }
public async Task <IActionResult> AcceptInvitee([FromRoute] Guid topicsId, [FromBody] InviteeAcceptRequest acceptRequest) { var invitee = await _inviteeService.AcceptInvitation(topicsId, acceptRequest, GetUserId()); if (!invitee) { return(Ok(new AuthResponse { Error = "Error Occur" })); } return(Ok(new AuthResponse { Token = "Invitation Accepted/Deleted" })); }
public async Task <bool> AcceptInvitation(Guid topicsId, InviteeAcceptRequest inviteeAccept, string GetUserId) { var findUsername = await _userManager.FindByNameAsync(inviteeAccept.username); var findInvitee = await _context.Invitees .Include(s => s.Topics) .ThenInclude(s => s.AppUser) .Where(x => x.Topics.AppUserId.Equals(GetUserId) || x.AppUserId.Equals(GetUserId)) .Where(s => s.TopicsId == topicsId) .Where(s => s.AppUserId == findUsername.Id) .SingleOrDefaultAsync(); if (findInvitee == null) { return(false); } if (!inviteeAccept.acceptance) { _context.Invitees.Remove(findInvitee); var deleted = await _context.SaveChangesAsync(); var rejectNottification = new Notification() { Id = Guid.NewGuid(), AppUserId = findInvitee.Topics.AppUserId, CreatedTime = DateTime.Now, NotificationMessage = $"#{ findUsername.UserName } Reject Collaboration on { findInvitee.Topics.Name }", Url = topicsId, ReadStatus = false }; _context.Notifications.Add(rejectNottification); await _notificationService.CreateAsync(rejectNottification); return(deleted > 0); } findInvitee.RequestStatus = inviteeAccept.acceptance; findInvitee.AcceptedDate = DateTime.Now; _context.Invitees.Update(findInvitee); var updated = await _context.SaveChangesAsync(); var dateTime = DateTime.Now; var message = $"#{ findUsername.UserName } Accept Collaboration on { findInvitee.Topics.Name }"; foreach (var item in await _context.Invitees.Include(s => s.AppUser).Where(s => s.TopicsId == topicsId).ToListAsync()) { if (GetUserId == item.AppUserId) { var newNottification = new Notification() { Id = Guid.NewGuid(), AppUserId = findInvitee.Topics.AppUserId, CreatedTime = dateTime, NotificationMessage = message, Url = topicsId, ReadStatus = false }; _notificationsList.Add(newNottification); await _hubContext.Clients.Group(findInvitee.AppUser.UserName).SendAsync("notification", message, dateTime.ToString("O")); } else { var newNottification = new Notification() { Id = Guid.NewGuid(), AppUserId = item.AppUserId, CreatedTime = dateTime, NotificationMessage = message, Url = topicsId, ReadStatus = false }; _notificationsList.Add(newNottification); await _hubContext.Clients.Group(item.AppUser.UserName).SendAsync("notification", message, dateTime.ToString("O")); } } _context.Notifications.AddRange(_notificationsList); await _context.SaveChangesAsync(); await _hubContext.Clients.Group(topicsId.ToString()).SendAsync("RecieveAccept", findUsername.UserName, findUsername.Images, findUsername.FirstName, findUsername.LastName); return(updated > 0); }