Example #1
0
        public async Task <SaveResult> CambiarClave(Guid userId, string claveAnterior, string nuevaClave)
        {
            try
            {
                _userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(UnitOfWork.Db));

                var usuario = GetById(userId);

                var applicationUser = await _userManager.FindByIdAsync(usuario.ApplicationUserId);

                IdentityResult result;

                if (applicationUser.PasswordHash != null)
                {
                    result = await _userManager.ChangePasswordAsync(usuario.ApplicationUserId, claveAnterior, nuevaClave);
                }
                else
                {
                    result = await _userManager.AddPasswordAsync(usuario.ApplicationUserId, nuevaClave);
                }

                return(result.Succeeded ? SaveResult.Success() : SaveResult.Failed(result.Errors));
            }
            catch (Exception ex)
            {
                return(ex.SaveResult());
            }
            finally
            {
                _userManager.Dispose();
            }
        }
Example #2
0
        public override async Task <SaveResult> SaveAsync(Personas entity)
        {
            var result = FirstOrDefault(e => e.Id != entity.Id && e.Identificacion == entity.Identificacion && e.EmpresaId == entity.EmpresaId);

            if (result != null)
            {
                return(SaveResult.Failed(new[] { string.Format("Identificacion: {0} ya asignado a {1} {2} {3} {4} ", result.Identificacion, result.PrimerNombre, result.SegundoNombre, result.PrimerApellido, result.SegundoApellido) }));
            }

            return(await base.SaveAsync(entity));
        }
Example #3
0
        public override async Task <SaveResult> SaveAsync(TEntity entity)
        {
            var result = FirstOrDefault(e => e.Id != entity.Id && e.Codigo == entity.Codigo);

            if (result != null)
            {
                return(SaveResult.Failed(new[] { string.Format("Código: {0} ya asignado a {1} ", result.Codigo, result.Descripcion) }));
            }

            return(await base.SaveAsync(entity));
        }