Exemplo n.º 1
0
        /// <summary>
        /// This function will take a list of mails, order them by the appropriate <see cref="MailSort"/>. Additionally, it will set up the viewbags
        /// needed for the index view, based on the sortby parameter.
        /// </summary>
        /// <param name="sortBy">A MailSort that determines how the mail will be sorted</param>
        /// <param name="mails">A reference list in which to sort by sortBy</param>
        /// <returns></returns>
        private List <Mail> OrderMailAndSetViewBag(MailSort sortBy, ref List <Mail> mails)
        {
            ViewBag.DateSortByValue    = MailSort.LatestDate;
            ViewBag.ContextSortByValue = MailSort.Context;
            ViewBag.FromSortByValue    = MailSort.From;
            ViewBag.SubjectSortByValue = MailSort.Subject;

            if (sortBy == MailSort.LatestDate)
            {
                mails = mails.OrderByDescending(m => m.Posted).ToList();
                ViewBag.DateSortByValue = MailSort.EarliestDate;
            }
            else if (sortBy == MailSort.EarliestDate)
            {
                mails = mails.OrderBy(m => m.Posted).ToList();
            }
            else if (sortBy == MailSort.Context)
            {
                mails = mails.OrderBy(m => m.Context).ToList();
                ViewBag.ContextSortByValue = MailSort.ReverseContext;
            }
            else if (sortBy == MailSort.ReverseContext)
            {
                mails = mails.OrderByDescending(m => m.Context).ToList();
            }
            else if (sortBy == MailSort.From)
            {
                mails = mails.OrderBy(m => m.FromUserProfile.FirstName).ThenBy(m => m.FromUserProfile.LastName).ToList();
                ViewBag.FromSortByValue = MailSort.ReverseFrom;
            }
            else if (sortBy == MailSort.ReverseFrom)
            {
                mails = mails.OrderByDescending(m => m.FromUserProfile.FirstName).ThenBy(m => m.FromUserProfile.LastName).ToList();
            }
            else if (sortBy == MailSort.Subject)
            {
                mails = mails.OrderBy(m => m.Subject).ToList();
                ViewBag.SubjectSortByValue = MailSort.ReverseSubject;
            }
            else if (sortBy == MailSort.ReverseSubject)
            {
                mails = mails.OrderByDescending(m => m.Subject).ToList();
            }
            return(mails);
        }
Exemplo n.º 2
0
        public ViewResult Index(MailSort sortBy = MailSort.LatestDate)
        {
            ViewBag.BoxHeader = "Inbox";
            List <Mail> mails = db.Mails.Where(m => m.ToUserProfileID == CurrentUser.ID && m.DeleteFromInbox == false).ToList();

            OrderMailAndSetViewBag(sortBy, ref mails);

            if (mails.Count() > 0)
            {
                List <int> threadIds = new List <int>();
                foreach (Mail mail in mails)
                {
                    MailAttachmentFilePath mfp = Directories.GetMailAttachment(mail.ContextID, mail.ThreadID);
                    if (mfp.AllFiles().Count() > 0)
                    {
                        threadIds.Add(mail.ThreadID);
                    }
                }
                ViewBag.AttachmentThreadIds = threadIds;
            }
            return(View(mails));
        }