示例#1
0
        public async Task DeleteGroupWithNotification(RemoveGroupDTO removeGroup)
        {
            var group = await base.GetAsync(removeGroup.GroupId);

            var teamMembers = (await GetGroupsWithMembersAndProjects())
                              .FirstOrDefault(g => g.Id == removeGroup.GroupId)?
                              .TeamMembers.Where(t => t.UserId != removeGroup.InitiatorUserId).ToList();

            if (group == null)
            {
                throw new NotFoundException(nameof(Group), removeGroup.GroupId);
            }
            await base.RemoveAsync(removeGroup.GroupId);

            var initiator = Context.Users.AsNoTracking().FirstOrDefault(u => u.Id == removeGroup.InitiatorUserId);

            foreach (var member in teamMembers)
            {
                await _notificationsService.Create(new NewNotificationDTO
                {
                    UserId  = member?.UserId,
                    Message = $"{initiator?.Username} deleted group {group?.Name}",
                    Type    = NotificationType.Group,
                    Date    = DateTime.Now,
                    ItemId  = -1
                });
            }
        }
示例#2
0
 public async Task DeleteGroupWithNotification([FromQuery] RemoveGroupDTO removeObject)
 {
     await _groupService.DeleteGroupWithNotification(removeObject);
 }