示例#1
0
        private async Task <Event> MapNewEvent(CreateEventDto newEventDto)
        {
            var newEvent = new Event
            {
                Created        = DateTime.UtcNow,
                CreatedBy      = newEventDto.UserId,
                OrganizationId = newEventDto.OrganizationId,
                OfficeIds      = JsonConvert.DeserializeObject <string[]>(newEventDto.Offices.Value),
                IsPinned       = newEventDto.IsPinned
            };

            var newWall = new CreateWallDto
            {
                Name          = newEventDto.Name,
                Logo          = newEventDto.ImageName,
                Access        = WallAccess.Private,
                Type          = WallType.Events,
                ModeratorsIds = new List <string> {
                    newEventDto.ResponsibleUserId
                },
                MembersIds = new List <string> {
                    newEventDto.ResponsibleUserId
                },
                UserId         = newEventDto.UserId,
                OrganizationId = newEventDto.OrganizationId
            };

            var wallId = await _wallService.CreateNewWallAsync(newWall);

            newEvent.WallId = wallId;
            UpdateEventInfo(newEventDto, newEvent);

            return(newEvent);
        }
示例#2
0
        public async Task NewProject(NewProjectDto dto)
        {
            var owningUserExists = await _usersDbSet
                                   .AnyAsync(u => u.Id == dto.OwningUserId && u.OrganizationId == dto.OrganizationId);

            if (!owningUserExists)
            {
                throw new ValidationException(ErrorCodes.ContentDoesNotExist, "Incorrect user");
            }

            var members = await _usersDbSet
                          .Where(u => dto.MembersIds.Contains(u.Id))
                          .ToListAsync();

            var completeListOfAttributes = await ManageProjectAttributes(dto.Attributes);

            var project = new Project
            {
                Name           = dto.Title,
                Desc           = dto.Description,
                OwnerId        = dto.OwningUserId,
                OrganizationId = dto.OrganizationId,
                Logo           = dto.Logo,
                Attributes     = completeListOfAttributes.ToList(),
                Members        = members
            };

            var wall = new CreateWallDto
            {
                Name           = dto.Title,
                UserId         = dto.OwningUserId,
                OrganizationId = dto.OrganizationId,
                Type           = WallType.Project,
                Description    = dto.Description,
                Logo           = dto.Logo,
                Access         = WallAccess.Public,
                MembersIds     = members.Select(m => m.Id).Concat(new List <string> {
                    dto.OwningUserId
                }),
                ModeratorsIds = new List <string> {
                    dto.OwningUserId
                }
            };

            _projectsDbSet.Add(project);
            await _wallService.CreateNewWall(wall);

            await _uow.SaveChangesAsync(dto.UserId);
        }
示例#3
0
        public async Task <int> CreateNewWallAsync(CreateWallDto newWallDto)
        {
            var alreadyExists = await _wallsDbSet
                                .AnyAsync(w =>
                                          w.OrganizationId == newWallDto.OrganizationId &&
                                          w.Name == newWallDto.Name &&
                                          (w.Type == WallType.UserCreated ||
                                           w.Type == WallType.Main));

            if (alreadyExists)
            {
                throw new ValidationException(ErrorCodes.WallNameAlreadyExists, "Wall name already exists");
            }

            if (newWallDto.MembersIds == null || newWallDto.MembersIds.Any())
            {
                newWallDto.MembersIds = newWallDto.ModeratorsIds;
            }
            else
            {
                newWallDto.MembersIds = newWallDto.MembersIds.Union(newWallDto.ModeratorsIds);
            }

            var wall = new MultiwallWall
            {
                Access         = newWallDto.Access,
                Type           = newWallDto.Type == WallType.Main ? WallType.UserCreated : newWallDto.Type,
                OrganizationId = newWallDto.OrganizationId,
                Name           = newWallDto.Name,
                Logo           = newWallDto.Logo,
                Description    = newWallDto.Description,
                Moderators     = newWallDto.ModeratorsIds.Select(x => new WallModerator
                {
                    UserId = x
                }).ToList(),
                IsHiddenFromAllWalls = newWallDto.IsHiddenFromAllWalls,
                Members = newWallDto.MembersIds.Select(x => new WallMember
                {
                    UserId = x,
                    AppNotificationsEnabled   = true,
                    EmailNotificationsEnabled = true
                }).ToList()
            };

            _wallsDbSet.Add(wall);
            await _uow.SaveChangesAsync(newWallDto.UserId);

            return(wall.Id);
        }
示例#4
0
        public async Task Should_Throw_Validation_Exception_If_Wall_Name_Already_Exists_In_UserCreated_Walls()
        {
            // Arrange
            _wallsDbSet.SetDbSetDataForAsync(new List <Wall> {
                new Wall {
                    Id = 1, Name = "wall1", OrganizationId = 2, Type = WallType.UserCreated
                }
            }.AsQueryable());
            var newWallDto = new CreateWallDto
            {
                Name           = "wall1",
                OrganizationId = 2,
                UserId         = "wallCreator",
                Description    = "wall1 desc"
            };

            // Act, Assert
            var ex = Assert.ThrowsAsync <ValidationException>(async() => await _wallService.CreateNewWall(newWallDto));

            Assert.AreEqual(ErrorCodes.WallNameAlreadyExists, ex.ErrorCode);
        }
示例#5
0
        private async Task <int> CreateEventWallAsync([NotNull] Event @event)
        {
            var wallDto = new CreateWallDto
            {
                Access        = WallAccess.Private,
                Name          = @event.Name,
                ModeratorsIds = new List <string> {
                    @event.ResponsibleUserId
                },
                MembersIds = new List <string> {
                    @event.ResponsibleUserId
                },
                Type           = WallType.Events,
                Logo           = @event.ImageName,
                OrganizationId = @event.OrganizationId ?? _appSettings.DefaultOrganizationId,
                UserId         = @event.ResponsibleUserId,
                Description    = @event.Description
            };

            var wallId = await _wallService.CreateNewWallAsync(wallDto);

            return(wallId);
        }
        public async Task <NotificationDto> CreateForWall(UserAndOrganizationDTO userOrg, CreateWallDto wallDto, int wallId)
        {
            int mainWallId = await _wallDbSet.Where(w => w.Type == WallType.Main).Select(s => s.Id).SingleAsync();

            var membersToNotify = _wallService.GetWallMembersIds(mainWallId, userOrg);

            var newNotification = Notification.Create(wallDto.Name, wallDto.Description, wallDto.Logo, new Sources {
                WallId = wallId
            }, NotificationType.NewWall, userOrg.OrganizationId, membersToNotify);

            _notificationDbSet.Add(newNotification);

            await _uow.SaveChangesAsync();

            return(_mapper.Map <NotificationDto>(newNotification));
        }