public async Task <IOperationResult <bool> > Create(SystemUserCreateViewModel systemUserToCreate) { try { IOperationResult <bool> isValidSystemUserToCreateResult = ValidateUserToCreate(systemUserToCreate); if (!isValidSystemUserToCreateResult.Success) { return(OperationResult <bool> .Fail(isValidSystemUserToCreateResult.Message)); } systemUserToCreate.Password = _encrypService.EncrypText(systemUserToCreate.Password); SystemUser systemUser = _mapper.Map <SystemUser>(systemUserToCreate); _systemUserRepository.Create(systemUser); await _systemUserRepository.SaveAsync(); await SendActivationEmail(systemUser); return(OperationResult <bool> .Ok(true)); } catch { return(OperationResult <bool> .Fail("Ha ocurrido un error creando el usuario")); } }
public async Task CreateWhenUserNotCompleteShouldReturnOperationResultFailed(SystemUserCreateViewModel systemUserCreateViewModel) { SystemUserManager systemUserManager = new SystemUserManager(systemUserRepository, mapper, encrypService, emailService); IOperationResult <bool> actual = await systemUserManager.Create(systemUserCreateViewModel); Assert.IsFalse(actual.Success); Assert.AreEqual("Todos los campos son requeridos", actual.Message); }
public async Task <IActionResult> Create(SystemUserCreateViewModel systemUserToCreate) { IOperationResult <bool> createResult = await _systemUserManager.Create(systemUserToCreate); if (!createResult.Success) { return(BadRequest(createResult.Message)); } return(Ok()); }
private IOperationResult <bool> ValidateUserToCreate(SystemUserCreateViewModel systemUserToCreate) { foreach (var prop in systemUserToCreate.GetType().GetProperties()) { Object value = prop.GetValue(systemUserToCreate, null); if (value == null || string.IsNullOrWhiteSpace(value.ToString())) { return(OperationResult <bool> .Fail("Todos los campos son requeridos")); } } return(OperationResult <bool> .Ok(true)); }
public void SetUp() { systemUserRepository = Substitute.For <ISystemUserRepository>(); mapper = Substitute.For <IMapper>(); encrypService = Substitute.For <IEncrypService>(); emailService = Substitute.For <IEmailService>(); systemUserCreateViewModel = new SystemUserCreateViewModel { Name = "nombre prueba", Email = "correo prueba", Lastname = "apellido prueba", Username = "******", Password = "******" }; }