protected override void HandlerUserButtonOk_Click(object sender, EventArgs e) { Log.Debug(TAG, "HandlerUserButtonOk_Click"); string errMsg = ReadView(userId); if (!string.IsNullOrWhiteSpace(errMsg)) { UserCardSubHeader.Text = errMsg; UserCardSubHeader.SetTextColor(Color.Red); Toast.MakeText(this, errMsg, ToastLength.Short).Show(); return; } int selected_telegram_id = TelegramUsers.Keys.ToList()[TelegramAccount.SelectedItemPosition]; lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { UserModel user = db.Users.Find(userId); user.Name = UserName.Text.Trim(); user.Email = UserEmail.Text.Trim(); user.Phone = UserPhone.Text.Trim(); user.AlarmSubscriber = UserAlarmSubscribing.Checked; user.CommandsAllowed = UserCommandsAllowed.Checked; db.Users.Update(user); if (selected_telegram_id > 0) { TelegramUserModel telegramUser = db.TelegramUsers.Find(selected_telegram_id); telegramUser.LinkedUserId = user.Id; List <TelegramUserModel> other_telegram_users = db.TelegramUsers.Where(x => x.LinkedUserId == user.Id && x.Id == selected_telegram_id).ToList(); if (other_telegram_users != null && other_telegram_users.Count > 0) { other_telegram_users.ForEach(x => { x.LinkedUserId = null; }); } } else { TelegramUserModel telegramUser = db.TelegramUsers.FirstOrDefault(x => x.LinkedUserId == userId); if (telegramUser != null) { telegramUser.LinkedUserId = null; } } db.SaveChanges(); } } StartActivity(typeof(UsersListActivity)); }
private void ButtonDeleteUser_Click(object sender, EventArgs e) { Log.Debug(TAG, "ButtonDeleteUser_Click"); AppCompatButton buttonDeleteUser = sender as AppCompatButton; buttonDeleteUser.Enabled = false; UserCardButtonOk.Enabled = false; UserCardButtonOk.Text = GetText(Resource.String.ok_mute_button_with_remove_user); UserName.Enabled = false; UserEmail.Enabled = false; UserPhone.Enabled = false; UserAlarmSubscribing.Enabled = false; UserCommandsAllowed.Enabled = false; UserCardSubHeader.Text = GetText(Resource.String.delete_user_card_sub_title); UserCardHeader.Text = GetText(Resource.String.delete_user_card_header); UserCardSubHeader.SetTextColor(Color.IndianRed); buttonDeleteUser.SetTextColor(Color.Gray); AppCompatTextView appCompatTextView = new AppCompatTextView(this) { Text = GetText(Resource.String.footer_text_with_remove_user), TextSize = 15 }; appCompatTextView.SetTextColor(Color.Red); appCompatTextView.SetWidth(3); UserFooterLayout.AddView(appCompatTextView); AppCompatButton buttonConfirmDeleteUser = new AppCompatButton(this) { Text = GetText(Resource.String.button_confirm_remove) }; buttonConfirmDeleteUser.SetTextColor(Color.DarkRed); buttonConfirmDeleteUser.Click += new EventHandler((sender, eventArg) => { lock (DatabaseContext.DbLocker) { using (DatabaseContext db = new DatabaseContext(gs.DatabasePathBase)) { UserModel user = db.Users.Find(userId); db.Users.Remove(user); db.SaveChanges(); StartActivity(typeof(UsersListActivity)); } } }); buttonConfirmDeleteUser.LayoutParameters = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent); UserFooterLayout.AddView(buttonConfirmDeleteUser); }