示例#1
0
        public static bool addScoutToMeeting(int meetingID, int scoutID)
        {
            bool scoutAdded = true;

            using (var ctx = new SALAHContext())
            {
                meeting meetingQuery = new meeting();
                try
                {
                    bool scoutAlreadyAdded = false;

                    meetingQuery = ctx.Meetings.FirstOrDefault(m => m.meetingID == meetingID);
                    if (meetingQuery.scoutsThatAttended != null)
                    {
                        string[] scoutsThatAttended = meetingQuery.scoutsThatAttended.Split(',');

                        foreach (string s in scoutsThatAttended)
                        {
                            if (s == scoutID.ToString())
                            {
                                scoutAlreadyAdded = true;
                            }
                        }

                        if (scoutAlreadyAdded == false)
                        {
                            meetingQuery.scoutsThatAttended += scoutID + ",";
                            meetingQuery.attendance++;
                            ctx.SaveChanges();
                            ctx.Dispose();
                            scoutAdded = true;
                        }
                        return(scoutAdded);
                    }
                    else if (meetingQuery.scoutsThatAttended == null)
                    {
                        meetingQuery.scoutsThatAttended += scoutID + ",";
                        meetingQuery.attendance++;
                        ctx.SaveChanges();
                        ctx.Dispose();
                        scoutAdded = true;
                    }
                }
                catch
                {
                    scoutAdded = false;
                    return(scoutAdded);
                }
            }
            return(scoutAdded);
        }
示例#2
0
        public static bool changeLocationsGroup(location location, group oldGroup, group newGroup, bool moveGroup)
        {
            bool   locationMoved    = true;
            string locationIDString = location.locationID.ToString();

            try
            {
                if (moveGroup == true)
                {
                    using (var ctx = new SALAHContext())
                    {
                        oldGroup             = ctx.Groups.FirstOrDefault(g => g.location_ID == locationIDString);
                        oldGroup.location_ID = null;
                        newGroup             = ctx.Groups.FirstOrDefault(g => g.groupID == newGroup.groupID);
                        newGroup.location_ID = location.locationID.ToString();
                        locationMoved        = true;
                        ctx.SaveChanges();
                        ctx.Dispose();
                        return(locationMoved);
                    }
                }
                return(locationMoved);
            }
            catch
            {
                locationMoved = false;
                return(locationMoved);
            }
        }
示例#3
0
        public static bool RemoveLocationFromGroup(location location)
        {
            bool   locationRemoved  = true;
            group  group            = new group();
            string locationIDString = location.locationID.ToString();

            try
            {
                using (var ctx = new SALAHContext())
                {
                    var result = ctx.Groups.SingleOrDefault(g => g.location_ID == locationIDString);
                    if (result != null)
                    {
                        group = result;
                    }
                    group.location_ID = null;

                    ctx.SaveChanges();
                    ctx.Dispose();
                    locationRemoved = true;
                    return(locationRemoved);
                }
            }
            catch
            {
                locationRemoved = false;
                return(locationRemoved);
            }
        }
示例#4
0
        public static bool deleteGroup(int groupID, user currentUser)
        {
            bool  groupDeleted = false;
            group groupQuery   = new group();

            using (var ctx = new SALAHContext())
            {
                try
                {
                    groupQuery = ctx.Groups.FirstOrDefault(m => m.groupID == groupID);
                    ctx.Groups.Remove(groupQuery);
                    ctx.SaveChanges();
                    ctx.Dispose();
                    if (user.groupRemovedFromUser(groupID, currentUser))
                    {
                        groupDeleted = true;
                    }
                }
                catch
                {
                    groupDeleted = false;
                }
            }
            return(groupDeleted);
        }
示例#5
0
        public static bool ChangeLocationOfResource(int resourceId, int oldLocationId, int newLocationId, bool moveResource)
        {
            bool     resourceMoved    = true;
            string   resourceIdString = resourceId.ToString();
            location oldLocation      = new location();
            location newLocation      = new location();
            resource resource         = new resource();

            try
            {
                if (moveResource == true)
                {
                    using (var ctx = new SALAHContext())
                    {
                        oldLocation = ctx.Locations.FirstOrDefault(l => l.locationID == oldLocationId);
                        resource    = ctx.Resources.FirstOrDefault(r => r.resourceID == resourceId);
                        location.RemoveResourceFromLocation(oldLocation, resource);
                        location.addResourceToLocation(newLocationId, resourceId);
                        resourceMoved = true;
                        ctx.SaveChanges();
                        ctx.Dispose();
                        return(resourceMoved);
                    }
                }
                return(resourceMoved);
            }
            catch
            {
                resourceMoved = false;
                return(resourceMoved);
            }
        }
