Пример #1
0
        private void JoinWall(string userId, DataLayer.EntityModels.Models.Multiwall.Wall wall)
        {
            var newMember = new WallMember
            {
                UserId = userId,
                WallId = wall.Id,
                AppNotificationsEnabled   = true,
                EmailNotificationsEnabled = true
            };

            wall.Members.Add(newMember);
        }
Пример #2
0
        private static string GetWallTitle(DataLayer.EntityModels.Models.Multiwall.Wall wall)
        {
            switch (wall.Type)
            {
            case WallType.Events:
                return(string.Format(EmailTemplates.EventPostTitle, wall.Name));

            case WallType.Project:
                return(string.Format(EmailTemplates.ProjectPostTitle, wall.Name));

            default:
                return(string.Format(EmailTemplates.DefaultPostTitle, wall.Name));
            }
        }
Пример #3
0
        private static string GetActionButtonTitle(DataLayer.EntityModels.Models.Multiwall.Wall wall)
        {
            switch (wall.Type)
            {
            case WallType.Events:
                return(EmailTemplates.EventActionButtonTitle);

            case WallType.Project:
                return(EmailTemplates.ProjectActionButtonTitle);

            default:
                return(EmailTemplates.DefaultActionButtonTitle);
            }
        }
Пример #4
0
        public async Task <int> CreateNewWall(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 DataLayer.EntityModels.Models.Multiwall.Wall
            {
                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(),
                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);
        }
Пример #5
0
        private void LeaveWall(string userId, DataLayer.EntityModels.Models.Multiwall.Wall wall)
        {
            var isModerator = wall.Moderators
                              .Any(m => m.UserId == userId && m.WallId == wall.Id);

            if (isModerator && wall.Type == WallType.UserCreated)
            {
                throw new ValidationException(ErrorCodes.WallModeratorCanNotLeave, "Moderator can not leave wall");
            }

            if (wall.Type == WallType.Main)
            {
                throw new ValidationException(ErrorCodes.WallCannotLeaveMain, "Can not leave main wall");
            }

            var member = wall.Members.First(x => x.UserId == userId);

            _wallUsersDbSet.Remove(member);
        }
Пример #6
0
        private void SendWallSubscriberEmails(NewlyCreatedPostDTO post, List <string> destinationEmails, ApplicationUser postCreator, Organization organization, DataLayer.EntityModels.Models.Multiwall.Wall wall)
        {
            var postLink                    = GetPostLink(post.WallType, post.WallId, organization.ShortName, post.Id);
            var authorPictureUrl            = _appSettings.PictureUrl(organization.ShortName, postCreator.PictureId);
            var userNotificationSettingsUrl = _appSettings.UserNotificationSettingsUrl(organization.ShortName);
            var subject = string.Format(Templates.NewWallPostEmailSubject, wall.Name, postCreator.FullName);
            var body    = _markdownConverter.ConvertToHtml(post.MessageBody);

            var emailTemplateViewModel = new NewWallPostEmailTemplateViewModel(
                GetWallTitle(wall),
                authorPictureUrl,
                postCreator.FullName,
                postLink,
                body,
                userNotificationSettingsUrl,
                GetActionButtonTitle(wall));
            var content = _mailTemplate.Generate(emailTemplateViewModel, EmailTemplateCacheKeys.NewWallPost);

            var emailData = new EmailDto(destinationEmails, subject, content);

            _mailingService.SendEmail(emailData);
        }