Пример #1
0
        public async Task <object> AddMessageGroup(int roomid, string message)
        {
            try
            {
                var project = await _projectRepository.FindAll().FirstOrDefaultAsync(x => x.Room.Equals(roomid));

                var managers = await _manageRepository.FindAll().Where(x => x.ProjectID.Equals(project.ID)).Select(x => x.UserID).ToListAsync();

                var members = await _teamMemberRepository.FindAll().Where(x => x.ProjectID.Equals(project.ID)).Select(x => x.UserID).ToListAsync();

                var listAll          = managers.Union(members);
                var listChats        = new List <Chat>();
                var listParticipants = new List <Participant>();
                foreach (var user in listAll)
                {
                    listChats.Add(new Chat
                    {
                        Message   = message,
                        UserID    = user,
                        ProjectID = project.ID,
                        RoomID    = roomid
                    });
                    listParticipants.Add(new Participant
                    {
                        UserID = user,
                        RoomID = roomid
                    });
                }
                await _participantRepository.AddMultipleAsync(listParticipants);

                await _chatRepository.AddMultipleAsync(listChats);

                await _unitOfWork.Commit();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);

                throw;
            }
            throw new NotImplementedException();
        }