public override void Update(LikeOrDislikeComment likeOrDislikeComment)
        {
            var user = userRepository.GetById(likeOrDislikeComment.UserId);

            var old = repository.GetMany(lod => lod.UserId == likeOrDislikeComment.UserId && lod.CommentId == likeOrDislikeComment.CommentId).ToList().FirstOrDefault();

            base.Delete(lod => lod.UserId == likeOrDislikeComment.UserId && lod.CommentId == likeOrDislikeComment.CommentId);
            string s = "";

            if (likeOrDislikeComment.IsLike)
            {
                s = " se svidja vas komentar.";
            }
            else
            {
                s = " se ne svidja vas komentar.";
            }
            Comment comment = commentRepository.GetById(likeOrDislikeComment.CommentId);

            if (comment.UserId != likeOrDislikeComment.UserId)
            {
                Notification notification = new Notification("Korisniku " + user.FirstName + " " + user.LastName +
                                                             s, DateTime.Now, Operation.LIKEORDISLIKE, NotificationType.PERSONAL);
                notification.UserId = likeOrDislikeComment.UserId;

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

                UserNotification u = new UserNotification(comment.UserId, notification, false);
                userNotificationRepository.Add(u);
            }


            base.Create(likeOrDislikeComment);
        }
Beispiel #2
0
        string IUserAnswerService.AddAnswers(List <UserAnswer> userAnswers, int surveyId, string encriptedUserId)
        {
            var s = surveyRepository.GetManyWithInclude(survey => survey.Id == surveyId, survey => survey.Users, survey => survey.Questions, survey => survey.Groups).FirstOrDefault();

            //validation
            var validation = this.Validation(s.Questions.ToList(), userAnswers, s, true);

            if (validation != null)
            {
                return(validation);
            }
            var userId = userAnswers.First().UserId;
            var user   = userRepository.GetById(userAnswers.First().UserId);

            repository.AddAnswers(userAnswers);

            //add user and survey in table UserSurvey
            UserSurvey us = new UserSurvey();

            us.UserId       = userId;
            us.SurveyId     = surveyId;
            us.EncrptUserId = encriptedUserId;

            userSurveyRepository.Add(us);
            var userNameAndLastName = "Korisnik ";

            if (!s.Anonymous)
            {
                userNameAndLastName += user.FirstName + " " + user.LastName;
            }

            //notification for author
            Notification notification = new Notification(userNameAndLastName + " je popunio/la Vašu  anketu", DateTime.Now, Operation.FILLED, NotificationType.PERSONAL);

            notification.SurveyId = us.SurveyId;
            notification.UserId   = us.UserId;
            UserNotification un = new UserNotification(s.UserId, notification, false);

            userNotificationRepository.Add(un);

            return(null);
        }
Beispiel #3
0
        public override void Create(FavoriteSurveys entity)
        {
            var          user = userRepository.GetById(entity.UserId);
            Notification n    = new Notification(user.FirstName + " " + user.LastName +
                                                 " se sviđa vasa anketa.", DateTime.Now, Operation.LIKEORDISLIKE, NotificationType.PERSONAL);

            n.SurveyId = entity.SurveyId;
            n.UserId   = entity.UserId;

            var survey = surveyRepository.GetByIdAsNoTracking(entity.SurveyId);

            userNotificationRepository.Add(new UserNotification(survey.UserId, n, false));
            base.Create(entity);
        }
Beispiel #4
0
        public Result <UserNotification, OperationError> AddUserNotification(int organizationId, int userToNotifyId, string name, string message, int relatedEntityId, RelatedEntityType relatedEntityType, NotificationType notificationType)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            using var transaction = _transactionManager.Begin(IsolationLevel.ReadCommitted);
            if (!RelatedEntityExists(relatedEntityId, relatedEntityType))
            {
                transaction.Rollback();
                return(new OperationError(OperationFailure.NotFound));
            }

            var notification = new UserNotification(name, message, notificationType, organizationId, userToNotifyId, _operationClock.Now);

            switch (relatedEntityType)
            {
            case RelatedEntityType.itContract:
                notification.Itcontract_Id = relatedEntityId;
                break;

            case RelatedEntityType.itProject:
                notification.ItProject_Id = relatedEntityId;
                break;

            case RelatedEntityType.itSystemUsage:
                notification.ItSystemUsage_Id = relatedEntityId;
                break;

            case RelatedEntityType.dataProcessingRegistration:
                notification.DataProcessingRegistration_Id = relatedEntityId;
                break;

            default:
                return(new OperationError(OperationFailure.BadInput));
            }


            var userNotification = _userNotificationRepository.Add(notification);

            transaction.Commit();
            return(userNotification);
        }
        public override void Create(RequestGroup entity)
        {
            var          group = groupRepository.GetById(entity.GroupId);
            var          user  = userRepository.GetById(entity.UserId);
            Notification n     = new Notification()
            {
                DateTime        = DateTime.Now,
                GroupId         = group.Id,
                NotificaionType = NotificationType.PERSONAL,
                UserId          = entity.UserId,
                Operation       = Operation.REQUEST,
                Message         = user.FirstName + " " + user.LastName + " je poslao zahtev za pristup grupi " + group.Name,
            };
            var userNotification = new UserNotification(group.UserId, n, false);

            userNotificationRepository.Add(userNotification);

            base.Create(entity);
        }
 public void Create(UserNotification userNotification)
 {
     _userNotificationRepository.Add(userNotification);
     _unitOfWork.Commit();
 }
Beispiel #7
0
 public async Task Add(UserNotification notification)
 {
     await _repository.Add(notification);
 }