Ejemplo n.º 1
0
        /// <summary>
        /// Displays the matched up assignment details to the current (non-admin) user
        /// </summary>
        /// <param name="currentUsername">
        /// The current username.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public static List <Assignments> DisplayCurrentUserAssignment(string currentUsername)
        {
            var assignments = new List <Assignments>();
            var memberData  = new MemberDataOperations();
            var giftData    = new GiftDataOperations();
            var filter      = new Filter <Member>();

            filter.Add(mem => mem.MemberUserName, currentUsername);
            Member      assignee       = new MemberDataOperations().Find(filter).ToList()[0];
            Assignments assignment     = new AssignmentDataOperations().GetById(assignee.MemberId);
            Member      assignedMember = memberData.GetById(assignment.AssignedMemberId);

            assignment.Membername     = assignee.MemberName;
            assignment.AssignedMember = assignedMember.MemberName;
            if (assignment.AssignedGiftId != 0)
            {
                Gift gift = giftData.GetById(assignment.AssignedGiftId);
                assignment.GiftName        = gift.GiftName;
                assignment.GiftPrice       = gift.GiftPrice;
                assignment.GiftDescription = gift.GiftDescription;
            }

            if (assignment.MemberId != 0)
            {
                assignments.Add(assignment);
            }

            return(assignments);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all users matched based on their username
        /// </summary>
        /// <param name="username">
        /// The username.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        private static List <Member> GetUsernamesFromDatabase(string username)
        {
            var filter = new Filter <Member>();

            filter.Add(member => member.MemberUserName, username);

            List <Member> members = new MemberDataOperations().Find(filter).ToList();

            return(members);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets an editable member collection
        /// </summary>
        /// <returns>
        /// The <see cref="ObservableCollection"/>.
        /// </returns>
        public static ObservableCollection <Member> ListAllMembers()
        {
            var           observableMembers = new MemberUIObjects();
            List <Member> members           = new MemberDataOperations().GetAll().ToList();

            foreach (Member member in members)
            {
                observableMembers.Add(member);
            }

            observableMembers.ItemEndEdit       += MembersItemEndEdit;
            observableMembers.CollectionChanged += MembersCollectionChanged;
            return(observableMembers);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Matches up the details from the assignments tables to names and prices from members and gifts
        /// </summary>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public static List <Assignments> DisplayAssignments()
        {
            List <Assignments> assignments = new AssignmentDataOperations().GetAll().ToList();
            var memberData = new MemberDataOperations();
            var giftData   = new GiftDataOperations();

            foreach (Assignments assignment in assignments)
            {
                Member assignee       = memberData.GetById(assignment.MemberId);
                Member assignedMember = memberData.GetById(assignment.AssignedMemberId);
                assignment.Membername     = assignee.MemberName;
                assignment.AssignedMember = assignedMember.MemberName;
                if (assignment.AssignedGiftId != 0)
                {
                    Gift gift = giftData.GetById(assignment.AssignedGiftId);
                    assignment.GiftName        = gift.GiftName;
                    assignment.GiftPrice       = gift.GiftPrice;
                    assignment.GiftDescription = gift.GiftDescription;
                }
            }

            return(assignments);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Generates the actual random assignments from the composition of members and gifts.
        /// </summary>
        /// <param name="assignGifts">
        /// Whether to include gifts in the the random assignment
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string GenerateAssignments(bool assignGifts)
        {
            var           rand    = new Random();
            List <Member> members = new MemberDataOperations().GetAll().ToList();

            if (members.Count <= 1)
            {
                return("There needs to be more than 1 member added to assign");
            }

            List <Gift> gifts = new GiftDataOperations().GetAll().ToList();

            if (assignGifts && gifts.Count < 1)
            {
                return("There are no gifts to assign");
            }

            var assignments = new Collection <Assignments>();

            while (members.Count > 0)
            {
                var         assignment1 = new Assignments();
                var         assignment2 = new Assignments();
                Assignments assignment3 = null;
                int         index       = rand.Next(members.Count);
                Member      member1     = members[index];
                members.RemoveAt(index);

                index = rand.Next(members.Count);
                Member member2 = members[index];
                members.RemoveAt(index);
                assignment1.MemberId         = member1.MemberId;
                assignment1.AssignedMemberId = member2.MemberId;
                assignment2.MemberId         = member2.MemberId;
                assignment2.AssignedMemberId = member1.MemberId;
                Member member3 = null;

                // Handle the edge case where we have 3 members
                if (members.Count == 1)
                {
                    index   = rand.Next(members.Count);
                    member3 = members[index];
                    members.RemoveAt(index);
                    assignment3          = new Assignments();
                    assignment3.MemberId = member3.MemberId;
                }

                if (assignGifts)
                {
                    Gift gift1 = gifts[rand.Next(gifts.Count)];
                    Gift gift2 = gifts[rand.Next(gifts.Count)];
                    assignment1.AssignedGiftId = gift1.GiftId;
                    assignment2.AssignedGiftId = gift2.GiftId;
                    if (member3 != null)
                    {
                        Gift gift3 = gifts[rand.Next(gifts.Count)];
                        assignment3.AssignedGiftId   = gift3.GiftId;
                        assignment2.AssignedMemberId = member3.MemberId;
                        assignment3.AssignedMemberId = member1.MemberId;
                        assignments.Add(assignment3);
                    }

                    assignments.Add(assignment1);
                    assignments.Add(assignment2);
                }
                else
                {
                    if (member3 != null)
                    {
                        assignment2.AssignedMemberId = member3.MemberId;
                        assignment3.AssignedMemberId = member1.MemberId;
                        assignments.Add(assignment3);
                    }

                    assignments.Add(assignment1);
                    assignments.Add(assignment2);
                }
            }

            // We can drop here because we're just going to regenerate from existing data
            new AssignmentDataOperations().DropAssignmentTable();
            if (new AssignmentDataOperations().AddMultipleRecords(assignments) < 2)
            {
                return("Assignment failed!");
            }

            return(null);
        }