Example #1
0
        public async Task <ServiceResponse <int> > AddUserToDialogAsync(UserDialogAddDTO userDialogDTO)
        {
            ServiceResponse <int> serviceResponse = new ServiceResponse <int>();

            try
            {
                var dialog = await _dialogRepository.GetAsync(userDialogDTO.DialogId);

                if (dialog.IsTeteATete)
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = "Только два пользователя";
                    return(serviceResponse);
                }
                UserDialog userDialog = new UserDialog()
                {
                    DialogId = userDialogDTO.DialogId,
                    UserId   = userDialogDTO.UserId
                };
                _dialogRepository.AddUserToDialog(userDialog);
                await _context.SaveChangesAsync();

                _chatEventRepository.Add(new ChatEvent()
                {
                    UserId         = userDialogDTO.UserId,
                    DialogId       = userDialogDTO.DialogId,
                    TypeOfActionId = (int)ActionTypes.UserAdded
                });
                await _context.SaveChangesAsync();

                _botNotifier.NotifyAsync();

                serviceResponse.Data = userDialog.UserId;
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message + ex.InnerException;
                return(serviceResponse);
            }

            return(serviceResponse);
        }
Example #2
0
 public async Task <Dialog> GetDialogAsync(Expression <Func <Dialog, bool> > where, params Expression <Func <Dialog, object> >[] includes)
 {
     return(await dialogsRepository.GetAsync(where, includes));
 }