Exemple #1
0
        public async Task Start(CommandArgs args)
        {
            var id = args.SentFromChatULong();

            if (await _chatRepository.Exists(id))
            {
                return;
            }

            var offset = args.ValueContainer.Get <TimeSpan>(0);

            var vkUser = new VkUser()
            {
                Id = args.SentFromUserULong()
            };
            var admin = new VkChatAdmin()
            {
                IsSuperAdmin = true,
                VkUser       = vkUser
            };
            var chat = new VkChat()
            {
                Id         = id,
                TimeOffset = offset,
                Admins     = new List <VkChatAdmin>()
                {
                    admin
                }
            };

            await _chatRepository.AddChat(chat);

            _api.Messages.SendTo(args.SourceMessage, "Поздравляем, вы успешно используете бота!");
        }
Exemple #2
0
        public ActionResult AddChat(int id, Bericht bericht)
        {
            Account account = (Account)Session["loggedIn_Account"];

            Contact contact = new Contact
            {
                ContactAccountID = id
            };

            bericht = new Bericht
            {
                ChatBericht   = bericht.ChatBericht,
                OntvangerID   = contact.ContactAccountID,
                VerstuurderID = account.ID,
                DatumTijd     = DateTime.Now
            };

            if (ModelState.IsValid)
            {
                chatRepository.AddChat(bericht);
                return(RedirectToAction("Index", "Contact"));
            }
            else
            {
                ModelState.AddModelError("error", "Er is iets misgegaan..");
            }

            return(View(bericht));
        }
 public void CreateChat(Guid userId, IChat chat)
 {
     if (!userRepa.Contains(userId))
     {
         throw new Exception("User is not registered");
     }
     chatRepa.AddChat(chat);
 }
Exemple #4
0
 public async Task AddChat(int contactUserFriendId, int contactFriendUserId)
 {
     await _chatRepository.AddChat(new Chat
     {
         ContactFriendUserId = contactFriendUserId,
         ContactUserFriendId = contactUserFriendId
     });
 }
Exemple #5
0
        public override IChat CreateChat(ChatType chatType, List <IUser> firstChatUsers, String chatName)
        {
            if (firstChatUsers.Count == 1)
            {
                IChat groupChat = new GroupChat(firstChatUsers[0], chatName);

                _chatRepository.AddChat(groupChat);
                return(groupChat);
            }

            throw new InvalidDataException("The group has to be created by the only one user!");
        }
        public override IChat CreateChat(ChatType chatType, List <IUser> firstChatUsers, String chatName)
        {
            if (firstChatUsers.Count == 1)
            {
                IChat channelChat = new ChannelChat(firstChatUsers[0], chatName);

                _chatRepository.AddChat(channelChat);
                return(channelChat);
            }

            throw new InvalidDataException("The channel can only have one creator!");
        }
        public override IChat CreateChat(ChatType chatType, List <IUser> firstChatUsers, String chatName)
        {
            if (firstChatUsers.Count == 2)
            {
                IChat privateChat = new PrivateChat(firstChatUsers[0],
                                                    firstChatUsers[1],
                                                    chatName);

                _chatRepository.AddChat(privateChat);
                return(privateChat);
            }

            throw new InvalidDataException("The private chat has to be created with two users!");
        }
Exemple #8
0
        public ChatModel CreateChat(User creator, string title)
        {
            var chatCreator = new ChatMember {
                User = creator, MemberType = MemberType.Admin
            };
            var members = new List <ChatMember>
            {
                chatCreator
            };
            var chat = new Chat {
                Title = title, Members = members
            };

            _repository.AddChat(chat);
            return(ChatToModel(chat));
        }
        public Chat CreateChat(string chatName)
        {
            if (chatName.Length > 50 || string.IsNullOrWhiteSpace(chatName))
            {
                throw new ChatNameInvalidException(chatName);
            }

            var chats = _chatRepo.GetChats();

            if (chats.Any(c => c.Name.ToLower() == chatName.ToLower()))
            {
                throw new ChatExistsException(chatName);
            }

            var newChat = new Chat(chatName);

            _chatRepo.AddChat(newChat);
            return(newChat);
        }
Exemple #10
0
        public IActionResult AddChat([FromBody] string name)
        {
            string token = User.FindFirst("token").Value;
            User   user  = Users.FindByToken(token);

            if (user == null)
            {
                return(Unauthorized());
            }

            var chat = Chats.AddChat(new Chat
            {
                UserID = user.ID,
                Name   = name
            });

            return(Json(new
            {
                success = true,
                data = chat
            }));
        }
Exemple #11
0
        public async Task AddMessage(int id, [FromBody] AddMessageViewModel model)
        {
            var userId = int.Parse(User.GetName());
            var chat   = await _chatRepository.GetChat(userId, id);

            var message = _mapper.Map <Message>(model);

            if (chat == null)
            {
                chat = new Chat
                {
                    IdSource = userId,
                    IdTarget = id
                };
                await _chatRepository.AddChat(chat);
            }

            message.IdSender = userId;
            message.IdChat   = chat.Id;
            message.Time     = DateTime.Now;
            await _messageRepository.AddMessage(message);
        }
Exemple #12
0
        public ActionResult Add(AddChatModel model)
        {
            Account account = GetAccount();

            model.Contacts = contactRepository.GetAllContactsForAccount(account.AccountId);

            if (ModelState.IsValid)                 // Check for model errors
            {
                if (model.SelectedContact.HasValue) // Check if the selected contact has an account (otherwise you can't chat)
                {
                    int receiverId = (int)model.SelectedContact;
                    int senderId   = account.AccountId;

                    if (!chatRepository.CheckForDuplicateChats(receiverId, senderId)) // Check if the chat doesn't exist yet (no duplicate chats)
                    {
                        Chat chat = new Chat();
                        chat.ReceiverId = receiverId;
                        chat.SenderId   = senderId;

                        chatRepository.AddChat(chat);                               // Add chat to DB
                        chatLogic.AddMessage(model.InitialMessage, senderId, chat); // Add initial message

                        return(RedirectToAction("ViewChat", "Chat", new { chatId = chat.ChatId }));
                    }
                    else
                    {
                        ModelState.AddModelError("", "You already have a chat with this contact. Try chatting in your existing chatroom.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The selected contact doesn't have an account yet. Try another contact!");
                }
            }
            return(View(model));
        }
        public IActionResult CreateChat([FromBody] Chat chat)
        {
            _repository.AddChat(chat);

            return(Ok(chat.Id));
        }