Example #1
0
        public void GetTopicReviewersTest()
        {
            var reviewer = new User
            {
                Id    = 4,
                Email = "*****@*****.**",
                Role  = "Reviewer"
            };
            var reviewerUser = new TopicUser
            {
                TopicId = _tester.TopicOne.Id,
                UserId  = reviewer.Id,
                Role    = reviewer.Role
            };

            _tester.TestControllerWithMockData()
            .WithDbContext(dbContext => dbContext
                           .WithSet <User>(db => db.Add(reviewer))
                           .WithSet <TopicUser>(db => db.Add(reviewerUser)))
            .Calling(c => c.GetTopicReviewers(_tester.TopicOne.Id))
            .ShouldReturn()
            .Ok()
            .WithModelOfType <IEnumerable <UserResult> >()
            .Passing(actual => actual.Any(u => u.Email == reviewer.Email));
        }
        public void ChangeTopicStatusTestForConflict()
        {
            TopicStatus.Status = "Done";
            var reviewer = new User
            {
                Id    = 4,
                Email = "*****@*****.**",
                Role  = "Reviewer"
            };
            var reviewerUser = new TopicUser
            {
                TopicId = _tester.TopicOne.Id,
                UserId  = reviewer.Id,
                Role    = reviewer.Role
            };
            var topicReview = new TopicReview
            {
                TopicId    = _tester.TopicOne.Id,
                ReviewerId = reviewer.Id
            };

            _tester.TestControllerWithMockData()
            .WithDbContext(dbContext => dbContext
                           .WithSet <User>(db => db.Add(reviewer))
                           .WithSet <TopicUser>(db => db.Add(reviewerUser))
                           .WithSet <TopicReview>(db => db.Add(topicReview)))
            .Calling(c => c.ChangeStatus(_tester.TopicOne.Id, TopicStatus))
            .ShouldReturn()
            .StatusCode(409);
        }
Example #3
0
        private void createNotification(TopicUser topicUser, NotificationType type, string data = null)
        {
            var userId = topicUser.UserId;

            if (!notifiedUsers.Contains(userId))
            {
                var not = createAppNotification(type, data, userId);
                createMailNotification(topicUser, type, userId, not);
            }
        }
Example #4
0
        private void createMailNotification(TopicUser topicUser, NotificationType type, int userId, Notification not)
        {
            var email      = fetchUserEmail(topicUser);
            var subscribed = isSubsccribed(type, userId);

            if (email != null && subscribed)
            {
                emailSender.NotifyAsync(email, not);
            }
        }
Example #5
0
 private string fetchUserEmail(TopicUser topicUser)
 {
     try
     {
         var user = DbContext.Users.First(candidate => candidate.Id == topicUser.UserId);
         return(user.Email);
     }
     catch (InvalidOperationException)
     {
         return(null);
     }
 }
Example #6
0
        /// <summary>
        /// Create TopicInfo
        /// </summary>
        /// <param name="user">TopicUser</param>
        /// <param name="uofw">FlowTasksUnitOfWork</param>
        /// <param name="num">Number of records to return</param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="status"></param>
        /// <param name="withReplies"></param>
        /// <returns>TopicInfo</returns>
        private TopicInfo CreateTopicInfo(TopicUser user, FlowTasksUnitOfWork uofw, int num, DateTime start, DateTime end, string status, bool withReplies)
        {
            var replies           = new List <TopicMessageInfo>();
            var statusNewStr      = TopicStatusType.New.ToString();
            var statusReadStr     = TopicStatusType.Read.ToString();
            var statusRead        = uofw.TopicStatuses.First(s => s.Status == statusReadStr);
            var globalTopicStatus = CreateStatusType(user);

            IEnumerable <TopicUser> userTopics;

            if (withReplies)
            {
                userTopics =
                    uofw.TopicUsers.Find(
                        tu =>
                        !tu.TopicMessage.IsTopic && tu.TopicMessage.TopicId == user.TopicMessage.TopicId &&
                        tu.User == user.User &&
                        (string.IsNullOrEmpty(status) || tu.TopicStatus.Status == status),
                        tu => tu.TopicMessage, tu => tu.TopicMessage.Topic, tu => tu.TopicStatus).ToList();
            }
            else
            {
                // If we don't need the replyes, just load the new topics because we want to change the status
                userTopics =
                    uofw.TopicUsers.Find(
                        tu =>
                        !tu.TopicMessage.IsTopic && tu.TopicMessage.TopicId == user.TopicMessage.TopicId &&
                        tu.User == user.User && tu.TopicStatus.Status.Equals(statusNewStr),
                        tu => tu.TopicMessage, tu => tu.TopicMessage.Topic, tu => tu.TopicStatus).ToList();
            }

            var users = new Dictionary <string, string>();

            foreach (var r in userTopics)
            {
                if (withReplies)
                {
                    replies.Add(CreateMessageInfo(r, uofw, users));
                }

                if (r.TopicStatus.Status == statusNewStr)
                {
                    globalTopicStatus = TopicStatusType.New;
                    r.TopicStatus     = statusRead;
                }
            }

            var ti = new TopicInfo {
                TopicId = user.TopicMessage.TopicId, Title = user.TopicMessage.Topic.Title, Status = globalTopicStatus, Message = CreateMessageInfo(user, uofw, users), Replies = replies.ToArray()
            };

            return(ti);
        }
