public async Task <Response> Update(CollaboratorViewModel model) { try { Encoded _encoded = !string.IsNullOrEmpty(model.Password) ? Crypto.EncryptPassword(model.Password) : null; var _entity = new Collaborator(model); _entity.SetActive(true); _entity.SetUpdatedAt(DateTime.UtcNow.AddHours(-3)); if (_encoded != null) { _entity.SetPassword(_encoded.Encrypted); } if (_entity.IsValid()) { return(Ok(await this._repository.Update(_entity), HttpMessage.Updated_Successfully)); } else { return(BadRequest(_entity.GetValidationResults())); } } catch (Exception except) { return(await InternalServerError(except.Message)); } }
public void ShoudCollaboratorIsValid() { bool collaboratorIsvalid = true; var colab = new Collaborator( _name, _document, _email, _phone, _addsress, _salary, _projectName, _birthDate, _jobTitle); bool valid = colab.IsValid(); Assert.AreEqual(valid, collaboratorIsvalid); }
public void ShoudRetunOneNotificationWhenProjectNameIsGreater10() { string projectName = "projetomaiordoque10fimjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj"; int qtdNotifications = 1; var colab = new Collaborator( _name, _document, _email, _phone, _addsress, _salary, projectName, _birthDate, _jobTitle); bool valid = colab.IsValid(); Assert.AreEqual(colab.Notifications.Count, qtdNotifications); Assert.AreEqual(valid, false); }
public void ShoudRetunOneNotificationWhenSalaryIsLess1000() { decimal salary = 900; int qtdNotifications = 1; var colab = new Collaborator( _name, _document, _email, _phone, _addsress, salary, _projectName, _birthDate, _jobTitle); bool valid = colab.IsValid(); Assert.AreEqual(colab.Notifications.Count, qtdNotifications); Assert.AreEqual(valid, false); }
public void ShoudReturnOneNotificationWhenYerOldCollaboratorIsLess18yers() { DateTime yerOld = DateTime.UtcNow.AddYears(-10); int qtdNotifications = 1; bool collaboratorIsvalid = false; var colab = new Collaborator( _name, _document, _email, _phone, _addsress, _salary, _projectName, yerOld, _jobTitle); bool valid = colab.IsValid(); Assert.AreEqual(colab.Notifications.Count, qtdNotifications); Assert.AreEqual(valid, collaboratorIsvalid); }
public void ShoudRetunTwoNotificationWhenProjectNameIsGreater10AndSalaryIsless100() { string projectName = "projetomaiordoque10fimooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"; decimal salary = 900; int qtdNotifications = 2; var colab = new Collaborator( _name, _document, _email, _phone, _addsress, salary, projectName, _birthDate, _jobTitle); bool valid = colab.IsValid(); Assert.AreEqual(colab.Notifications.Count, qtdNotifications); Assert.AreEqual(valid, false); }
public async Task <Response> Save(CollaboratorViewModel model) { try { Encoded _encoded = !string.IsNullOrEmpty(model.Password) ? Crypto.EncryptPassword(model.Password) : null; var _entity = new Collaborator(model); _entity.SetActive(true); _entity.SetCreatedAt(DateTime.UtcNow.AddHours(-3)); if (_encoded != null) { _entity.SetPassword(_encoded.Encrypted); } if (_entity.IsValid()) { var _isExist = await this._repository.GetByEmailAndRegistryCode(_entity.Email, _entity.RegistryCode) == null ? false : true; if (!_isExist) { return(Ok(await this._repository.Save(_entity), HttpMessage.Saved_Successfully)); } else { return(AlreadyExists()); } } else { return(await ParametersNotProvided(_entity.GetValidationResults())); } } catch (Exception except) { return(await InternalServerError(except.Message)); } }