Beispiel #1
0
 private void buttonAddUser_Click(object sender, EventArgs e)
 {
     if (listBoxUsers.SelectedItem == null)
         return;
     UsersContest uc = new UsersContest();
     uc.UserId = ((User)listBoxUsers.SelectedItem).Id;
     uc.ContestId = this._contest.Id;
     using (var db = new DatabaseEntities())
     {
         db.UsersContests.Add(uc);
         db.SaveChanges();
     }
     ShowUsers();
 }
Beispiel #2
0
 private void buttonRemove_Click(object sender, EventArgs e)
 {
     if (listBoxUsers.SelectedItem == null)
     {
         MessageBox.Show("You need to select contest!");
         return;
     }
     DialogResult dialogResult = MessageBox.Show("Do you really want to delete current record?", "Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
     if (dialogResult == System.Windows.Forms.DialogResult.Yes)
     {
         using (var db = new DatabaseEntities())
         {
             User contest = (User)listBoxUsers.SelectedItem;
             var item = db.Users.FirstOrDefault(t => t.Id == contest.Id);
             if (item != null)
             {
                 db.Users.Remove(item);
                 db.SaveChanges();
             }
         }
     }
     ShowUsers();
 }
Beispiel #3
0
        private void buttonRemoveUser_Click(object sender, EventArgs e)
        {
            if (listBoxUsersInCompetition.SelectedItem == null)
                return;
            User user = (User)listBoxUsersInCompetition.SelectedItem;
            using (var db = new DatabaseEntities())
            {
                UsersContest uc = db.UsersContests.FirstOrDefault(t => t.ContestId == this._contest.Id && t.UserId == user.Id);
                if (uc != null)
                {
                    db.UsersContests.Remove(uc);
                    db.SaveChanges();
                }

            }
            ShowUsers();
        }