public void SendMessage(int?ddCourses, string textMessage) { var controller = User is StudentViewModel ? "Student" : "Teacher"; var usersInCourse = _studentAppService.GetUsersForStudent(CurrentUser.Id).Where(s => s.Courses.Any(c => c.Id.Equals(ddCourses.Value))); var users = ddCourses != null?_userAppService.GetUsersByCourse(ddCourses.Value).Where(u => !u.Id.Equals(CurrentUser.Id)).ToList() : new List <UserViewModel>(); users.AddRange(userList); List <Message> messages = StudentMessageViewModelFactory.CreateUserMessage(users, textMessage, CurrentUser); _messageAppService.AddMessages(messages); userList = new List <UserViewModel>(); }