예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id", "Username", "TempPassword", "FirstName", "LastName")] AdminUser user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }

            //only set password if value exists
            if (!String.IsNullOrWhiteSpace(user.TempPassword))
            {
                user.SetPassword(user.TempPassword);
            }


            if (ModelState.IsValid)
            {
                try
                {
                    if (user.Id == 0)
                    {
                        //new user
                        _work.AdminUsers.Insert(user);
                    }
                    else
                    {
                        //existing user
                        _work.AdminUsers.Update(user);
                    }

                    //save
                    await _work.Save();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            return(View(user));
        }