public HttpResponseMessage Post(AccountRegistrationService.RegisterNewAccountModel registerNewAccountModel) { HttpResponseMessage httpResponse = new HttpResponseMessage(); if (ModelState.IsValid) { //AccountRegistrationService.AccountRegistrationServiceClient accountRegistrationClient = new AccountRegistrationService.AccountRegistrationServiceClient(); //var registrationServiceResponse = accountRegistrationClient.RegisterAccount(registerNewAccountModel); //accountRegistrationClient.Close(); var accountRegistrationServiceClient = new AccountRegistrationService.AccountRegistrationServiceClient(); try { accountRegistrationServiceClient.Open(); var registrationServiceResponse = accountRegistrationServiceClient.RegisterAccount(registerNewAccountModel, Common.SharedClientKey); //Close the connection WCFManager.CloseConnection(accountRegistrationServiceClient); if (registrationServiceResponse.isSuccess) { httpResponse = Request.CreateResponse(HttpStatusCode.Created, registrationServiceResponse); } else { httpResponse = Request.CreateResponse(HttpStatusCode.OK, registrationServiceResponse); } } catch (Exception e) { #region Manage Exception string exceptionMessage = e.Message.ToString(); var currentMethod = System.Reflection.MethodBase.GetCurrentMethod(); string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name; // Abort the connection & manage the exception WCFManager.CloseConnection(accountRegistrationServiceClient, exceptionMessage, currentMethodString); // Upate the response object var exceptionResponse = new Sahara.Api.Accounts.Registration.AccountRegistrationService.DataAccessResponseType(); exceptionResponse.isSuccess = false; exceptionResponse.ErrorMessage = WCFManager.UserFriendlyExceptionMessage; exceptionResponse.ErrorMessages[0] = exceptionMessage; #endregion httpResponse = Request.CreateResponse(HttpStatusCode.OK, exceptionResponse); } } else { httpResponse = Request.CreateErrorResponse(HttpStatusCode.OK, ModelState); } return(httpResponse); }
public AccountNameValidationResponse AccountNameValidation(AccountNameValidator accountNameValidator) { string accountName = accountNameValidator.AccountName; var response = new AccountNameValidationResponse(); var accountRegistrationServiceClient = new AccountRegistrationService.AccountRegistrationServiceClient(); try { accountRegistrationServiceClient.Open(); var validationResponse = accountRegistrationServiceClient.ValidateAccountName(accountName); if (validationResponse.isValid) { response.valid = true; response.message = accountName + " is available!"; } else { response.valid = false; response.message = validationResponse.validationMessage; } //CommonMethods.MethodsClient commonMethodsClient = new CommonMethods.MethodsClient(); response.subdomain = accountRegistrationServiceClient.ConvertToAccountNameKey(accountName); //Close the connection WCFManager.CloseConnection(accountRegistrationServiceClient); } catch (Exception e) { #region Manage Exception string exceptionMessage = e.Message.ToString(); var currentMethod = System.Reflection.MethodBase.GetCurrentMethod(); string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name; // Abort the connection & manage the exception WCFManager.CloseConnection(accountRegistrationServiceClient, exceptionMessage, currentMethodString); // Upate the response object response.valid = false; response.message = WCFManager.UserFriendlyExceptionMessage; #endregion } return(response); }
public ValidationResponse PostLastNameValidation(LastNameValidator nameValidator) { var response = new ValidationResponse(); var accountRegistrationServiceClient = new AccountRegistrationService.AccountRegistrationServiceClient(); try { accountRegistrationServiceClient.Open(); var validationResponse = accountRegistrationServiceClient.ValidateLastName(nameValidator.LastName); //Close the connection WCFManager.CloseConnection(accountRegistrationServiceClient); response.valid = validationResponse.isValid; response.message = validationResponse.validationMessage; } catch (Exception e) { #region Manage Exception string exceptionMessage = e.Message.ToString(); var currentMethod = System.Reflection.MethodBase.GetCurrentMethod(); string currentMethodString = currentMethod.DeclaringType.FullName + "." + currentMethod.Name; // Abort the connection & manage the exception WCFManager.CloseConnection(accountRegistrationServiceClient, exceptionMessage, currentMethodString); // Upate the response object response.valid = false; response.message = WCFManager.UserFriendlyExceptionMessage; #endregion } return(response); }