Ejemplo n.º 1
0
        public async Task <BasicOutput <ChatRoom> > CreateChatRoom(string chatRoomName)
        {
            var result = new BasicOutput <ChatRoom>();

            if (string.IsNullOrWhiteSpace(chatRoomName))
            {
                result.AddNotification(new Notification("Chat name should not be empty", ENotificationType.Error, "chatRoomName"));
            }

            if (result.Invalid)
            {
                return(result);
            }

            var chatRoom = new ChatRoom(chatRoomName);

            if (chatRoom.Invalid)
            {
                result.AddNotifications(chatRoom.ValidationResult);
                return(result);
            }

            await _chatRoomRepository.Create(chatRoom);

            await _unitOfWork.CommitAsync();

            result.SetOutput(chatRoom);
            return(result);
        }
Ejemplo n.º 2
0
        public void CreateChatRoom(IEnumerable <string> usersId)
        {
            var chatRoom  = new ChatRoom();
            var roomTitle = new StringBuilder();

            foreach (var id in usersId)
            {
                var user = _userManager.FindById(id);
                if (user == null)
                {
                    throw new ObjectNotFoundException($"User with id={id} not found");
                }

                roomTitle.Append($" - {user.UserName}");
                chatRoom.Users.Add(user);
            }

            chatRoom.Title = roomTitle.ToString();
            _chatRoomRepository.Create(chatRoom);
        }