public ActionResult NewTopic(TopicVM vm)
        {
            if (repo.GetById(vm.ClassId) == null)
            {
                return(HttpNotFound());
            }


            if (ModelState.IsValid)
            {
                var top = new ClassTopic
                {
                    Topic   = vm.Topic,
                    ClassId = vm.ClassId,
                    Order   = vm.Order
                };

                _db.ClassTopic.Add(top);
                _db.SaveChanges();

                return(PartialView("PartialAllClassTopics", GetAllTopics(top.ClassId)));
            }

            return(PartialView("PartialClassTopic", vm));
        }
        public void CreateTopic(TopicVM vm)
        {
            var   isNewTopic = vm.TopicId == null && DataContext.Topics.FirstOrDefault(t => t.TopicTitle == vm.Title) == null;
            Topic topic      = null;

            if (isNewTopic)
            {
                topic = new Topic()
                {
                    TopicTitle = vm.Title,
                    TopicLink  = vm.Link,
                    TopicAdded = DateTime.Now
                };

                DataContext.Topics.Add(topic);
            }
            else
            {
                topic = DataContext.Topics.SingleOrDefault(t => t.TopicId == vm.TopicId);
                if (topic != null)
                {
                    topic.TopicTitle = vm.Title;
                    topic.TopicLink  = vm.Link;
                }
            }
        }
예제 #3
0
        public IActionResult Index(int id)
        {
            Topic topic = _context.Topics.Find(id);

            TopicVM topicVM = new TopicVM
            {
                TopicViewId   = topic.TopicId,
                TopicViewName = topic.TopicName
            };

            List <ThreadVM> threadVMList = new List <ThreadVM>();

            List <Thread> threads = _context.Threads.Where(x => x.TopicId == id).ToList();

            foreach (Thread t in threads)
            {
                threadVMList.Add(
                    new ThreadVM
                {
                    ThreadViewId   = t.ThreadId,
                    ThreadViewName = t.ThreadName
                });
            }

            topicVM.Threads = threadVMList;

            return(View(topicVM));
        }
예제 #4
0
        public ActionResult EditTopic(int id)
        {
            TopicVM topicVM = Mapper.Map <TopicVM>(_chapterService.GetTopicById(id));

            topicVM.SubjectId = topicVM.Chapter.SubjectId;
            return(View(topicVM));
        }
 public SendDynamicDialog(DynamicItemDisplayModel dynamicItem)
 {
     this.InitializeComponent();
     emoteVM       = new EmoteVM();
     atVM          = new AtVM();
     topicVM       = new TopicVM();
     sendDynamicVM = new SendDynamicVM(dynamicItem);
 }
예제 #6
0
        public Response <TopicVM> Post([FromBody] TopicVM value)
        {
            var service = new Services.Content.TopicService(Context, CurrentUser);

            LogService.Write("Saved Topic", value.TopicId.ToString());

            return(new Response <TopicVM>(service.SaveTopic(value)));
        }
 public SendDynamicDialog()
 {
     this.InitializeComponent();
     emoteVM       = new EmoteVM();
     atVM          = new AtVM();
     sendDynamicVM = new SendDynamicVM();
     topicVM       = new TopicVM();
 }
예제 #8
0
        public ActionResult CreateTopic(int id)
        {
            TopicVM topicVM = new TopicVM
            {
                ChapterId = id,
                SubjectId = _chapterService.GetById(id).SubjectId
            };

            return(View(topicVM));
        }
예제 #9
0
        public void SaveTopicTest()
        {
            var newTopic = new TopicVM()
            {
                Name = "New Topic"
            };

            this.service.SaveTopic(newTopic);

            mockContext.Verify(m => m.Topics.Add(It.IsAny <Topic>()), Times.Once);
        }
예제 #10
0
 public ActionResult EditTopic(TopicVM topicVM)
 {
     if (!_chapterService.TryEditTopic(topicVM))
     {
         return(View());
     }
     else
     {
         return(RedirectToAction("Chapter", new { id = topicVM.SubjectId }));
     }
 }
