예제 #1
0
        public void UpdateUser(Tables.User user)
        {
            var existingUser = this.Users.FirstOrDefault(x => x.Id == user.Id);

            if (existingUser != null)
            {
                this.Entry(existingUser).State = EntityState.Detached;
                this.Entry(user).State         = EntityState.Modified;
            }
            this.SaveChanges();
        }
예제 #2
0
        public async Task UpsertUser(Tables.User user, long chatId)
        {
            var existingUser = this.Users.FirstOrDefault(x => x.Id == user.Id);

            if (existingUser != null)
            {
                this.Entry(existingUser).State = EntityState.Detached;
                this.Entry(user).State         = EntityState.Modified;
            }
            else
            {
                await this.Users.AddAsync(user);

                await this.ChatUsers.AddAsync(new Tables.ChatUser()
                {
                    ChatId = chatId,
                    UserId = user.Id
                });
            }
            await this.SaveChangesAsync();
        }