示例#6
0
        public static bool DeleteLocation(location location, group group)
        {
            bool     locationDeleted = false;
            location locationQuery   = new location();
            int      locationIDint   = location.locationID;

            using (var ctx = new SALAHContext())
            {
                try
                {
                    locationQuery = ctx.Locations.FirstOrDefault(l => l.locationID == locationIDint);
                    ctx.Locations.Remove(locationQuery);
                    ctx.SaveChanges();
                    ctx.Dispose();
                    if (group.RemoveLocationFromGroup(location))
                    {
                        locationDeleted = true;
                    }
                }
                catch
                {
                    locationDeleted = false;
                }
            }
            return(locationDeleted);
        }
示例#7
0
        public static bool RemoveResourceFromLocation(location location, resource resourceToRemove)
        {
            bool     resourceRemoved = false;
            location currentLocation;

            string[] resourceIDsArray = location.resourceIDs.Split(',');

            int count = 0;

            foreach (string s in resourceIDsArray)
            {
                if (s != null && s != "")
                {
                    count++;
                }
            }
            string[] resourceIDs = new string[count];
            int      i           = 0;

            foreach (string s in resourceIDsArray)
            {
                if (s != null && s != "")
                {
                    resourceIDs[i] = s;
                    i++;
                }
            }

            string locationIDString = location.locationID.ToString();

            try
            {
                using (var ctx = new SALAHContext())
                {
                    currentLocation             = ctx.Locations.FirstOrDefault(l => l.locationID == location.locationID);
                    currentLocation.resourceIDs = "";
                    foreach (string s in resourceIDs)
                    {
                        if (s != resourceToRemove.resourceID.ToString())
                        {
                            currentLocation.resourceIDs += s + ",";
                        }
                    }

                    ctx.SaveChanges();
                    resourceRemoved = true;
                    ctx.Dispose();
                    return(resourceRemoved);
                }
            }
            catch
            {
                resourceRemoved = false;
                return(resourceRemoved);
            }
        }
示例#8
0
        public static bool RemoveMeetingFromGroup(group group, meeting meeting)
        {
            bool meetingRemovedFromGroup = false;

            using (var ctx = new SALAHContext())
            {
                try
                {
                    var result = ctx.Groups.SingleOrDefault(g => g.group_name == group.group_name);
                    if (result != null)
                    {
                        group = result;
                    }

                    string[] oldGroupMeetings = group.meetingIDs.Split(',');

                    for (int i = 0; i < oldGroupMeetings.Length; i++)
                    {
                        if (oldGroupMeetings[i] == meeting.meetingID.ToString())
                        {
                            var result1 = ctx.Groups.SingleOrDefault(g => g.group_name == group.group_name);
                            if (result1 != null)
                            {
                                result1.meetingIDs = "";

                                for (int j = 0; j < oldGroupMeetings.Length - 1; j++)
                                {
                                    if (i != j)
                                    {
                                        result1.meetingIDs += oldGroupMeetings[j] + ",";
                                    }
                                }
                            }
                        }
                    }
                    meetingRemovedFromGroup = true;
                    ctx.SaveChanges();
                    ctx.Dispose();
                }
                catch
                {
                    meetingRemovedFromGroup = false;
                }
            }
            return(meetingRemovedFromGroup);
        }
示例#9
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;
        }
示例#10
0
        /// <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();
                }
            }
        }
示例#11
0
        public static bool DeleteResource(int resourceID)
        {
            bool     resourceDeleted = false;
            resource resourceQuery   = new resource();

            using (var ctx = new SALAHContext())
            {
                try
                {
                    resourceQuery = ctx.Resources.FirstOrDefault(r => r.resourceID == resourceID);
                    ctx.Resources.Remove(resourceQuery);
                    ctx.SaveChanges();
                    ctx.Dispose();
                    resourceDeleted = true;
                }
                catch
                {
                    resourceDeleted = false;
                }
            }
            return(resourceDeleted);
        }