Example #7
0
        /// <summary>
        /// 一个话题明细
        /// </summary>
        /// <param name="topicId"></param>
        /// <returns></returns>
        public ActionResult Detail(int topicId)
        {
            var tp = LoveDb.One((Topic t) => t.Id == topicId);

            if (tp == null)
            {
                return(RedirectToAction("ErroResult"));
            }
            tp.Content = Helper.HtmlHelper.TransStringToHtml(tp.Content);
            var tu = new TopicUser
            {
                Topic    = tp,
                UninUser = LoveDb.GetUninUser(tp.UserId),
            };

            ViewBag.UserId        = tp.UserId;
            ViewBag.CurrentUserId = CheckValid();
            ViewBag.Sex           = GetIdSex(tp.UserId);

            return(View(tu));
        }
Example #8
0
        /// <summary>
        /// Create MessageInfo
        /// </summary>
        /// <param name="user">TopicUser</param>
        /// <param name="uofw">FlowTasksUnitOfWork</param>
        /// <param name="users"></param>
        /// <returns>TopicMessageInfo</returns>
        private TopicMessageInfo CreateMessageInfo(TopicUser user, FlowTasksUnitOfWork uofw, Dictionary <string, string> users)
        {
            var documents = CreateDocuments(user.TopicMessage, uofw);

            if (!users.ContainsKey(user.TopicMessage.From))
            {
                GetUserResponse resp;
                if (_usersService == null)
                {
                    using (var usersOperations = new FlowUsersService())
                    {
                        resp = usersOperations.GetUser(new GetUserRequest {
                            User = user.TopicMessage.From
                        });
                    }
                }
                else
                {
                    resp = _usersService.GetUser(new GetUserRequest {
                        User = user.TopicMessage.From
                    });
                }

                users.Add(user.TopicMessage.From, resp.User.PhotoPath);
            }

            return(new TopicMessageInfo
            {
                From = user.TopicMessage.From,
                ImageUrl = users[user.TopicMessage.From],
                To = user.TopicMessage.To,
                Message = user.TopicMessage.Message,
                When = user.TopicMessage.Topic.LastChanged,
                Status = CreateStatusType(user),
                Attachments = documents
            });
        }
Example #9
0
 public bool recommendTopic(int TopicId, string UserId)
 {
     using (context = new ApplicationDbContext())
     {
         try
         {
             var newTU = new TopicUser();
             var user  = context.Users.Where(x => x.Id == UserId).First();
             //if (user.RecommendedTopics.Where(x => x.TopicId == TopicId).ToArray().Length > 0)
             //    return false;
             var topic = context.topics.Where(x => x.TopicsId == TopicId).First();
             newTU.Topic = topic;
             newTU.User  = user;
             context.topicUsers.AddOrUpdate(newTU);
             context.SaveChanges();
             return(true);
         }
         catch (DbUpdateException ex)
         {
             Debug.WriteLine("Recommendation failed: Data Duplication");
             return(false);
         }
     }
 }
Example #10
0
        /// <summary>
        /// 一个话题明细
        /// </summary>
        /// <param name="topicId"></param>
        /// <returns></returns>
        public ActionResult Detail(int topicId)
        {
            var tp= LoveDb.One((Topic t) => t.Id == topicId);
            if (tp == null)
            {
                return RedirectToAction("ErroResult");
            }
            tp.Content = Helper.HtmlHelper.TransStringToHtml(tp.Content);
            var tu = new TopicUser
            {
                Topic = tp,
                UninUser = LoveDb.GetUninUser(tp.UserId),
            };
            ViewBag.UserId = tp.UserId;
            ViewBag.CurrentUserId = CheckValid();
            ViewBag.Sex = GetIdSex(tp.UserId);

            return View(tu);
        }
