public GenericActionResult <RegistrationReturnModel <IndividualConsigneeBindingModel> > RegisterIndividual(CreateUserBindingModel principalUser, IndividualConsigneeBindingModel individualConsignee) { //validate individual doesn't exist first bool personAlreadyExists = _validationHelper.CheckForExistingIndividual(individualConsignee.TRN); if (personAlreadyExists) { return new GenericActionResult <RegistrationReturnModel <IndividualConsigneeBindingModel> >() { IsSuccess = false, Errors = new List <string> { "Individual already registered, duplicate TRN" } } } ; var userCreateResult = _userManagement.CreateUser(principalUser); string userId = null; if (userCreateResult.IsSuccess) { userId = userCreateResult.Result.Id; AssignUserToDefaultRoles(userId); } else { return(new GenericActionResult <RegistrationReturnModel <IndividualConsigneeBindingModel> >() { Errors = userCreateResult.Errors, IsSuccess = false, Result = null }); } int?indivdualConsigneeId = _dataAccess.CreateIndividualConsignee(individualConsignee); //if an id wasn't returned, it means an error occurred during the creation of the consignee record //therefore roll back all that came before it. if (!indivdualConsigneeId.HasValue) { //reverse the created user by deleting it _userManagement.DeleteUser(userCreateResult.Result.UserName); return(new GenericActionResult <RegistrationReturnModel <IndividualConsigneeBindingModel> >() { IsSuccess = false, Errors = new List <string> { "Error completing registration,please try again later." } }); } //create link between individual and consignee _dataAccess.CreateIndividualConsigneeRepresentative(userId, indivdualConsigneeId.Value); //return new information on user & company return(new GenericActionResult <RegistrationReturnModel <IndividualConsigneeBindingModel> >() { IsSuccess = true, Result = new RegistrationReturnModel <IndividualConsigneeBindingModel> { ConsigneeModel = individualConsignee, UserModel = userCreateResult.Result }, Errors = null }); }