Example #1
0
        private void editGroupBtn_Click(object sender, EventArgs e)
        {
            var confirmResult = MessageBox.Show("Are you sure you want to save your changes?",
                                                "Save changes",
                                                MessageBoxButtons.YesNo);

            if (confirmResult == DialogResult.Yes)
            {
                int groupId = groupToBeEdited.groupID;

                using (var ctx = new SALAHContext())
                {
                    var result = ctx.Groups.SingleOrDefault(g => g.groupID == groupId);
                    if (result != null)
                    {
                        result.group_name = groupNameTxtbx.Text;
                        bool locationExists = location.checkLocationExists(meetingPlaceTxtBx.Text);
                        if (locationExists == true)
                        {
                            location location = location.getLocationWName(meetingPlaceTxtBx.Text);
                            group.changeLocationOfGroup(groupId, location.locationID);
                            string locationIDString = location.locationID.ToString();
                            result.location_ID = locationIDString;
                        }
                        else
                        {
                            location location = new location(meetingPlaceTxtBx.Text);
                            location.addLocation(location);
                            group.changeLocationOfGroup(groupId, location.locationID);
                        }

                        result.group_type = ageGroupCBox.SelectedItem.ToString();
                    }

                    ctx.SaveChanges();
                    ctx.Dispose();
                }

                main_screen open_screen = new main_screen(currentUser);
                this.Close();
                open_screen.Show();
            }
            return;
        }
Example #2
0
        private void addNewGroupBtn_Click(object sender, EventArgs e)
        {
            name           = groupNameTxtbx.Text;
            meetingplace   = meetingPlaceTxtBx.Text;
            type           = ageGroupCBox.Text;
            groupNameValid = true;
            foreach (string s in group.getGroupNames(user))
            {
                if (name == s)
                {
                    MessageBox.Show("This group name is already taken.");
                    groupNameValid = false;
                    break;
                }
            }
            if (groupNameValid)
            {
                location location = new location(meetingplace);
                location.addLocation(location);
                string locationIDString = location.locationID.ToString();
                group  newGroup         = new group(name, locationIDString, type);
                bool   userAdded        = group.AddNewGroup(newGroup, user);

                if (userAdded)
                {
                    MessageBox.Show("Group was successfully added.");
                    main_screen open_screen = new main_screen(user);
                    this.Close();
                    open_screen.Show();
                }
                if (!userAdded)
                {
                    MessageBox.Show("Group was not added. Please try again.");
                }
            }
        }