Ejemplo n.º 1
0
        public void FillChildMail(VMMailDetail hierarchicalMails, int parentMailId, List <Mail> allMails)
        {
            foreach (var item in allMails.Where(c => c.ParentMailId == parentMailId).ToList())
            {
                VMMailDetail childMail = VMMailDetail.Parse(item, item.User);

                hierarchicalMails.ChildMails.Add(childMail);

                FillChildMail(hierarchicalMails, childMail.MailId, allMails);
            }
        }
Ejemplo n.º 2
0
        public ActionResult Detail(int id)
        {
            // Huzurlarınızdaa, iyyyyğğrenç bir kod bloğu.

            User loggedUser = Session["LoggedUser"] as User;

            Mail detailedMail = _uow.MailManager.Get(x => x.MailId == id);

            if (detailedMail == null)
            {
                TempData["ProcessResult"] = "An error has occured when bringing mail.";
                TempData["AlertType"]     = "danger";
                return(RedirectToAction("Inbox"));
            }

            List <VMMailDetail> hierarchicalMails = new List <VMMailDetail>();
            List <Mail>         allMails          = _uow.MailManager.ListAll(x => x.IsActive && (x.SenderId == loggedUser.UserId || x.ReceiverId == loggedUser.UserId));

            var isDone = false;

            while (!isDone)
            {
                if (detailedMail.ParentMailId == null)
                {
                    isDone = true;
                }
                else
                {
                    detailedMail = _uow.MailManager.BringById(x => x.MailId == detailedMail.ParentMailId);
                }

                if (!detailedMail.IsRead)
                {
                    detailedMail.IsRead   = true;
                    detailedMail.ReadDate = DateTime.Now;
                    _uow.MailManager.Update(detailedMail);
                    _uow.SaveChanges();
                }
            }

            VMMailDetail parentMail = VMMailDetail.Parse(detailedMail, detailedMail.User);

            FillChildMail(parentMail, detailedMail.MailId, allMails);
            hierarchicalMails.Add(parentMail);

            return(View(hierarchicalMails));
        }