public RecipientsSelectionViewModel(List <Recipient> preSelected)
 {
     AddNewCommand = new RelayCommand(AddNewCommandExecuted, CanAddNewCommand);
     OkayCommand   = new RelayCommand(OkayCommandExecuted, CanOkayCommand, true);
     CancelCommand = new RelayCommand(CancelCommandExecuted, CanCancelCommand, true);
     //Load a recipient selection
     preSelected.ForEach(r => AllRecipients.Add(new RecipientViewModel(r)));
     Recipient.AllRecipients.ForEach(r => { if (preSelected.Any(ps => ps.Id == r.Id))
                                            {
                                                AllRecipients.Add(new RecipientViewModel(r));
                                            }
                                     });
 }
예제 #2
0
        void ReleaseDesignerOutlets()
        {
            if (AllRecipients != null)
            {
                AllRecipients.Dispose();
                AllRecipients = null;
            }

            if (CreateRecipient != null)
            {
                CreateRecipient.Dispose();
                CreateRecipient = null;
            }
        }
        public IHttpResponse Create()
        {
            var user = this.Db.Users.FirstOrDefault(x => x.Username == this.User.Username);

            if (!User.IsLoggedIn || user.Role != Role.Admin)
            {
                return(this.View("/Users/Login"));
            }
            var recipients = this.Db.Users
                             .Select(x => new RecipientViewModel
            {
                Recipient = x.Username
            }).ToList();

            var model = new AllRecipients
            {
                Recipients = recipients
            };

            return(this.View("Packages/Create", model));
        }
        public async Task <AllRecipients> GetAllParentRecipients(int?studentUsi, string recipientUniqueId, int recipientTypeId, int rowsToSkip, int rowsToRetrieve)
        {
            var teachers = await(from staffsa in _edFiDb.StaffSectionAssociations
                                 join ssa in _edFiDb.StudentSectionAssociations
                                 on new { staffsa.SchoolId, staffsa.SchoolYear, staffsa.LocalCourseCode, staffsa.SequenceOfCourse, staffsa.TermDescriptorId, staffsa.UniqueSectionCode }
                                 equals new { ssa.SchoolId, ssa.SchoolYear, ssa.LocalCourseCode, ssa.SequenceOfCourse, ssa.TermDescriptorId, ssa.UniqueSectionCode }
                                 join spa in _edFiDb.StudentParentAssociations on ssa.StudentUsi equals spa.StudentUsi
                                 join co in _edFiDb.CourseOfferings
                                 on new { staffsa.SchoolId, staffsa.SchoolYear, staffsa.TermDescriptorId, staffsa.LocalCourseCode }
                                 equals new { co.SchoolId, co.SchoolYear, co.TermDescriptorId, co.LocalCourseCode }
                                 join s in _edFiDb.Students
                                 on ssa.StudentUsi equals s.StudentUsi
                                 join p in _edFiDb.Parents
                                 on spa.ParentUsi equals p.ParentUsi
                                 join staff in _edFiDb.Staffs on staffsa.StaffUsi equals staff.StaffUsi
                                 join sy in _edFiDb.SchoolYearTypes on ssa.SchoolYear equals sy.SchoolYear
                                 where p.ParentUniqueId == recipientUniqueId && sy.CurrentSchoolYear
                                 group new { s, staff, co } by new { s.StudentUsi, staff.StaffUsi } into g
                                 select new
            {
                StudentFirstName   = g.FirstOrDefault().s.FirstName,
                StudentMiddleName  = g.FirstOrDefault().s.MiddleName,
                StudentLastsurname = g.FirstOrDefault().s.LastSurname,
                StudentUniqueId    = g.FirstOrDefault().s.StudentUniqueId,
                StudentUsi         = g.FirstOrDefault().s.StudentUsi,
                Usi          = g.Key.StaffUsi,
                UniqueId     = g.FirstOrDefault().staff.StaffUniqueId,
                FirstName    = g.FirstOrDefault().staff.FirstName,
                MiddleName   = g.FirstOrDefault().staff.MiddleName,
                LastSurname  = g.FirstOrDefault().staff.LastSurname,
                PersonTypeId = ChatLogPersonTypeEnum.Staff.Value,
                CourseTitles = g.Select(x => x.co.LocalCourseTitle)
            }).ToListAsync();

            var studentTeachers = teachers.GroupBy(x => x.StudentUsi).Select(x => new StudentRecipients
            {
                StudentUsi      = x.Key,
                StudentUniqueId = x.FirstOrDefault().StudentUniqueId,
                FirstName       = x.FirstOrDefault().FirstName,
                MiddleName      = x.FirstOrDefault().MiddleName,
                LastSurname     = x.FirstOrDefault().LastSurname,
                Recipients      = x.Select(recipient => new RecipientModel
                {
                    FirstName          = recipient.FirstName,
                    LastSurname        = recipient.LastSurname,
                    Usi                = recipient.Usi,
                    UniqueId           = recipient.UniqueId,
                    PersonTypeId       = ChatLogPersonTypeEnum.Staff.Value,
                    RelationsToStudent = recipient.CourseTitles.ToList(),
                }).ToList()
            }).ToList();

            var totalRecipients = studentTeachers.Count();

            List <StudentRecipients> result = new List <StudentRecipients>();


            // If they selected a Student
            if (studentUsi.HasValue)
            {
                result.Add(studentTeachers.FirstOrDefault(x => x.StudentUsi == studentUsi.Value));
            }

            var unreadMessages = studentTeachers.Where(x => (studentUsi.HasValue ? studentUsi.Value != x.StudentUsi : true) &&
                                                       _edFiDb.ChatLogs.Count(c => !c.RecipientHasRead &&
                                                                              c.RecipientUniqueId == recipientUniqueId &&
                                                                              c.RecipientTypeId == recipientTypeId &&
                                                                              c.StudentUniqueId == x.StudentUniqueId &&
                                                                              x.Recipients
                                                                              .Any(r => r.UniqueId == c.SenderUniqueId && r.PersonTypeId == c.SenderTypeId)) > 0)
                                 .Select(x => {
                foreach (var recipient in x.Recipients)
                {
                    recipient.UnreadMessageCount = _edFiDb.ChatLogs.Count(c => !c.RecipientHasRead &&
                                                                          c.RecipientUniqueId == recipientUniqueId &&
                                                                          c.RecipientTypeId == recipientTypeId &&
                                                                          c.StudentUniqueId == x.StudentUniqueId &&
                                                                          recipient.UniqueId == c.SenderUniqueId &&
                                                                          recipient.PersonTypeId == c.SenderTypeId);
                }
                return(x);
            })
                                 .ToList();

            var recentMessages = studentTeachers.Where(x => (studentUsi.HasValue ? studentUsi.Value != x.StudentUsi : true) &&
                                                       _edFiDb.ChatLogs.Count(c =>
                                                                              ((c.RecipientUniqueId == recipientUniqueId && c.SenderTypeId == recipientTypeId) ||
                                                                               (c.SenderUniqueId == recipientUniqueId && c.SenderTypeId == recipientTypeId)) &&
                                                                              c.StudentUniqueId == x.StudentUniqueId &&
                                                                              !unreadMessages.Any(um => um.StudentUniqueId == x.StudentUniqueId) &&
                                                                              x.Recipients
                                                                              .Any(r => (r.UniqueId == c.SenderUniqueId && r.PersonTypeId == c.SenderTypeId) ||
                                                                                   (r.UniqueId == c.RecipientUniqueId && r.PersonTypeId == c.RecipientTypeId))) > 0).ToList();


            var otherMessages = studentTeachers.Where(x => (studentUsi.HasValue ? studentUsi.Value != x.StudentUsi : true) &&
                                                      !(unreadMessages.Any(um => um.StudentUniqueId == x.StudentUniqueId) ||
                                                        recentMessages.Any(rm => rm.StudentUniqueId == x.StudentUniqueId))).ToList();

            result.AddRange(unreadMessages);
            result.AddRange(recentMessages);
            result.AddRange(otherMessages);

            var model = new AllRecipients
            {
                EndOfData         = totalRecipients <= rowsToSkip + rowsToRetrieve,
                StudentRecipients = result.Skip(rowsToSkip).Take(rowsToRetrieve).ToList()
            };

            return(model);
        }
 private bool CanOkayCommand() => AllRecipients.Any(t => t.IsSelected);