public void UpdatePerson(Person person, out TransactionalInformation transaction) { transaction = new TransactionalInformation(); try { var personBusinessRules = new PersonBusinessRules(); var results = personBusinessRules.Validate(person); bool validationSucceeded = results.IsValid; var failures = results.Errors; if (validationSucceeded == false) { transaction = ValidationErrors.PopulateValidationErrors(failures); return; } _personDataService.CreateSession(); _personDataService.BeginTransaction(); var existingPerson = _personDataService.GetPerson(person.PersonID); existingPerson.CompanyName = person.CompanyName; existingPerson.Name = person.Name; existingPerson.Country = person.Country; existingPerson.City = person.City; existingPerson.Address = person.Address; existingPerson.MobileNumber = person.MobileNumber; existingPerson.Image = person.Image; _personDataService.UpdatePerson(person); _personDataService.CommitTransaction(true); transaction.ReturnStatus = true; transaction.ReturnMessage.Add("Person was successfully updated."); } catch (Exception ex) { string errorMessage = ex.Message; transaction.ReturnMessage.Add(errorMessage); transaction.ReturnStatus = false; } finally { _personDataService.CloseSession(); } }
public Person CreatePerson(Person person, out TransactionalInformation transaction) { transaction = new TransactionalInformation(); try { var personBusinessRules = new PersonBusinessRules(); var results = personBusinessRules.Validate(person); bool validationSucceeded = results.IsValid; var failures = results.Errors; if (validationSucceeded == false) { transaction = ValidationErrors.PopulateValidationErrors(failures); return(person); } _personDataService.CreateSession(); _personDataService.BeginTransaction(); _personDataService.CreatePerson(person); _personDataService.CommitTransaction(true); transaction.ReturnStatus = true; transaction.ReturnMessage.Add("Person successfully created."); } catch (Exception ex) { string errorMessage = ex.Message; transaction.ReturnMessage.Add(errorMessage); transaction.ReturnStatus = false; } finally { _personDataService.CloseSession(); } return(person); }