Exemplo n.º 1
0
        //TODO : notification sending

        public AnnouncementQnA AskQuestion(int announcementId, AnnouncementTypeEnum announcementType, string question)
        {
            Trace.Assert(Context.PersonId.HasValue && Context.SchoolLocalId.HasValue);

            using (var uow = Update())
            {
                var da  = new AnnouncementQnADataAccess(uow);
                var ann = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementById(announcementId);

                var annQnA = new AnnouncementQnAComplex
                {
                    AnnouncementRef = announcementId,
                    AskerRef        = Context.PersonId.Value,
                    Question        = question,
                    QuestionTime    = Context.NowSchoolTime,
                    State           = AnnouncementQnAState.Asked
                };
                da.Insert(annQnA);
                uow.Commit();
                annQnA = da.GetAnnouncementQnA(new AnnouncementQnAQuery
                {
                    AnnouncementId = announcementId,
                    CallerId       = annQnA.AskerRef,
                    SchoolId       = Context.SchoolLocalId.Value
                }).AnnouncementQnAs.OrderByDescending(x => x.Id).First();
                ServiceLocator.NotificationService.AddAnnouncementNotificationQnToAuthor(annQnA.Id, ann.Id, announcementType);
                return(annQnA);
            }
        }
 private bool CanEditAnswer(AnnouncementQnAComplex announcementQnA)
 {
     return(BaseSecurity.IsSysAdmin(Context) || announcementQnA.AnswererRef == Context.PersonId ||
            (Context.PersonId.HasValue && Context.Role == CoreRoles.TEACHER_ROLE &&
             string.IsNullOrEmpty(announcementQnA.Answer) && announcementQnA.ClassRef.HasValue &&
             ((DemoClassService)ServiceLocator.ClassService).ClassTeacherExists(announcementQnA.ClassRef.Value, Context.SchoolLocalId.Value)));
 }
Exemplo n.º 3
0
        private bool CanEditQuestion(AnnouncementQnAComplex announcementQnA, UnitOfWork uow)
        {
            var da = new ClassTeacherDataAccess(uow);

            return(BaseSecurity.IsSysAdmin(Context) || announcementQnA.AskerRef == Context.PersonId ||
                   (Context.PersonId.HasValue && Context.Role == CoreRoles.TEACHER_ROLE &&
                    da.Exists(announcementQnA.ClassRef, Context.PersonId.Value)) ||
                   (BaseSecurity.IsDistrictAdmin(Context) && announcementQnA.AdminRef == Context.PersonId));
        }
Exemplo n.º 4
0
 public static AnnouncementQnAViewData Create(AnnouncementQnAComplex announcementQnA)
 {
     return(new AnnouncementQnAViewData
     {
         Id = announcementQnA.Id,
         AnnouncementId = announcementQnA.AnnouncementRef,
         IsOwner = announcementQnA.IsOwner,
         Question = AnnouncementMessageViewData.Create(announcementQnA, false),
         Answer = announcementQnA.Answerer != null?AnnouncementMessageViewData.Create(announcementQnA, true) : null,
                      State = (int)announcementQnA.State
     });
 }