예제 #11
0
 public ActionResult Topic(TopicVM topicVM)
 {
     if (topicVM == null)
     {
         return(PartialView(Mapper.Map <Topic, TopicVM>(_chapterService.GetFirstTopicFromChaper(_chapterService.GetFirstChapter().Id))));
     }
     else
     {
         return(PartialView(topicVM));
     }
 }
예제 #12
0
        public void SaveExistingTest()
        {
            var existingTopic = new TopicVM()
            {
                TopicId = existingTopicId,
                Name    = "Existing Topic"
            };

            this.service.SaveTopic(existingTopic);

            mockContext.Verify(m => m.Topics.Update(It.IsAny <Topic>()), Times.Once);
        }
        /// <summary>
        /// Returns all topics and playlist related to a particular class
        /// </summary>
        /// <param name="classId">The class id to query topics by</param>
        /// <returns></returns>

        private TopicVM GetAllTopics(int classId)
        {
            topic = ClassTopicRepository.CreateRepo();

            var mod = new TopicVM
            {
                AllTopics = topic.GetByClassId(classId),
                ClassId   = classId
            };

            return(mod);
        }
예제 #14
0
 public ActionResult CreateTopic(TopicVM topicVM)
 {
     if (_chapterService.TrySaveTopic(topicVM))
     {
         return(RedirectToAction("Chapter", "Chapter", new { id = topicVM.SubjectId }));
     }
     else
     {
         ModelState.AddModelError("credentials", "Перевірте, будь ласка, на заповненість поля.");
         return(View(topicVM));
     }
 }
예제 #15
0
        public TopicVM SaveTopic(TopicVM topic)
        {
            var  dbTopic         = GetTopic(topic.TopicId);
            var  dbSameNameCount = this.mainContext.Topics.Where(t => t.Name.ToLower() == topic.Name.ToLower() && t.TopicId != topic.TopicId).Count();
            Guid TopicId         = Guid.Empty;

            if (dbSameNameCount == 0)
            {
                if (dbTopic is null)
                {
                    var newTopic = new Topic();

                    if (topic.TopicId == Guid.Empty)
                    {
                        newTopic.TopicId = Guid.NewGuid();
                    }
                    else
                    {
                        newTopic.TopicId = topic.TopicId;
                    }
                    newTopic.Name        = topic.Name;
                    newTopic.Description = topic.Description;
                    newTopic.CreatedBy   = this.Actor.UserId;

                    if (this.Actor.Roles.Contains("Admin"))
                    {
                        newTopic.Elligible = topic.Elligible;
                    }

                    TopicId = newTopic.TopicId;
                    this.mainContext.Topics.Add(newTopic);
                }
                else if (this.Actor.Roles.Contains("Admin"))
                {
                    dbTopic.Name        = topic.Name;
                    dbTopic.Description = topic.Description;
                    dbTopic.Elligible   = topic.Elligible;
                    TopicId             = dbTopic.TopicId;
                    this.mainContext.Topics.Update(dbTopic);
                }

                if (this.Actor.Roles.Contains("Admin") && TopicId != Guid.Empty)
                {
                    SaveKeywords(topic.Keywords, TopicId);
                    SaveLinks(topic.Links, TopicId);
                }

                this.mainContext.SaveChanges();
            }

            return(GetTopicVM(topic.TopicId));
        }
