コード例 #1
0
        public static async Task <PowerBotChat> AddOrUpdateChat(Message message)
        {
            //Check if messagetype is not private
            if (!(message.Chat.Type == ChatType.Supergroup || message.Chat.Type == ChatType.Supergroup))
            {
                return(null);
            }

            var chatFromDb = await GetChat(message.Chat.Id);

            // New Сhat
            if (chatFromDb == null)
            {
                var chat = new PowerBotChat
                {
                    Id       = message.Chat.Id,
                    Title    = message.Chat.Title,
                    ActiveAt = DateTime.UtcNow,
                };

                var chatEntity = await _dbContext.Chats.AddAsync(chat);

                chatFromDb = chatEntity.Entity;

                await LogsManager.CreateLog($"New Chat ({chatFromDb.Title})", LogLevel.Info);
            }
            // Update Сhat
            else
            {
                if (message.Chat.Type == ChatType.Group || message.Chat.Type == ChatType.Supergroup)
                {
                    chatFromDb.Title    = message.Chat.Title;
                    chatFromDb.ActiveAt = DateTime.UtcNow;
                }
                ;
            }

            await _dbContext.SaveChangesAsync();

            return(chatFromDb);
        }
コード例 #2
0
ファイル: UserManager.cs プロジェクト: awitwicki/PowerBot
        public static async Task <PowerbotUser> AddOrUpdateUser(User user)
        {
            var usr = await GetUser(user.Id);

            // New user
            if (usr == null)
            {
                PowerbotUser _user = new PowerbotUser
                {
                    Id         = user.Id,
                    ActiveAt   = DateTime.UtcNow,
                    UserAccess = UserAccess.User,
                    FirstName  = user.FirstName,
                    LastName   = user.LastName,
                    UserName   = user.Username
                };

                var usrEntity = await _dbContext.Users.AddAsync(_user);

                usr = usrEntity.Entity;

                await LogsManager.CreateLog($"New user ({_user.FullName})", LogLevel.Info);
            }
            // Update User
            else
            {
                usr.FirstName = user.FirstName;
                usr.LastName  = user.LastName;
                usr.UserName  = user.Username;
                usr.ActiveAt  = DateTime.UtcNow;
            }

            await _dbContext.SaveChangesAsync();

            return(usr);
        }