Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Text,Link,ContestId")] NewsContest newsContest)
        {
            if (id != newsContest.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    ViewData["ContestName"] = _context.Contests.FirstOrDefault(x => x.Id == newsContest.ContestId).Name;
                    ViewData["ContestId"]   = newsContest.ContestId;

                    _context.Update(newsContest);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NewsContestExists(newsContest.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("News", "Contests", new { contestId = newsContest.ContestId }));
            }
            ViewData["ContestId"] = new SelectList(_context.Contests, "Id", "Name", newsContest.ContestId);
            return(View(newsContest));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Text,Link,ContestId")] NewsContest newsContest, IFormFile uploadPhoto)
        {
            if (ModelState.IsValid)
            {
                newsContest.DateCreated = DateTime.Now;
                newsContest.PhotoId     = await uploadPhoto.AddFileContestDatabase(_context, _appEnvironment);

                _context.Add(newsContest);
                await _context.SaveChangesAsync();

                return(RedirectToAction("News", "Contests", new { contestId = newsContest.ContestId }));
            }
            ViewData["ContestId"] = new SelectList(_context.Contests, "Id", "Name", newsContest.ContestId);
            return(View(newsContest));
        }