Example #11
0
 /// <summary>
 /// Create Status Type
 /// </summary>
 /// <param name="user">TopicUser</param>
 /// <returns>TopicStatusType</returns>
 private TopicStatusType CreateStatusType(TopicUser user)
 {
     return((TopicStatusType)Enum.Parse(typeof(TopicStatusType), user.TopicStatus.Status));
 }
        public ControllerTester()
        {
            Admin = new User
            {
                Id    = 1,
                UId   = AdminUId,
                Email = "*****@*****.**",
                Role  = "Administrator"
            };
            Student = new User
            {
                Id    = 2,
                UId   = StudentUId,
                Email = "*****@*****.**",
                Role  = "Student"
            };
            Supervisor = new User
            {
                Id    = 3,
                UId   = SupervisorUId,
                Email = "*****@*****.**",
                Role  = "Supervisor"
            };
            Reviewer = new User
            {
                Id    = 6,
                UId   = ReviewerUId,
                Email = "*****@*****.**",
                Role  = "Reviewer"
            };

            /*
             * Layer1   Layer2
             * |-tag1   |-tag2
             * |-tag3   |-tag4
             *
             * Layer Relation Rules:
             * Layer1 -> Layer2
             *
             * Annotation AnnotationTag Relations:
             * tag1 -> tag2
             * tag3 -> tag2
             * tag3 -> tag4
             */
            Layer1 = new Layer()
            {
                Id = 1, Name = "Time"
            };
            Layer2 = new Layer()
            {
                Id = 2, Name = "Perspective"
            };
            Tag1 = new AnnotationTag()
            {
                Id = 1, Layer = Layer1.Name
            };
            Tag2 = new AnnotationTag()
            {
                Id = 2, Layer = Layer2.Name
            };
            Tag3 = new AnnotationTag()
            {
                Id = 3, Layer = Layer1.Name
            };
            Tag4 = new AnnotationTag()
            {
                Id = 4, Layer = Layer2.Name
            };
            Tag1.ChildTags = new List <AnnotationTag>()
            {
                Tag3
            };
            Tag2.ChildTags = new List <AnnotationTag>()
            {
                Tag4
            };
            RelationRule12 = new AnnotationTagRelationRule()
            {
                Id = 3, SourceTagId = Tag1.Id, TargetTagId = Tag2.Id, Title = "Tag Relation Rule 1->2"
            };
            RelationRule32 = new AnnotationTagRelationRule()
            {
                Id = 5, SourceTagId = Tag3.Id, TargetTagId = Tag2.Id, Title = "Tag Relation Rule 3->2"
            };
            RelationRule34 = new AnnotationTagRelationRule()
            {
                Id = 7, SourceTagId = Tag3.Id, TargetTagId = Tag4.Id, Title = "Tag Relation Rule 3->4"
            };
            TagInstance1 = new AnnotationTagInstance(Tag1)
            {
                Id = 1
            };
            TagInstance2 = new AnnotationTagInstance(Tag2)
            {
                Id = 2
            };
            TagInstance3 = new AnnotationTagInstance(Tag3)
            {
                Id = 3
            };
            TagInstance4 = new AnnotationTagInstance(Tag4)
            {
                Id = 4
            };
            Relation12 = new AnnotationTagInstanceRelation(TagInstance1, TagInstance2)
            {
                Id = 3
            };
            Relation32 = new AnnotationTagInstanceRelation(TagInstance3, TagInstance2)
            {
                Id = 5
            };
            Relation34 = new AnnotationTagInstanceRelation(TagInstance3, TagInstance4)
            {
                Id = 7
            };
            LayerRelationRule = new LayerRelationRule()
            {
                Id            = 3,
                SourceLayer   = Layer1,
                SourceLayerId = Layer1.Id,
                TargetLayer   = Layer2,
                TargetLayerId = Layer2.Id,
                Color         = "test-color",
                ArrowStyle    = "test-style"
            };
            TopicOne = new Topic
            {
                Id          = 1,
                Title       = "Paderborner Dom",
                Status      = "InReview",
                Deadline    = new DateTime(2017, 5, 04),
                CreatedById = Supervisor.Id,
                Description = "Church"
            };
            TopicTwo = new Topic
            {
                Id          = 2,
                Title       = "Westerntor",
                Status      = "InProgress",
                Deadline    = new DateTime(2017, 4, 18),
                CreatedById = Supervisor.Id,
                Description = "Shopping"
            };
            UnreadNotification = new Notification
            {
                NotificationId = 1,
                UserId         = Student.Id,
                UpdaterId      = Supervisor.Id,
                Type           = NotificationType.TOPIC_ASSIGNED_TO,
                TopicId        = TopicOne.Id,
                IsRead         = false
            };
            ReadNotification = new Notification
            {
                NotificationId = 2,
                UserId         = Student.Id,
                UpdaterId      = Supervisor.Id,
                Type           = NotificationType.TOPIC_ASSIGNED_TO,
                TopicId        = TopicTwo.Id,
                IsRead         = true
            };
            Subscription = new Subscription // Adding a new subscription
            {
                SubscriptionId = 1,
                SubscriberId   = Student.Id,
                Subscriber     = Student,
                Type           = NotificationType.TOPIC_ASSIGNED_TO
            };
            SupervisorUser = new TopicUser
            {
                TopicId = TopicOne.Id,
                UserId  = Supervisor.Id,
                Role    = Supervisor.Role
            };
            StudentUser = new TopicUser
            {
                TopicId = TopicOne.Id,
                UserId  = Student.Id,
                Role    = Student.Role
            };
            ReviewerUser = new TopicUser
            {
                TopicId = TopicOne.Id,
                UserId  = Reviewer.Id,
                Role    = Reviewer.Role
            };
            FirstDocument = new Document
            {
                TopicId   = TopicOne.Id,
                UpdaterId = Admin.Id,
                Content   = "Hello"
            };
            TagInstanceForDocument = new AnnotationTagInstance
            {
                Id         = 5,
                TagModelId = Tag1.Id,
                Document   = FirstDocument
            };
        }