public ActionResult BillPage(string billID, string title)
        {
            ViewBag.BillID    = billID;
            ViewBag.BillTitle = title;

            if (billID == null || title == null)
            {
                return(HttpNotFound());
            }
            var list             = new List <UserComment>();
            DiscussViewModel dvw = new DiscussViewModel();
            //as a template
            string uid     = User.Identity.GetUserId();
            var    comment = uc.CreateComment(billID, title, uid);

            //fill the viewmodel
            dvw.comment = comment;
            list        = uc.GetAllCommentsByBillId(billID);
            if (list.Count() == 0)
            {
                ViewBag.Message = "Hi there is no comments yet, be the first one to leave a comment!";
            }
            dvw.list = list;

            return(View(dvw));
        }
예제 #2
0
        public IActionResult Detail(long id, int page = 1)
        {
            Room             room        = _roomService.GetRoom(id);
            DiscussViewModel discussions = _discussionService.GetDiscussions(id, page);

            ViewBag.Disc = discussions;
            return(View(room));
        }
        /// <summary>
        /// Passes elements from the DiscussViewModel into the view.
        /// </summary>
        /// <param name="bill_id">The ID of a bill.</param>
        /// <param name="ttl">The title of a bill.</param>
        /// <param name="uid">The ID of the user.</param>
        /// <returns>A DiscuessViewModel with elements passed into it.</returns>
        public DiscussViewModel FillViewModel(string bill_id, string ttl, string uid)
        {
            DiscussViewModel dvw = new DiscussViewModel();

            dvw.comment = uc.CreateComment(bill_id, ttl, uid);
            var list = new List <UserComment>();

            list = uc.GetAllCommentsByBillId(bill_id);
            if (list.Count() == 0)
            {
                ViewBag.Message = "Hi there is no comments yet, be the first one to leave a comment!";
            }
            dvw.list = list;

            return(dvw);
        }
        public ActionResult CreateComments(DiscussViewModel dvw)
        {
            //Debug.WriteLine("bill id: " + dvw.comment.blid + "comment: " + dvw.comment.comt);
            if (ModelState.IsValid)
            {
                try
                {
                    uc.AddComment(dvw.comment);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "unable to save the changes: " + ex.Message);
                }
                // redirect to the action with the right value, for testing
                return(RedirectToAction("CreateComments", new { bill_id = dvw.comment.blid, ttl = dvw.comment.bltitle }));
            }

            return(View(ViewBag.Message = "view model is not valid"));
        }
예제 #5
0
        public DiscussViewModel GetDiscussions(long roomid, int page)
        {
            int pageSize = 20;
            IQueryable <Discussion> source = _db.discussions
                                             .Include(m => m.room)
                                             .Include(m => m.author)
                                             .Where(m => m.room.id == roomid)
                                             .OrderBy(m => m.id);

            var              count         = source.Count();
            var              items         = source.Skip((page - 1) * pageSize).Take(pageSize).ToList();
            PageViewModel    pageViewModel = new PageViewModel(count, page, pageSize);
            DiscussViewModel viewModel     = new DiscussViewModel
            {
                PageViewModel = pageViewModel,
                discussions   = items
            };

            return(viewModel);
        }
예제 #6
0
        public async Task <IActionResult> Discuss(int id)
        {
            //var topic = _context.TopicModels.Include(x => x.Messages).FirstOrDefault(x => x.Id == id);//.FindAsync(id);
            var topic = await _context.TopicModels.FindAsync(id);

            if (topic == null)
            {
                return(NotFound());
            }
            bool isAuntificated = User.Identity.IsAuthenticated;
            User user           = null;

            if (isAuntificated)
            {
                user = await _userManager.FindByNameAsync(User.Identity.Name);
            }
            bool isAdmin = false;

            if (isAuntificated && (await _userManager.IsInRoleAsync(user, "admin") || user.Id == topic.UserId))
            {
                isAdmin = true;
            }
            var model = new DiscussViewModel
            {
                Id           = topic.Id,
                Name         = topic.Name,
                Description  = topic.Description,
                CreationTime = topic.CreationTime,
                User         = user,
                Messages     = _context.TopicMessages.Where(x => x.TopicId == topic.Id).OrderBy(x => x.CreationTime).ToList(),
                IsAdmin      = isAdmin
            };

            foreach (var message in model.Messages)
            {
                message.User = await _userManager.FindByIdAsync(message.UserId);
            }
            return(View(model));
        }