예제 #16
0
        public ActionResult Topics(int id)
        {
            Topic   topic   = _chapterService.GetTopicById(id);
            TopicVM topicVM = Mapper.Map <Topic, TopicVM>(topic);

            var res = JsonConvert.SerializeObject(topic, new JsonSerializerSettings
            {
                ContractResolver      = new CamelCasePropertyNamesContractResolver(),
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            return(Content(res, "application/json"));
        }
예제 #17
0
        public void DeleteImages(TopicVM topic)
        {
            var oldFiles = _unitOfWork.FileRepository.GetByTopicId(topic.Id);

            foreach (var file in oldFiles)
            {
                if (!topic.Text.Contains("Download/File/" + file.Id))
                {
                    _unitOfWork.FileRepository.Remove(file);
                }
            }

            _unitOfWork.SaveChanges();
        }
예제 #18
0
        public ActionResult Index(int page = 1)
        {
            TopicVM topicVM = new TopicVM
            {
                Topics = db.Topics
                         .OrderBy(t => t.TopicId)
                         .Skip((page - 1) * PAGE_SIZE)
                         .Take(PAGE_SIZE),
                PagingInfo = new PagingInfo
                {
                    CurrentPage  = page,
                    ItemsPerPage = PAGE_SIZE,
                    TotalItems   = db.Topics.Count()
                }
            };

            return(View(topicVM));
        }
예제 #19
0
 public MentorshipVM(Mentorship mentorship, TopicVM Topic) : base(mentorship.LearnerUserId, mentorship.TopicId)
 {
     this.MentorshipId      = mentorship.MentorshipId;
     this.LearnerUserId     = mentorship.LearnerUserId;
     this.LearnerContact    = mentorship.LearnerContact;
     this.MentorUserId      = mentorship.MentorUserId;
     this.MentorContact     = mentorship.MentorContact;
     this.TopicId           = mentorship.TopicId;
     this.Active            = mentorship.Active;
     this.CreatedDate       = mentorship.CreatedDate;
     this.StartDate         = mentorship.StartDate;
     this.EndDate           = mentorship.EndDate;
     this.LearnerClosed     = mentorship.LearnerClosed;
     this.LearnerClosedDate = mentorship.LearnerClosedDate;
     this.MentorClosed      = mentorship.MentorClosed;
     this.MentorClosedDate  = mentorship.MentorClosedDate;
     this.Topic             = Topic;
     this.HasMentor         = (mentorship.MentorUserId != Guid.Empty);
 }
예제 #20
0
        public TopicVM GetTopicVM(Guid topicId)
        {
            var     dbTopic  = GetTopic(topicId);
            TopicVM rtnTopic = new TopicVM();

            if (dbTopic != null)
            {
                var dbUserTopic = GetUserTopics(this.Actor.UserId, topicId).Select(ut => new UserTopicVM(ut)).FirstOrDefault();
                rtnTopic = new TopicVM(dbTopic, dbUserTopic);

                rtnTopic.Links           = this.mainContext.Links.Where(l => l.Active).Join(this.mainContext.TopicLinks.Where(tl => tl.TopicId == rtnTopic.TopicId && tl.Active), l => l.LinkId, tl => tl.LinkId, (l, tl) => l).OrderBy(l => l.Name).ToList();
                rtnTopic.Keywords        = this.mainContext.Keywords.Where(k => k.Active).Join(this.mainContext.TopicKeywords.Where(tk => tk.TopicId == rtnTopic.TopicId), k => k.KeywordId, tk => tk.KeywordId, (k, tk) => k).OrderBy(l => l.Name).ToList();
                rtnTopic.UserMentorships = MentorshipService.GetUserMentorships(this.Actor.UserId, topicId);

                if (dbUserTopic != null && rtnTopic.UserTopic.Status == TopicStatus.Mentor)
                {
                    rtnTopic.Mentorships = MentorshipService.OpenMentorships(this.Actor.UserId, topicId).Select(m => new MentorshipVM(m, null)).ToList();
                }
            }

            return(rtnTopic);
        }
예제 #21
0
        public bool TryEditTopic(TopicVM topic)
        {
            if (String.IsNullOrEmpty(topic.Name) || String.IsNullOrEmpty(topic.Text))
            {
                return(false);
            }
            else
            {
                _fileService.DeleteImages(topic);

                var newFiles = _fileService.SaveImages(_httpContext.Request.Files, topic.Id);
                foreach (var file in newFiles)
                {
                    topic.Text = topic.Text.Replace(file.Temporary, $"/Download/File/{file.Id}");
                }

                Topic originalTopic = GetTopicById(topic.Id);
                originalTopic.Name = topic.Name;
                originalTopic.Text = topic.Text;
                _unitOfWork.SaveChanges();
                return(true);
            }
        }
예제 #22
0
        public bool TrySaveTopic(TopicVM topicVM)
        {
            if (String.IsNullOrEmpty(topicVM.Name) || String.IsNullOrEmpty(topicVM.Text))
            {
                return(false);
            }
            else
            {
                var topic = Mapper.Map <Topic>(topicVM);

                topic.AuthorId = _unitOfWork.UserRepository.GetActualUserById <Teacher>(UserId).Id;

                topic = _unitOfWork.TopicRepository.Add(topic);
                _unitOfWork.SaveChanges();
                var files = _fileService.SaveImages(_httpContext.Request.Files, topic.Id);
                foreach (var file in files)
                {
                    topic.Text = topic.Text.Replace(file.Temporary, $"/Download/File/{file.Id.ToString()}");
                }
                _unitOfWork.SaveChanges();

                return(true);
            }
        }
 public HomeTopicPage()
 {
     this.InitializeComponent();
     this.Loaded += HomeTopicPage_Loaded;
     topicVM      = new TopicVM();
 }
예제 #24
0
        public void GetPollByIdSuccess(string pollId)
        {
            List <Topic> topic = new List <Topic>()
            {
                new Topic()
                {
                    id         = "01",
                    TopicName  = "โหวตข้าว",
                    ChoiceList = new List <Choice>()
                    {
                        new Choice()
                        {
                            Id = "01", Name = "กะเพาหมูกรอบ", CraeteBy = "ake", CraeteDate = DateTime.MinValue
                        },
                        new Choice()
                        {
                            Id = "02", Name = "กะเพาหมูสับ", CraeteBy = "ake", CraeteDate = DateTime.MinValue
                        },
                    },
                    CreateBy   = "ake",
                    CreateDate = DateTime.UtcNow,
                    VoteList   = new List <Vote>()
                    {
                        new Vote()
                        {
                            Id = "01", ChoiceId = "01", Rating = 5, UserName = "******", CreateDate = DateTime.MinValue
                        },
                        new Vote()
                        {
                            Id = "02", ChoiceId = "01", Rating = 4, UserName = "******", CreateDate = DateTime.MinValue
                        },
                        new Vote()
                        {
                            Id = "03", ChoiceId = "02", Rating = 3, UserName = "******", CreateDate = DateTime.MinValue
                        },
                        new Vote()
                        {
                            Id = "04", ChoiceId = "01", Rating = 5, UserName = "******", CreateDate = DateTime.MinValue
                        },
                    },
                }
            };

            dac.Setup(dac => dac.GetTopic(It.IsAny <Expression <Func <Topic, bool> > >()))
            .Returns <Expression <Func <Topic, bool> > >((expression) => topic.FirstOrDefault(expression.Compile()));


            var poll = facade.GetPollById(pollId);

            var expected = new TopicVM()
            {
                id         = "01",
                CreateBy   = "ake",
                CreateDate = DateTime.UtcNow,
                TopicName  = "โหวตข้าว",
                VoteCount  = 4,
                ChoiceList = new List <ChoiceVM>()
                {
                    new ChoiceVM()
                    {
                        Id       = "01", Name = "กะเพาหมูกรอบ", CraeteBy = "ake", CraeteDate = DateTime.MinValue, Rating = "4.67", VoteCount = 3,
                        VoteList = new List <VoteVM>()
                        {
                            new VoteVM()
                            {
                                Id = "01", ChoiceId = "01", Rating = 5, UserName = "******", CreateDate = DateTime.MinValue
                            },
                            new VoteVM()
                            {
                                Id = "02", ChoiceId = "01", Rating = 4, UserName = "******", CreateDate = DateTime.MinValue
                            },
                            new VoteVM()
                            {
                                Id = "04", ChoiceId = "01", Rating = 5, UserName = "******", CreateDate = DateTime.MinValue
                            },
                        }
                    },
                    new ChoiceVM()
                    {
                        Id       = "02", Name = "กะเพาหมูสับ", CraeteBy = "ake", CraeteDate = DateTime.MinValue, Rating = "3.00", VoteCount = 1,
                        VoteList = new List <VoteVM>()
                        {
                            new VoteVM()
                            {
                                Id = "03", ChoiceId = "02", Rating = 3, UserName = "******", CreateDate = DateTime.MinValue
                            },
                        }
                    },
                },
            };


            expected.Should().BeEquivalentTo(poll, option =>
                                             option.Excluding(x => x.CreateDate));
        }
예제 #25
0
 public MentorshipVM(Guid LearnerUserId, Guid TopicId, TopicVM Topic) : base(LearnerUserId, TopicId)
 {
     this.Topic = Topic;
 }