private void ValidateNOK(NOKEntity nok, ElementBL elementBL) { if (nok == null) { throw new ArgumentNullException("nok"); } CommonEntities.ElementEntity _nokMetadata = base.GetElementByName(EntityNames.NOKEntityName, elementBL); NOKHelper nokHelper = new NOKHelper(_nokMetadata); ValidationResults result = nokHelper.Validate(nok); if (!result.IsValid) { StringBuilder sb = new StringBuilder(); foreach (ValidationResult vr in result) { sb.AppendLine(); sb.AppendFormat("■ {0}", vr.Message); } throw new Exception( string.Format(Properties.Resources.ERROR_nokValidationError, sb)); } //base.ValidatePerson(nok.Person, elementBL); }
public NOKEntity Save(NOKEntity nok, bool forceSave, out PersonAddressListDTO[] homonymPersons) { try { if (nok == null) { throw new ArgumentNullException("nok"); } ElementBL _elementBL = new ElementBL(); homonymPersons = null; switch (nok.EditStatus.Value) { case StatusEntityValue.Deleted: return(nok); case StatusEntityValue.New: CheckInsertPreconditions(nok, forceSave, out homonymPersons, _elementBL); if (homonymPersons != null) { return(nok); } return(this.Insert(nok)); case StatusEntityValue.NewAndDeleted: return(nok); case StatusEntityValue.None: CheckUpdatePreconditions(nok, forceSave, out homonymPersons, _elementBL); if (homonymPersons != null) { return(nok); } if ((nok.Person != null) && (nok.Person.EditStatus.Value == StatusEntityValue.Updated)) { nok.Person = base.Update(nok.Person); } return(nok); case StatusEntityValue.Updated: CheckUpdatePreconditions(nok, forceSave, out homonymPersons, _elementBL); if (homonymPersons != null) { return(nok); } return(this.Update(nok)); default: throw new ArgumentOutOfRangeException(); } } catch (Exception ex) { if (ExceptionPolicy.HandleException(ex, ExceptionPolicies.Service)) { throw; } homonymPersons = null; return(null); } }
protected virtual void CheckUpdatePreconditions(NOKEntity nok, bool forceSave, out PersonAddressListDTO[] homonymPersons, ElementBL elementBL) { if (nok == null) { throw new ArgumentNullException("nok"); } ValidateNOK(nok, elementBL); #region Comentado por SALVA //PersonFindRequest personFind = new PersonFindRequest(); //BackofficeConfigurationSection backOfficeConfig = FrameworkConfigurationService<BackofficeConfigurationSection>.GetSection("backoffice") as BackofficeConfigurationSection; //if (backOfficeConfig != null) //{ // if (backOfficeConfig.EntitySettings.PersonEntity.Attributes != null) // { // foreach (EntityAttributeElement attrib in backOfficeConfig.EntitySettings.PersonEntity.Attributes) // { // if ((attrib.Name == "FirstName") && (attrib.Mandatory)) // { // personFind.FirstName = nok.Person.FirstName; // personFind.MandatoryFirstName = true; // } // if ((attrib.Name == "LastName") && (attrib.Mandatory)) // { // personFind.LastName = nok.Person.LastName; // personFind.MandatoryLastName = true; // } // } // } //} //int id = _personDA.GetPerson(personFind); //if ((id > 0) && (id != nok.Person.ID)) //{ // throw new Exception(string.Format(Properties.Resources.MSG_PersonAlreadyExists, string.Concat(nok.Person.FirstName, " ", nok.Person.LastName))); //} #endregion base.CheckUpdatePreconditions(nok.Person, nok.CustomerID, CategoryPersonKeyEnum.NOK, forceSave, false, true, out homonymPersons, elementBL); }
private void CheckInsertPreconditions(CustomerContactPersonEntity customerContactPerson, bool forceSave, out PersonAddressListDTO[] homonymPersons, ElementBL elementBL) { if (customerContactPerson == null) { throw new ArgumentNullException("customerContactPerson"); } ValidateCustomerContactPerson(customerContactPerson, elementBL); #region Comentado por SALVA //PersonFindRequest personFind = new PersonFindRequest(); //BackofficeConfigurationSection backOfficeConfig = FrameworkConfigurationService<BackofficeConfigurationSection>.GetSection("backoffice") as BackofficeConfigurationSection; //if (backOfficeConfig.EntitySettings.PersonEntity.Attributes != null) //{ // foreach (EntityAttributeElement attrib in backOfficeConfig.EntitySettings.PersonEntity.Attributes) // { // if ((attrib.Name == "FirstName") && (attrib.Mandatory)) // { // personFind.FirstName = customerContactPerson.Person.FirstName; // personFind.MandatoryFirstName = true; // } // if ((attrib.Name == "LastName") && (attrib.Mandatory)) // { // personFind.LastName = customerContactPerson.Person.LastName; // personFind.MandatoryLastName = true; // } // } //} #endregion homonymPersons = null; switch (customerContactPerson.Person.EditStatus.Value) { case StatusEntityValue.New: //int id = _personDA.GetPerson(personFind); //if (id > 0) //{ // throw new Exception(string.Format(Properties.Resources.MSG_PersonAlreadyExists, string.Concat(customerContactPerson.Person.FirstName, " ", customerContactPerson.Person.LastName))); //} //DO SALVA: Llamamos al algoritmo de validación de Persona. base.CheckInsertPreconditions(customerContactPerson.Person, customerContactPerson.CustomerID, CategoryPersonKeyEnum.CustContactPerson, forceSave, true, true, out homonymPersons, elementBL); break; case StatusEntityValue.Updated: //int id2 = _personDA.GetPerson(personFind); //if ((id2 > 0) && (id2 != customerContactPerson.Person.ID)) //{ // throw new Exception(string.Format(Properties.Resources.MSG_PersonAlreadyExists, string.Concat(customerContactPerson.Person.FirstName, " ", customerContactPerson.Person.LastName))); //} //DO SALVA base.CheckUpdatePreconditions(customerContactPerson.Person, customerContactPerson.CustomerID, CategoryPersonKeyEnum.CustContactPerson, forceSave, true, true, out homonymPersons, elementBL); break; } }
private void ValidateCustomerContactPerson(CustomerContactPersonEntity customerContactPerson, ElementBL elementBL) { if (customerContactPerson == null) { throw new ArgumentNullException("customerContactPerson"); } CommonEntities.ElementEntity _customerContactPersonMetadata = base.GetElementByName(EntityNames.CustomerContactPersonEntityName, elementBL); CustomerContactPersonHelper customerContactPersonHelper = new CustomerContactPersonHelper(_customerContactPersonMetadata); ValidationResults result = customerContactPersonHelper.Validate(customerContactPerson); if (!result.IsValid) { StringBuilder sb = new StringBuilder(); foreach (ValidationResult vr in result) { sb.AppendLine(); sb.AppendFormat("■ {0}", vr.Message); } throw new Exception( string.Format(Properties.Resources.ERROR_CustomerContactPersonValidationError, sb)); } //base.ValidatePerson(customerContactPerson.Person, elementBL); }