public async Task <IActionResult> AddComments([Bind("MatchID,CommentsContent")] MatchDetailViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Comment comment = new Comment();
                comment.commentscontent = viewModel.CommentsContent;

                comment.commentUsername = HttpContext.Session.GetString("tempUserName");

                string tempuserid = HttpContext.Session.GetString("tempUserId");

                //ViewData["Userid"] = tempuserid;

                ApplicationUser user = await db.Users.SingleOrDefaultAsync(m => m.Id == tempuserid);


                //Database query.
                Match match = await db.Matches
                              .SingleOrDefaultAsync(m => m.matchid == viewModel.MatchID);

                if (match == null)
                {
                    return(NotFound());
                }

                comment.RelatedMatch = match;
                comment.RelatedUser  = user;
                //Add the comments to the database.
                db.Comments.Add(comment);
                await db.SaveChangesAsync();

                viewModel = await GetMatchDetailViewModelFromMatch(match);
            }
            return(View(viewModel));
        }
Пример #2
0
 public MatchDetail()
 {
     InitializeComponent();
     SetText();
     _vm = new MatchDetailViewModel(MainPage.SelectedMatch);
     this.DataContext = _vm;
 }
Пример #3
0
        public MatchDetailPage()
        {
            int id = 444242;

            InitializeComponent();
            BindingContext = viewModel = new MatchDetailViewModel(id);
        }
        /// <summary>
        /// Set the comment list for viewmodel.
        /// </summary>
        /// <param name="match"></param>
        /// <returns>viewModel</returns>
        private async Task <MatchDetailViewModel> GetMatchDetailViewModelFromMatch(Match match)
        {
            MatchDetailViewModel viewModel = new MatchDetailViewModel();

            viewModel.Match = match;

            List <Comment> comments = await db.Comments.Include(u => u.RelatedUser)
                                      .Where(m => m.RelatedMatch == match).ToListAsync();

            viewModel.Comments = comments;

            return(viewModel);
        }
        /// <summary>
        /// HttpGet method for viewing match detail and adding comments.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>View and viewmodel</returns>
        public async Task <IActionResult> AddComments(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            //Database query.
            Match match = await db.Matches
                          .SingleOrDefaultAsync(m => m.matchid == id);

            if (match == null)
            {
                return(NotFound());
            }


            MatchDetailViewModel viewModel = await GetMatchDetailViewModelFromMatch(match);

            return(View(viewModel));
        }
Пример #6
0
        public MatchDetailPage()
        {
            InitializeComponent();

            BindingContext = viewModel = new MatchDetailViewModel();
        }
Пример #7
0
        public MatchDetailPage(MatchDetailViewModel viewModel)
        {
            InitializeComponent();

            BindingContext = this.viewModel = viewModel;
        }