Esempio n. 1
0
        public override void Update(Comment entity)
        {
            // entity.CommentState = State.WAITING_PERMISION_FOR_UPDATE;
            //notification for moderators
            Comment old = repository.GetComment(entity.Id);
            var     sub = repository.GetManyAsNoTracking(c => c.ParentId == entity.Id).ToList();

            if (old.LikesOrDislikes.Count() > 0 || sub.Count() > 0)
            {
                throw new Exception("Komentar se ne može izmeniti. Postoje glasovi ili podkomentari.");
            }
            Survey s    = surveyRepository.GetByIdAsNoTracking(entity.SurveyId);
            var    user = userRepository.GetById(entity.UserId);

            var ids = userCategoryRepository.GetMany(uc => uc.CategoryId == s.CategoryId).Select(uc => uc.UserId).ToList();
            List <UserNotification> list = new List <UserNotification>();
            Notification            n    = new Notification(
                user.FirstName + " " + user.LastName + "je izmenio/la komentar.",
                DateTime.Now, Operation.UPDATE, NotificationType.MODERATOR);

            n.UserId    = user.Id;
            n.SurveyId  = s.Id;
            n.CommentId = entity.Id;

            if (ids.Count() > 0)
            {
                ids.ForEach(modId => {
                    UserNotification un = new UserNotification(modId, n, false);
                    list.Add(un);
                });
            }
            else
            {
                var admins = userRepository.GetForRoleName("Admin").ToList();
                admins.ForEach(admin => {
                    UserNotification un = new UserNotification(admin.Id, n, false);
                    list.Add(un);
                });
            }


            base.Update(old, entity);
            userNotificationRepository.AddUserNotifications(list);
        }
Esempio n. 2
0
 List <UserCategory> IUserCategoryService.GetForCategory(int categoryId)
 {
     return(repository.GetMany(uc => uc.CategoryId == categoryId).ToList());
 }
Esempio n. 3
0
 IEnumerable <UserCategory> IUserService.GetModeratorsForCategory(int catId)
 {
     return(userCategoryRepository.GetMany(uc => uc.CategoryId == catId));
 }