public async Task <IHttpActionResult> CreateWall(CreateWallViewModel newWall) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var wallDto = _mapper.Map <CreateWallViewModel, CreateWallDto>(newWall); SetOrganizationAndUser(wallDto); try { var wallId = await _wallService.CreateNewWall(wallDto); var userAndOrg = GetUserAndOrganization(); var notificationDto = await _notificationService.CreateForWall(userAndOrg, wallDto, wallId); NotificationHub.SendNotificationToAllUsers(_mapper.Map <NotificationViewModel>(notificationDto), GetUserAndOrganizationHub()); return(Ok(new { Id = wallId })); } catch (ValidationException e) { return(BadRequestWithError(e)); } }
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); }