コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,UserName")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("PostID,ReleaseDate")] Post post)
        {
            if (id != post.PostID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(post);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PostExists(post.PostID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(post));
        }
コード例 #3
0
        public async Task Update(UserData userData)
        {
            var userToUpdate = await GetByUserId(userData.UserId);

            userToUpdate.Firstname   = userData.Firstname;
            userToUpdate.Lastname    = userData.Lastname;
            userToUpdate.Age         = userData.Age;
            userToUpdate.Description = userData.Description;
            userToUpdate.City        = userData.City;
            _context.Update(userToUpdate);
            await _context.SaveChangesAsync();
        }