Example #1
0
        public async Task CreateDialogue(int id, string token, int idUser)
        {
            if (!await _usersService.IsUserAuth(id, token))
            {
                throw new Exception("Authentication error");
            }
            if (!await _usersService.IsUser(id))
            {
                throw new Exception("Error! No user with such id");
            }

            _unitOfWork.Repository <Dialogue>().Add(new Dialogue
            {
                Created      = DateTime.Now,
                UserIdFirst  = id,
                UserIdSecond = idUser
            });
            await _unitOfWork.SaveChangesAsync();
        }
 public async Task SendMessage(int id, string token, int idDial, string data)
 {
     if (!await _usersService.IsUserAuth(id, token))
     {
         throw new Exception("Authentication error");
     }
     if (!await _dialoguesService.IsDialogue(idDial))
     {
         throw new Exception("Error! No dialogue with such id");
     }
     _unitOfWork.Repository <Message>().Add(new Message
     {
         Data       = data,
         DialogueId = idDial,
         MsgTime    = DateTime.Now,
         UserIdFrom = id
     });
     await _unitOfWork.SaveChangesAsync();
 }