예제 #7
0
        public ActionResult Index(int id)
        {
            TFDBLibrary.TakeFiveDBEntities db = new TFDBLibrary.TakeFiveDBEntities();
            var query = from c in db.discuss
                        where c.p_id == id
                        orderby c.d_id descending
                        select new DiscussViewModel {
                DId      = c.d_id, PId = c.p_id, MId = c.Id,
                DContent = c.d_content, DCrateDate = c.d_crateDate,
                DGreat   = c.d_great, DModifyDate = c.d_modifyDate
            };

            if (query.Count() > 0)
            {
                return(PartialView("_Discuss", query));
            }
            else
            {
                DiscussViewModel non = new DiscussViewModel();
                non.PId = id;
                return(PartialView("_NonDiscuss", non));
            }
        }
        public void SetupMoq()
        {
            moq = new Mock <IUCCRepository>();


            x = new DiscussViewModel
            {
                comment = new UserComment {
                    id = 0, blid = "wa20156", comt = "Very good", netuid = "abc", bltitle = "study while you are still can"
                },
                list = new List <UserComment> {
                    new UserComment {
                        id = 0, blid = "wa20156", comt = "Very good", netuid = "abc", bltitle = "study while you are still can"
                    },
                    new UserComment {
                        id = 1, blid = "or20156", comt = "well done", netuid = "xyz", bltitle = "do something while you are still alive"
                    },
                    new UserComment {
                        id = 2, blid = "ca20156", comt = "space X is cool", netuid = "jkl", bltitle = "what is up"
                    },
                    new UserComment {
                        id = 3, blid = "ca20156", comt = "space Z is cool", netuid = "zzz", bltitle = "what is up"
                    }
                }
            };

            //fake user comment
            moq.Setup(m => m.UserComments).Returns(
                new UserComment[] {
                new UserComment {
                    id = 0, blid = "wa20156", comt = "Very good", netuid = "abc", bltitle = "study while you are still can"
                },
                new UserComment {
                    id = 1, blid = "or20156", comt = "well done", netuid = "xyz", bltitle = "do something while you are still alive"
                },
                new UserComment {
                    id = 2, blid = "ca20156", comt = "space X is cool", netuid = "jkl", bltitle = "what is up"
                },
                new UserComment {
                    id = 3, blid = "ca20156", comt = "space Z is cool", netuid = "zzz", bltitle = "what is up!"
                }
            });
            //fake user vote
            moq.Setup(m => m.UserVotes).Returns(
                new UserVote[] {
                new UserVote {
                    id = 0, ucblid = "or20156", ucnetuid = "xyz", votebit = 1
                },
                new UserVote {
                    id = 1, ucblid = "ca20156", ucnetuid = "jkl", votebit = 0
                },
                new UserVote {
                    id = 2, ucblid = "wa20156", ucnetuid = "abc", votebit = 0
                },
                new UserVote {
                    id = 3, ucblid = "or20156", ucnetuid = "zzz", votebit = 1
                },
            });
            // fake users
            moq.Setup(m => m.Users).Returns(
                new AspNetUser[] {
                new AspNetUser {
                    Id = "abc", Email = "*****@*****.**", EmailConfirmed = false, PhoneNumber = "123456", PhoneNumberConfirmed = true, UserName = "******", County = "washington"
                },
                new AspNetUser {
                    Id = "xyz", Email = "*****@*****.**", EmailConfirmed = true, PhoneNumber = "987654", PhoneNumberConfirmed = false, UserName = "******", County = "polk"
                },
                new AspNetUser {
                    Id = "jkl", Email = "*****@*****.**", EmailConfirmed = false, PhoneNumber = "668855", PhoneNumberConfirmed = true, UserName = "******", County = "clark"
                },
                new AspNetUser {
                    Id = "zzz", Email = "*****@*****.**", EmailConfirmed = false, PhoneNumber = "668856", PhoneNumberConfirmed = true, UserName = "******", County = "clark"
                }
            });
            moq.Setup(m => m.DeleteCommentByCommentId(It.IsAny <int?>())).Callback(() => comments = comments - 1);
            moq.Setup(m => m.FindCommentByCommentId(0)).Returns(
                new UserComment {
                id = 0, blid = "wa20156", comt = "Very good", netuid = "abc", bltitle = "study while you are still can"
            });
            moq.Setup(m => m.PhoneNumberConfirmed(It.IsAny <string>())).Returns(true);
            moq.Setup(m => m.AddComment(It.IsAny <UserComment>())).Callback(() => { comments = ++comments; commentaddedcount = ++commentaddedcount; });
            //moq.Setup(m => m.FindCommentsByUserId(It.IsAny<string>())).Returns(
            //new List<UserComment>{
            //    new UserComment {id = 2, blid="ca20156",comt="space X is cool",netuid="jkl",bltitle="what is up" },
            //    new UserComment {id = 3, blid="ca20156",comt="space Z is cool",netuid="zzz",bltitle="what is up!" }
            // });
        }