Пример #1
0
        public async Task <BuildHistoryDTO> ChangeStatus(StatusChangeDto statusChange)
        {
            // TODO add checking
            var buildHistory = Context.BuildHistories.Include(bh => bh.Project)
                               .FirstOrDefault(bh => bh.Id == statusChange.BuildHistoryId);

            if (buildHistory != null)
            {
                buildHistory.BuildStatus = statusChange.Status;

                if (statusChange.Status != BuildStatus.InProgress)
                {
                    buildHistory.BuildAt  = statusChange.Time;
                    buildHistory.Duration = (buildHistory.BuildAt - buildHistory.StartedAt).Value.Milliseconds;
                }

                await Context.SaveChangesAsync();

                if (statusChange.Status != BuildStatus.InProgress)
                {
                    await _notificationsService.Create(new NewNotificationDTO
                    {
                        UserId  = buildHistory.PerformerId,
                        Message = $"{StatusToNotificationMessage(buildHistory, statusChange)}",
                        Type    = StatusToNotificationType(statusChange),
                        Date    = DateTime.Now,
                        ItemId  = statusChange.BuildHistoryId
                    });

                    var teamMembers = await Context.ProjectGroups.AsNoTracking()
                                      .Where(pg => pg.ProjectId == buildHistory.ProjectId)
                                      .Include(pg => pg.Group)
                                      .ThenInclude(g => g.TeamMembers)
                                      .ThenInclude(tm => tm.User).AsNoTracking()
                                      .SelectMany(pg => pg.Group.TeamMembers)
                                      .ToListAsync();

                    foreach (var member in teamMembers.Where(tm => tm.IsAccepted && tm.UserId != buildHistory.PerformerId))
                    {
                        await _notificationsService.Create(new NewNotificationDTO
                        {
                            UserId  = member.UserId,
                            Message = $"{StatusToNotificationMessage(buildHistory, statusChange)}",
                            Type    = StatusToNotificationType(statusChange),
                            Date    = DateTime.Now,
                            ItemId  = statusChange.BuildHistoryId
                        });
                    }
                }
            }

            return(await GetBuildById(statusChange.BuildHistoryId));
        }
Пример #2
0
        public async Task <BuildHistoryDTO> ChangeStatus(StatusChangeDto statusChange)
        {
            // TODO add checking
            var buildHistory = Context.BuildHistories.Include(bh => bh.Project).FirstOrDefault(bh => bh.Id == statusChange.BuildHistoryId);

            if (buildHistory != null)
            {
                buildHistory.BuildStatus = statusChange.Status;

                if (statusChange.Status != BuildStatus.InProgress)
                {
                    buildHistory.BuildAt  = statusChange.Time;
                    buildHistory.Duration = (buildHistory.BuildAt - buildHistory.StartedAt).Value.Milliseconds;
                }

                await Context.SaveChangesAsync();

                if (statusChange.Status != BuildStatus.InProgress)
                {
                    await _notificationsService.Create(new NewNotificationDTO
                    {
                        UserId  = buildHistory.PerformerId,
                        Message = $"{StatusToNotificationMessage(buildHistory, statusChange)}",
                        Type    = StatusToNotificationType(statusChange),
                        Date    = DateTime.Now,
                        ItemId  = statusChange.BuildHistoryId
                    });
                }
            }

            return(await GetBuildById(statusChange.BuildHistoryId));
        }
Пример #3
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
                });
            }
        }
        public void Should_Create_Valid()
        {
            var newNotificationEntity = new NotificationEntity
            {
                Description = "Test",
                ProfileId   = Guid.NewGuid().ToString(),
                Status      = "approved",
                TimeStamp   = DateTime.Now.ToString(CultureInfo.InvariantCulture),
                Title       = "Title",
                Id          = Guid.NewGuid().ToString(),
                Created     = DateTime.Now,
                Updated     = DateTime.Now,
                Version     = 0
            };
            var newCreatedAccountEntity = _service.Create(newNotificationEntity);

            Assert.NotNull(newCreatedAccountEntity);
        }
        public NotificationDto?AddNewNotification(INotificationModel notificationModel)
        {
            if (string.IsNullOrEmpty(notificationModel.ProfileId))
            {
                return(null);
            }
            var notification = _notificationsService.Create(notificationModel.ToNotificationsEntity());

            return(notification.ToNotificationsModel <NotificationDto>());
        }
Пример #6
0
 async Task MakeNotificationAsync(string Message, TeamMember memb = null, int?userId = null, int?groupId = null)
 {
     await _notificationsService.Create(new NewNotificationDTO
     {
         Message = Message,
         Date    = DateTime.Now,
         Type    = NotificationType.Group,
         UserId  = memb != null ? memb.UserId : userId,
         ItemId  = memb != null ? memb.GroupId : groupId
     });
 }
 public async Task <NotificationDTO> Create(NewNotificationDTO notification)
 {
     return(await _notificationsService.Create(notification));
 }