public MeetingAssignment MeetingAssignmentByMeetingAssignmentId(int meetingAssignmentId) { MeetingAssignment meetingAssignment = (from ms in repository.MeetingAssignments where ms.Id == meetingAssignmentId select ms).Single(); return(meetingAssignment); }
public List <MeetingAssignment> MeetingAssignmentsForSchedule(ScheduleDate scheduleDates, int congregationId) { Congregation congo = CongregationByCongregationId(congregationId); List <Assignment> congoAssignments = AssignmentsByCongregationId(congo.Id); List <Meeting> meetings = new List <Meeting>(); List <MeetingAssignment> meetingAssignments = new List <MeetingAssignment>(); Meeting meeting; string dayOfWeekMeeting = congo.WeekMeetingDay; string publicMeeting = congo.PublicMeetingDay; foreach (DateTime day in EachDayLoop(scheduleDates.StartDate, scheduleDates.EndDate)) { if (Convert.ToString(day.DayOfWeek) == dayOfWeekMeeting || Convert.ToString(day.DayOfWeek) == publicMeeting) { if (Convert.ToString(day.DayOfWeek) == publicMeeting) { meeting = CreateMeeting(2, day.Date, congo.Id); } else { meeting = CreateMeeting(1, day.Date, congo.Id); } meetings.Add(meeting); } } List <UnavailableDate> cancelled = UnavailableDateByCongregationId(congregationId); foreach (Meeting m in meetings) { if (cancelled.Any(p => p.DateUnavailable == m.MeetingDate)) { continue; } congoAssignments = congoAssignments.OrderBy(o => o.PositionOnSchedule).ToList(); foreach (Assignment a in congoAssignments) { if (a.AmountPerMeeting == 0) { continue; } List <Member> membersAvailable = MembersAvailable(a.Id, m.MeetingDate); int counter = 1; while (counter <= a.AmountPerMeeting) { Member nextMember = NextMemberToAssign(membersAvailable, m, a); MeetingAssignment ma = CreateMeetingAssignment(m.Id, nextMember.Id, a.Id, nextMember.CongregationId, scheduleDates.Id); meetingAssignments.Add(ma); counter++; } } } return(meetingAssignments); }
public MeetingAssignment UpdateMeetingAssignment(MeetingAssignment meetingAssignment) { MeetingAssignment ma = MeetingAssignmentByMeetingAssignmentId(meetingAssignment.Id); ma.MeetingId = meetingAssignment.MeetingId; ma.AssignmentId = meetingAssignment.AssignmentId; ma.MemberId = meetingAssignment.MemberId; ma.ReferanceMark = meetingAssignment.ReferanceMark; ma.ScheduleDateId = meetingAssignment.ScheduleDateId; ma.UpdateDate = DateTime.Now; repository.SaveChanges(); return(ma); }
public MeetingAssignment CreateMeetingAssignment(int meetingId, int memberId, int assignmentId, int congregationId, int scheduleDateId) { MeetingAssignment meetingassignment = new MeetingAssignment(); meetingassignment.MeetingId = meetingId; meetingassignment.MemberId = memberId; meetingassignment.AssignmentId = assignmentId; meetingassignment.CongregationId = congregationId; meetingassignment.ReferanceMark = false; meetingassignment.ScheduleDateId = scheduleDateId; meetingassignment.CreateDate = DateTime.Now; repository.MeetingAssignments.Add(meetingassignment); repository.SaveChanges(); return(meetingassignment); }
public Member NextMemberToAssign(List <Member> membersAvailable, Meeting currentMeeting, Assignment currentAssignment) { List <Member> newMembers = (from mem in membersAvailable where mem.MeetingAssignments.Count == 0 select mem).ToList(); if (newMembers.Count != 0) { newMembers = newMembers.OrderBy(z => z.FirstName).ToList(); return(newMembers[0]); } int meetingCountToBeat = new int(); int meetingCounter = 0; Member currentlySelected = new Member(); MeetingAssignment mLastMeetingAssignment = new MeetingAssignment(); List <Member> alreadyAssigned = (from l in currentMeeting.MeetingAssignments select l.Member).ToList(); List <Meeting> allMeeting = (from v in repository.Meetings where v.CongregationId == currentMeeting.CongregationId select v).ToList(); allMeeting = allMeeting.OrderByDescending(o => o.MeetingDate).ToList(); int index = allMeeting.IndexOf(currentMeeting); List <Member> go = (from goat in allMeeting[index + 1].MeetingAssignments select goat.Member).ToList(); foreach (Member m in membersAvailable) { List <MeetingAssignment> selectedMAssignments = (from d in repository.MeetingAssignments where d.MemberId == m.Id select d).ToList(); selectedMAssignments = selectedMAssignments.OrderByDescending(o => o.Meeting.MeetingDate).ToList(); if (alreadyAssigned.Any(p => p.Id == m.Id))//skips if they are already assigned or previous assignment was same assignment. { continue; } if (selectedMAssignments[0].AssignmentId == currentAssignment.Id && m.MemberAssignments.Count > 2) { continue; } foreach (DateTime d in EachDayLoop(selectedMAssignments[0].Meeting.MeetingDate.AddDays(1), currentMeeting.MeetingDate.AddDays(-1))) { if (Convert.ToString(d.DayOfWeek) == m.Congregation.PublicMeetingDay || Convert.ToString(d.DayOfWeek) == m.Congregation.WeekMeetingDay) { meetingCounter++; } } if (currentlySelected.Id == 0) { meetingCountToBeat = meetingCounter; currentlySelected = m; mLastMeetingAssignment = selectedMAssignments[0]; meetingCounter = 0; continue; } if (meetingCounter > meetingCountToBeat) { meetingCountToBeat = meetingCounter; currentlySelected = m; mLastMeetingAssignment = selectedMAssignments[0]; meetingCounter = 0; } if (meetingCounter == meetingCountToBeat) { if (selectedMAssignments[0].Assignment.Label != currentAssignment.Label && mLastMeetingAssignment.Assignment.Label == currentAssignment.Label) { currentlySelected = m; mLastMeetingAssignment = selectedMAssignments[0]; } } meetingCounter = 0; continue; } return(currentlySelected); }