示例#1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,PostId,ApplicationUserId,VoteValue,DateTime,NotifyMe,ReportType")] PostMetric postMetric)
        {
            if (id != postMetric.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(postMetric);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PostMetricExists(postMetric.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", postMetric.ApplicationUserId);
            ViewData["PostId"]            = new SelectList(_context.Posts, "Id", "Body", postMetric.PostId);
            return(View(postMetric));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,PostId,ApplicationUserId,VoteValue,DateTime,NotifyMe,ReportType")] PostMetric postMetric)
        {
            if (ModelState.IsValid)
            {
                postMetric.Id = Guid.NewGuid();
                postMetric.ApplicationUserId = _userManager.GetUserId(User);
                postMetric.DateTime          = DateTime.Now;
                _context.Add(postMetric);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["PostId"] = new SelectList(_context.Posts, "Id", "Title", postMetric.PostId);
            return(View(postMetric));
        }