public static int getGroupID(string groupName) { group groupQuery = new group(); int groupId = 0; try { using (var ctx = new SALAHContext()) { groupQuery = ctx.Groups.FirstOrDefault(m => m.group_name == groupName); groupId = groupQuery.groupID; } } catch (Exception e) { MessageBox.Show("Group could not be found."); } return(groupId); }
/// <summary> /// change which group the scout belongs to /// </summary> /// <param name="oldGroup">group the scout currently belongs to</param> /// <param name="newGroup">group the scout is going to belong to</param> /// <param name="scout">the scout to be moved</param> /// <param name="moveGroup">if the scout needs to be moved</param> public static void changeGroupMeeting(group oldGroup, group newGroup, meeting meeting, bool moveGroup) { if (moveGroup == true) { using (var ctx = new SALAHContext()) { var result = ctx.Groups.SingleOrDefault(g => g.groupID == newGroup.groupID); if (result != null) { newGroup = result; } string[] oldGroupMeetings = oldGroup.meetingIDs.Split(','); for (int i = 0; i < oldGroupMeetings.Length; i++) { if (oldGroupMeetings[i] == meeting.meetingID.ToString()) { var result1 = ctx.Groups.SingleOrDefault(g => g.groupID == oldGroup.groupID); if (result1 != null) { result1.meetingIDs = ""; for (int j = 0; j < oldGroupMeetings.Length - 1; j++) { if (i != j) { result1.meetingIDs += oldGroupMeetings[j] + ","; } } } } } group.addMeetingToGroup(newGroup.groupID, meeting.meetingID); ctx.SaveChanges(); ctx.Dispose(); } } }
public void SetUpForm(user user, location location, group group) { currentUser = user; currentLocation = location; currentGroup = group; currentAddress = location.Address; if (currentAddress != null) { houseNumbTxtBx.Text = currentAddress.houseNumberOrName; streetTxtBx.Text = currentAddress.street; cityTxtBx.Text = currentAddress.city; countyTxtBx.Text = currentAddress.county; countryTxtBx.Text = currentAddress.country; postcodeTxtBx.Text = currentAddress.postcode; } titleLbl.Text += currentLocation.locationName; chooseGroupLocationComboBox.Text = currentGroup.group_name; locationNameTxtBx.Text = currentLocation.locationName; venueNotesTxtBx.Text = currentLocation.venueNotes; newGroup = new group(); updateComboBox(chooseGroupLocationComboBox); }
/// <summary> /// Add a scout to a group /// </summary> /// <param name="groupName">name of the group</param> /// <param name="newScoutID">id of the new scout</param> /// <returns></returns> public static bool addScoutToGroup(int groupID, int newScoutID) { bool scoutAdded = false; try { using (var ctx = new SALAHContext()) { group groupQuery = ctx.Groups.FirstOrDefault(g => g.groupID == groupID); if (groupQuery.scoutID != null) { string[] groupsScouts = groupQuery.scoutID.Split(','); groupQuery.scoutID = ""; foreach (string s in groupsScouts) { if (s != "" && s != null) { groupQuery.scoutID = groupQuery.scoutID + s + ","; } } groupQuery.scoutID += newScoutID + ","; } if (groupQuery.scoutID == null) { groupQuery.scoutID = newScoutID + ","; } ctx.SaveChanges(); scoutAdded = true; } } catch { scoutAdded = false; } return(scoutAdded); }
public static bool deleteGroup(string groupname) { bool groupDeleted = false; group groupQuery = new group(); using (var ctx = new SALAHContext()) { try { groupQuery = ctx.Groups.FirstOrDefault(m => m.group_name == groupname); ctx.Groups.Remove(groupQuery); ctx.SaveChanges(); ctx.Dispose(); groupDeleted = true; } catch { groupDeleted = false; } } return(groupDeleted); }
public static bool addMeetingToGroup(int groupID, int newMeetingID) { bool meetingAdded = false; try { using (var ctx = new SALAHContext()) { group groupQuery = ctx.Groups.FirstOrDefault(g => g.groupID == groupID); if (groupQuery.meetingIDs != null) { string[] groupsMeetings = groupQuery.meetingIDs.Split(','); groupQuery.meetingIDs = ""; foreach (string s in groupsMeetings) { if (s != "" && s != null) { groupQuery.meetingIDs = groupQuery.meetingIDs + s + ","; } } groupQuery.meetingIDs += newMeetingID + ","; } if (groupQuery.meetingIDs == null) { groupQuery.meetingIDs = newMeetingID + ","; } ctx.SaveChanges(); meetingAdded = true; } } catch { meetingAdded = false; } return(meetingAdded); }
private void SetUpForm(user user, meeting meeting, group group) { currentUser = user; currentGroup = group; newGroup = new group(); currentMeeting = meeting; titleLbl.Text += meeting.meetingTitle; meetingTitleTxtBx.Text = meeting.meetingTitle; meetingDescTxtBx.Text = meeting.meetingDesc; meetingPlaceTxtBx.Text = meeting.Location; try { meetingDatePicker.Value = DateTime.Parse(meeting.DateTime); } catch { MessageBox.Show("No date was set for this meeting. Please set one before saving."); } updateComboBox(); chooseGroupMeetingComboBox.Text = group.group_name; }
public static string getGroupLocation(string groupId) { string groupLocation; try { int intGroupId = int.Parse(groupId); group groupQuery = new group(); using (var ctx = new SALAHContext()) { groupQuery = ctx.Groups.FirstOrDefault(m => m.groupID == intGroupId); groupLocation = location.getLocationWId(groupQuery.location_ID).locationName; return(groupLocation); } } catch (Exception e) { groupLocation = null; return(groupLocation); } }
public static string[] getGroupNames(user user) { string[] userGroups = user.groupIDs.Split(','); string[] existingGroupNames = new string[userGroups.Length - 1]; int i = 0; try { using (var ctx = new SALAHContext()) { foreach (string s in userGroups) { int groupID; if (s != "") { groupID = int.Parse(s); group groupNamesQuery = ctx.Groups.FirstOrDefault(g => g.groupID == groupID); if (groupNamesQuery != null) { existingGroupNames[i] = groupNamesQuery.group_name; i++; } if (groupNamesQuery == null) { user.groupRemovedFromUser(groupID, user); } } } } } catch (Exception e) { MessageBox.Show("New group could not be created. Please try again with a different group name"); } return(existingGroupNames); }
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."); } } }
public editLocation(user user, location location, group group) { InitializeComponent(); SetUpForm(user, location, group); }
public editGroup(group group, user user) { InitializeComponent(); groupToBeEdited = group; SetUpForm(groupToBeEdited, user); }
public editMeeting(user user, group group, meeting meeting) { InitializeComponent(); SetUpForm(user, meeting, group); }