Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Text")] Idea idea)
        {
            if (ModelState.IsValid)
            {
                User user   = (User)RouteData.Values["User"];
                Idea dbIdea =
                    _context
                    .Idea
                    .Include(m => m.User)
                    .Where(u => u.UserId == user.Id)
                    .SingleOrDefault(m => m.Id == id);

                if (dbIdea == null || dbIdea.Approved)
                {
                    return(NotFound());
                }

                try
                {
                    dbIdea.Text = idea.Text;
                    _context.Update(dbIdea);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(MyIdeas)));
            }
            return(View(idea));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,UserID,Title,Problem,Solution,Status,Team,UploadDate")] Idea idea)
        {
            // if the idea isn't found return null
            // error case
            if (id != idea.ID)
            {
                return(NotFound());
            }
            // grab the user associated with this idea
            var user = _userManager.FindByIdAsync(idea.UserID).Result;

            idea.UploadDate = idea.UploadDate;
            idea.UserID     = user.Id;
            idea.Name       = user.Firstname + " " + user.Lastname;
            idea.Team       = user.Team;
            idea.UploadDate = DateTime.Now;
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(idea);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!IdeaExists(idea.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(idea));
        }