Пример #1
0
        public async Task <IActionResult> PutFeed([FromRoute] int id, [FromBody] Feed feed)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != feed.FeedId)
            {
                return(BadRequest());
            }

            _context.Entry(feed).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FeedExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("FeedId,FeedTitle,FeedLike,FeedCreatedDateTime,FeedCreatedUser,FeedValidFlag")] Feed feed)
        {
            if (ModelState.IsValid)
            {
                _context.Add(feed);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(feed));
        }
Пример #3
0
        public async Task <ActionResult> Create([Bind("FeedTitle")] Feed feed)
        {
            var user = await this._userManager.GetUserAsync(User);

            if (user == null)
            {
                //throw new Exception("尚未認證");
            }

            feed.FeedCreatedDateTime = DateTime.Now;
            feed.FeedCreatedUser     = user.Email;
            feed.FeedLike            = 0;
            feed.FeedValidFlag       = true;

            // TODO: Add insert logic here
            if (ModelState.IsValid)
            {
                using (var context = new VoteItDBContext())
                {
                    context.Add(feed);
                    await context.SaveChangesAsync();
                }

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