Ejemplo n.º 1
0
        public async Task <IWriterResult> UpdateUser(UpdateUserModal model)
        {
            using (var context = DataContextFactory.CreateContext())
            {
                var user = await context.Users.FirstOrDefaultAsync(x => x.Id == model.Id);

                if (user == null)
                {
                    return(new WriterResult(false, "User not found"));
                }

                user.UserName       = model.UserName;
                user.Email          = model.Email;
                user.EmailConfirmed = model.IsEmailConfirmed;
                if (model.IsLocked && !user.LockoutEndDateUtc.HasValue)
                {
                    user.LockoutEndDateUtc = DateTime.UtcNow.AddYears(1);
                    user.SecurityStamp     = Guid.NewGuid().ToString();
                }

                if (!model.IsLocked && user.LockoutEndDateUtc.HasValue)
                {
                    user.LockoutEndDateUtc = null;
                }

                await context.SaveChangesAsync();

                return(new WriterResult(true));
            }
        }
Ejemplo n.º 2
0
        public async Task <IdentityResult> UpdateAccount(UpdateUserModal user)
        {
            var userUpdate = _userManager.FindByName(user.UserName);

            userUpdate.FullName    = user.FullName;
            userUpdate.Address     = user.Address;
            userUpdate.Email       = user.Email;
            userUpdate.PhoneNumber = user.PhoneNumber;
            var result = await _userManager.UpdateAsync(userUpdate);

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> UpdateAccount(UpdateUserModal userModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            IdentityResult result = await _repo.UpdateAccount(userModel);

            if (result.Succeeded)
            {
                return(Ok());
            }
            return(BadRequest());
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> UpdateUserModal(UpdateUserModal model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await UserWriter.UpdateUser(model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View(model));
            }

            return(CloseModalSuccess());
        }