public void MarkAsRead(IList <int> ids, bool read)
        {
            Trace.Assert(Context.PersonId.HasValue);

            PrivateMessageSecurity.EnsureMessgingPermission(Context);
            if (ids != null)
            {
                using (var uow = Update())
                {
                    var da = new PrivateMessageRecipientDataAccess(uow);
                    var messagesRecipients = da.GetNotDelatedMessageRecpients(ids, Context.PersonId.Value);
                    if (messagesRecipients.Count == 0)
                    {
                        throw new ChalkableSecurityException(ChlkResources.ERR_PRIVATE_MESSAGE_MARK_INVALID_RIGHTS);
                    }

                    foreach (var messageRecipient in messagesRecipients)
                    {
                        messageRecipient.Read = read;
                    }

                    da.Update(messagesRecipients);
                    uow.Commit();
                }
            }
        }
        public PaginatedList <PrivateMessage> GetMessages(int start, int count, bool?read, PrivateMessageType type, string role, string keyword, bool?classOnly, int?acadYear)
        {
            Trace.Assert(Context.PersonId.HasValue);
            Trace.Assert(Context.SchoolLocalId.HasValue);
            Trace.Assert(Context.SchoolYearId.HasValue);

            DateTime?fromDate = null;
            DateTime?toDate   = null;

            if (acadYear.HasValue)
            {
                var schoolYears = ServiceLocator.SchoolYearService.GetSchoolYearsByAcadYear(acadYear.Value);
                if (schoolYears.Count == 0)
                {
                    return(new PaginatedList <PrivateMessage>(new List <PrivateMessage>(), start / count, count));
                }

                fromDate = schoolYears.Min(x => x.StartDate);
                toDate   = schoolYears.Max(x => x.EndDate);
            }

            PrivateMessageSecurity.EnsureMessgingPermission(Context);
            using (var uow = Read())
            {
                var da       = new PrivateMessageDataAccess(uow);
                var roles    = string.IsNullOrWhiteSpace(role) ? new List <string>() : role.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                var rolesIds = roles.Select(x => CoreRoles.GetByName(x).Id).ToList();
                switch (type)
                {
                case PrivateMessageType.Income:
                    var inMsg = da.GetIncomeMessages(Context.PersonId.Value, rolesIds, keyword, read, start, count, fromDate, toDate);
                    return(new PaginatedList <PrivateMessage>(inMsg.Select(x => x), inMsg.PageIndex, inMsg.PageSize, inMsg.TotalCount));

                case PrivateMessageType.Sent:
                    var sentMsg = da.GetSentMessages(Context.PersonId.Value, rolesIds, keyword, start, count, classOnly, fromDate, toDate);
                    return(new PaginatedList <PrivateMessage>(sentMsg.Select(x => x), sentMsg.PageIndex, sentMsg.PageSize, sentMsg.TotalCount));

                default:
                    throw new ChalkableException(ChlkResources.ERR_PRIVATE_MESSAGE_INVALID_TYPE);
                }
            }
        }
 public IncomePrivateMessage GetIncomeMessage(int messageId)
 {
     Trace.Assert(Context.PersonId.HasValue);
     PrivateMessageSecurity.EnsureMessgingPermission(Context);
     return(DoRead(u => new PrivateMessageDataAccess(u).GetIncomePrivateMessage(messageId, Context.PersonId.Value)));
 }