Beispiel #1
0
        void ICommentService.Create(Comment comment, int userId)
        {
            var user = userRepository.GetById(userId);

            comment.CreationDate = DateTime.Now;
            comment.LastEdited   = DateTime.Now;


            comment.UserId = userId;

            //VALIDACIJA !!!

            List <UserNotification> list = new List <UserNotification>();
            //Za autora ankete i autora komentara
            Notification notification = new Notification(user.FirstName + " " + user.LastName + " je prokomentarisao/la Vašu anketu.", DateTime.Now, Operation.ADD, NotificationType.PERSONAL);

            notification.UserId    = comment.UserId;
            notification.SurveyId  = comment.SurveyId;
            notification.CommentId = comment.Id;

            Survey survey = surveyRepository.GetByIdAsNoTracking(comment.SurveyId);

            if (survey.UserId != userId)
            {
                UserNotification forSurveyAuthor = new UserNotification(survey.UserId, notification, false);
                list.Add(forSurveyAuthor);
            }
            if (comment.ParentId != null)
            {
                Comment parent = repository.GetById((int)comment.ParentId);
                if (parent.UserId == survey.UserId)
                {
                }
                else
                {
                    Notification notificationForCommentAuthor = new Notification(user.FirstName + " " + user.LastName + " je odgovorio/la na Vaš komentar.",
                                                                                 DateTime.Now, Operation.ADD, NotificationType.PERSONAL);
                    notification.UserId    = comment.UserId;
                    notification.SurveyId  = comment.SurveyId;
                    notification.CommentId = comment.Id;
                    UserNotification forCommentAuthor = new UserNotification(parent.UserId, notification, false);
                    list.Add(forCommentAuthor);
                }
            }

            base.Create(comment);
            userNotificationRepository.AddUserNotifications(list);
        }
Beispiel #2
0
        public string ResetSurvey(int userId, int surveyId)
        {
            var survey = surveyRepository.GetByIdAsNoTracking(surveyId);

            //if user is unauthorized
            if (survey.UserId != userId)
            {
                return("401");
            }

            var users  = survey.Users;
            var author = userRepository.GetById(userId);
            //notification
            Notification notification = new Notification(author.FirstName + " " + author.LastName
                                                         + " je resetovao anketu. Molimo Vas da je ponovo popunite.", DateTime.Now, Operation.RESET, NotificationType.PERSONAL);

            notification.SurveyId = survey.Id;
            notification.UserId   = author.Id;
            List <UserNotification> notifications = new List <UserNotification>();

            foreach (var u in users)
            {
                notifications.Add(new UserNotification(u.UserId, notification, false));
            }
            // delete all answers
            userSurveyRepository.Delete(us => us.SurveyId == surveyId);
            userNotificationRepository.AddUserNotifications(notifications);
            var questionIdList = survey.Questions.Select(q => q.Id);

            repository.Delete(ua => questionIdList.Contains(ua.QuestionId));
            return("");
        }
        public void RespondOnRequest(RequestGroup request, Group group, bool accepted)
        {
            var user = userRepository.GetById(request.UserId);

            //delete request
            repository.Delete(r => r.GroupId == request.GroupId && r.UserId == request.UserId);
            //delete notification
            notificationRepository.Delete(n => n.GroupId == group.Id || n.UserId == request.UserId);
            if (accepted)
            {
                var author = userRepository.GetById(group.UserId);
                //create new notification
                Notification notification = new Notification()
                {
                    DateTime = DateTime.Now,
                    Message  = author.FirstName + " " + author.LastName +
                               " je prihvatio Vaš zahtev. Postali ste član grupe  " + group.Name,
                    GroupId         = group.Id,
                    UserId          = group.UserId,
                    Operation       = Operation.ACCEPTED,
                    NotificaionType = NotificationType.PERSONAL
                };

                Notification notificationForAuthor = new Notification()
                {
                    DateTime = DateTime.Now,
                    Message  = user.FirstName + " " + user.LastName +
                               " je postao član Vaše grupe " + group.Name,
                    GroupId         = group.Id,
                    UserId          = user.Id,
                    Operation       = Operation.ACCEPTED,
                    NotificaionType = NotificationType.PERSONAL
                };

                userNotificationRepository.AddUserNotifications(new List <UserNotification>(
                                                                    new UserNotification[] {
                    new UserNotification(request.UserId, notification, false),
                    new UserNotification(group.UserId, notificationForAuthor, true)
                })

                                                                );

                userGroupRepository.Add(new UserGroup()
                {
                    GroupId = group.Id, UserId = request.UserId
                });
            }
        }
Beispiel #4
0
        void ISurveyService.Create(Survey survey, int userId)
        {
            survey.UserId = userId;


            // survey.State = State.WAITING_PERMISION_FOR_ADD;
            survey.CreationDate = DateTime.Now;

            var user = userRepository.GetById(userId);

            // create Notification for administrator

            Notification notification = new Notification(user.FirstName + " " + user.LastName + " je napravio/la anketu.", DateTime.Now, Operation.ADD, NotificationType.MODERATOR);

            notification.Survey = survey;
            notification.UserId = userId;
            List <UserNotification> notifications = this.CreateNotificationsForAdminsAndModerators(survey.CategoryId, notification, userId);



            base.Create(survey);
            userNotificationRepository.AddUserNotifications(notifications);
        }
 void IUserNotificationService.AddUserNotifications(List <UserNotification> notifications)
 {
     repository.AddUserNotifications(notifications);
 }