示例#12
0
        public static bool deleteMeeting(int meetingID)
        {
            bool    meetingDeleted = false;
            meeting meetingQuery   = new meeting();

            using (var ctx = new SALAHContext())
            {
                try
                {
                    meetingQuery = ctx.Meetings.FirstOrDefault(m => m.meetingID == meetingID);
                    ctx.Meetings.Remove(meetingQuery);
                    ctx.SaveChanges();
                    ctx.Dispose();
                    meetingDeleted = true;
                }
                catch
                {
                    meetingDeleted = false;
                }
            }
            return(meetingDeleted);
        }
示例#13
0
        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);
        }
示例#14
0
        private void saveChangesBtn_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)

            {

                if (newGroup.group_name == currentGroup.group_name)
                    moveGroup = false;

                group.changeGroupMeeting(currentGroup, newGroup, currentMeeting, moveGroup);

                int meetingId = currentMeeting.meetingID;

                using (var ctx = new SALAHContext())
                {
                    var result = ctx.Meetings.SingleOrDefault(m => m.meetingID == meetingId);
                    if (result != null)
                    {
                        result.meetingTitle = meetingTitleTxtBx.Text;
                        result.meetingDesc = meetingDescTxtBx.Text;
                        result.Location = meetingPlaceTxtBx.Text;
                        result.DateTime = meetingDatePicker.Value.ToString();
                    }

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

                main_screen open_screen = new main_screen(currentUser);
                this.Close();
                open_screen.Show();

            }
            return;
        }
示例#15
0
        public static bool deleteScout(int scoutID)
        {
            bool  scoutDeleted = false;
            scout scoutQuery   = new scout();

            using (var ctx = new SALAHContext())
            {
                try
                {
                    scoutQuery = ctx.Scouts.FirstOrDefault(m => m.scoutID == scoutID);
                    ctx.Scouts.Remove(scoutQuery);
                    ctx.SaveChanges();
                    ctx.Dispose();
                    //if (group.RemoveUserFromGroup())
                    scoutDeleted = true;
                }
                catch
                {
                    scoutDeleted = false;
                }
            }
            return(scoutDeleted);
        }
        private void saveBtn_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)
            {
                if (newGroup.group_name == currentGroup.group_name || newGroup.group_name == null)
                {
                    moveGroup = false;
                }

                location.changeLocationsGroup(currentLocation, currentGroup, newGroup, moveGroup);

                int locationId = currentLocation.locationID;

                using (var ctx = new SALAHContext())
                {
                    var result = ctx.Locations.SingleOrDefault(l => l.locationID == locationId);
                    if (result != null)
                    {
                        result.locationName = locationNameTxtBx.Text;
                        result.venueNotes   = venueNotesTxtBx.Text;
                        result.Address      = CreateAddress();
                    }

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

                main_screen open_screen = new main_screen(currentUser);
                this.Close();
                open_screen.Show();
            }
        }
        private void saveBtn_Click(object sender, EventArgs e)
        {
            var confirmResult = MessageBox.Show("Are you sure you want to save your changes to this resource?",
                                                "Save Changes",
                                                MessageBoxButtons.YesNo);

            if (confirmResult == DialogResult.Yes)
            {
                if (newLocation.locationID == currentLocation.locationID)
                {
                    moveLocation = false;
                }

                resource.ChangeLocationOfResource(currentResource.resourceID, currentLocation.locationID, newLocation.locationID, moveLocation);

                int resourceId = currentResource.resourceID;

                using (var ctx = new SALAHContext())
                {
                    var result = ctx.Resources.SingleOrDefault(r => r.resourceID == resourceId);
                    if (result != null)
                    {
                        result.name     = resourceNameTxtBx.Text;
                        result.notes    = resourceNotesTxtBx.Text;
                        result.quantity = int.Parse(quantityUpDown.Text);
                    }

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

                main_screen open_screen = new main_screen(currentUser);
                this.Close();
                open_screen.Show();
            }
        }