Example #1
0
        public async Task Unsubscribe(long chatId, string username)
        {
            var user = _dbContext.Users.Where(x => x.ChatId == chatId.ToString()).SingleOrDefault();

            if (user == null)
            {
                await Bot.Api.SendTextMessageAsync
                    (chatId, "Подписка не активна.");

                await _logger.LogAuth(LogConst.UnsubscribedUserSendBye, username);

                await _newLogger.LogByType(MessageTypes.Incoming, LogConst.UnsubscribedUserSendBye, username);

                return;
            }
            _dbContext.Users.Remove(user);
            await _dbContext.SaveChangesAsync();

            await Bot.Api.SendTextMessageAsync
                (chatId,
                _configService.Config.UserUnsubscribed);

            await _logger.LogAuth(LogConst.Unsubscribe, _phoneHelper.Format(user.PhoneNumber));

            await _newLogger.LogByType(MessageTypes.Auth, LogConst.Unsubscribe, user.PhoneNumber);
        }
Example #2
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                var user = _dbContext.Users.SingleOrDefault(x => x.Id == id);
                if (user == null)
                {
                    return(NotFound());
                }
                _dbContext.Users.Remove(user);
                await _dbContext.SaveChangesAsync();

                return(NoContent());
            }
            catch (Exception err)
            {
                return(BadRequest(err.Message));
            }
        }