Exemplo n.º 5
0
 public static AnnouncementMessageViewData Create(AnnouncementQnAComplex announcementQnA, bool isAnswerer)
 {
     if (isAnswerer)
     {
         return(new AnnouncementMessageViewData
         {
             Person = ShortPersonViewData.Create(announcementQnA.Answerer),
             Message = announcementQnA.Answer,
             Created = announcementQnA.AnsweredTime
         });
     }
     return(new AnnouncementMessageViewData
     {
         Person = ShortPersonViewData.Create(announcementQnA.Asker),
         Message = announcementQnA.Question,
         Created = announcementQnA.QuestionTime
     });
 }
        public AnnouncementQnA AskQuestion(int announcementId, AnnouncementTypeEnum announcementType, string question)
        {
            Trace.Assert(Context.PersonId.HasValue);

            var ann = ServiceLocator.GetAnnouncementService(announcementType).GetAnnouncementDetails(announcementId);

            //if(!ann.PrimaryTeacherRef.HasValue)
            //    throw new ChalkableException("There is no teachers for that item");

            var annQnA = new AnnouncementQnAComplex
            {
                AnnouncementRef = announcementId,
                AskerRef        = Context.PersonId.Value,
                Question        = question,
                QuestionTime    = Context.NowSchoolTime,
                State           = AnnouncementQnAState.Asked,
                Asker           = ServiceLocator.PersonService.GetPersonDetails(Context.PersonId.Value),
                Answerer        = ServiceLocator.PersonService.GetPersonDetails(ann.Owner.Id)
            };

            if (ann.ClassAnnouncementData != null)
            {
                annQnA.ClassRef = ann.ClassAnnouncementData.ClassRef;
            }
            if (ann.LessonPlanData != null)
            {
                annQnA.ClassRef = ann.LessonPlanData.ClassRef;
            }
            if (ann.AdminAnnouncementData != null)
            {
                annQnA.AdminRef = ann.AdminAnnouncementData.AdminRef;
            }

            AnnouncementQnAStorage.Add(annQnA);
            annQnA = GetAnnouncementQnA(new AnnouncementQnAQuery
            {
                AnnouncementId = announcementId,
                CallerId       = annQnA.AskerRef
            }).AnnouncementQnAs.OrderByDescending(x => x.Id).First();
            ServiceLocator.NotificationService.AddAnnouncementNotificationQnToAuthor(annQnA.Id, ann.Id, announcementType);
            return(annQnA);
        }
 public void AddQnA(AnnouncementQnAComplex announcementQnAComplex)
 {
     AnnouncementQnAStorage.Add(announcementQnAComplex);
 }
 private bool CanEditQuestion(AnnouncementQnAComplex announcementQnA)
 {
     return(BaseSecurity.IsSysAdmin(Context) || announcementQnA.AskerRef == Context.PersonId ||
            (Context.PersonId.HasValue && Context.Role == CoreRoles.TEACHER_ROLE && announcementQnA.ClassRef.HasValue &&
             ((DemoClassService)ServiceLocator.ClassService).ClassTeacherExists(announcementQnA.ClassRef.Value, Context.PersonId.Value)));
 }
Exemplo n.º 9
0
 public Notification BuildAnnouncementAnswerToPersonNotifiaction(DateTime created, AnnouncementQnAComplex announcementQnA, AnnouncementComplex announcement)
 {
     return(BuildNotificationFromTemplate(NotificationTemplateProvider.ANNOUNCEMENT_NOTIFICATION_ANSWER_TO_PERSON,
                                          NotificationType.Announcement, announcementQnA.Asker, announcement, null, null,
                                          null, announcementQnA.Answerer, new
     {
         announcement.AnnouncementTypeName,
         AnnouncementTitle = announcement.Title,
         PersonQuestion = StringTools.BuildShortText(announcementQnA.Question, 40),
         AnswererName = announcementQnA.Answerer.DisplayName()
     }));
 }
Exemplo n.º 10
0
 public Notification BuildAnnouncementQnToAuthorNotifiaction(DateTime created, AnnouncementQnAComplex announcementQnA, AnnouncementComplex announcement, Person answerer)
 {
     return(BuildNotificationFromTemplate(NotificationTemplateProvider.ANNOUNCEMENT_QUESTION_NOTIFICATION_TOAUTHOR,
                                          NotificationType.Question, answerer, announcement, null, null, null,
                                          announcementQnA.Asker, new
     {
         announcement.AnnouncementTypeName,
         PersonQuestion = StringTools.BuildShortText(announcementQnA.Question, 35),
         AnnouncementTitle = announcement.Title,
         AskerName = announcementQnA.Asker.DisplayName()
     }));
 }