예제 #1
0
 public void AddPrivateMessageNotification(int privateMessageId)
 {
     Trace.Assert(Context.PersonId.HasValue);
     using (var uow = Update())
     {
         var msg           = new PrivateMessageDataAccess(uow).GetSentPrivateMessage(privateMessageId, Context.PersonId.Value);
         var notifications = msg.RecipientPersons.Select(x => builder.BuildPrivateMessageNotification(Context.NowSchoolTime, msg, msg.Sender, x)).ToList();
         new NotificationDataAccess(uow).Insert(notifications);
         uow.Commit();
     }
 }
예제 #2
0
        private void DeleteSentMessages(IList <int> ids, UnitOfWork uow)
        {
            var da       = new PrivateMessageDataAccess(uow);
            var messages = da.GetNotDeleted(ids, Context.PersonId.Value);

            if (messages.Count == 0)
            {
                throw new ChalkableSecurityException(ChlkResources.ERR_PRIVATE_MESSAGE_MARK_INVALID_RIGHTS);
            }

            foreach (var message in messages)
            {
                message.DeletedBySender = true;
            }

            da.Update(messages);
        }
예제 #3
0
        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);
                }
            }
        }