public RegisterStoreViewModel(IValidatableObjectFactory validatableObjectFactory, IUserDataStore userDataStore, IStoreDataStore storeDataStore, IStoreFactory storeFactory, IUserFactory userFactory, IRegisterCardViewModel cardViewModel, IStoreRegistrationEntry storeRegistrationEntry) { _validatableObjectFactory = validatableObjectFactory; _UserDataStore = userDataStore; _StoreDataStore = storeDataStore; _StoreFactory = storeFactory; _UserFactory = userFactory; CardViewModel = cardViewModel; StoreRegistrationEntry = storeRegistrationEntry; StoreName = _validatableObjectFactory.CreateSimpleValidatebleObject <string>("Store 1"); CardNumber = _validatableObjectFactory.CreateSimpleValidatebleObject <string>(); Longitude = _validatableObjectFactory.CreateSimpleValidatebleObject <string>("1"); Latitude = _validatableObjectFactory.CreateSimpleValidatebleObject <string>("2"); StoreOwnerName = _validatableObjectFactory.CreateSimpleValidatebleObject <string>("Owner 1"); Description = _validatableObjectFactory.CreateSimpleValidatebleObject <string>("Description"); Category = _validatableObjectFactory.CreateSimpleValidatebleObject <string>("Category"); StoreNameValidationCommand = new Command(() => StoreName.Validate()); LongitudeValidationCommand = new Command(() => Longitude.Validate()); LatitudeValidationCommand = new Command(() => Latitude.Validate()); StoreOwnerNameValidationCommand = new Command(() => StoreOwnerName.Validate()); MoreInfoCommand = new Command <CommandEventData>((commandData) => MoreInfoPopup(commandData)); RegisterStoreCommand = new Command <CommandEventData>(async(data) => await NavigateToInventoryProductItem(data)); DescriptionValidationCommand = new Command(() => Description.Validate()); GetLogoPhotoCommand = new Command(async() => ProductImageSource = await Utils.PickPhoto()); TakeLogoPhotoCommand = new Command(() => { }); GetLocationCommand = new Command(async() => await GetLocation()); TypeOfCardChangedCommand = new Command <CommandEventData>((data) => TypeOfCardSelectionChangedHandler(data)); Init(); }
public ApiResponse <User> RegisterStoreAction(IStoreRegistrationEntry storeRegistrationEntry) { ApiResponse <User> apiResponse = new ApiResponse <User>(); HttpResponseMessage httpResponse; FullAPIUri = new Uri(BaseAPIUri, $"{nameof(RegisterStoreAction)}"); string serializedObjString = JsonConvert.SerializeObject(storeRegistrationEntry); byte[] bytes = Encoding.UTF8.GetBytes(serializedObjString); ByteArrayContent byteContent = new ByteArrayContent(bytes); byteContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); Policy.Handle <Exception>() //.WaitAndRetryForever .Retry( retryCount: 0, //sleepDurationProvider: retryAttemp => TimeSpan.FromSeconds(Math.Pow(1, retryAttemp)), onRetry: (exception, /*timeSpan,*/ retryCount, context) => { // Add logic to be executed before each retry, such as logging System.Diagnostics.Debug.WriteLine($"Retry #{retryCount} due to exception '{(exception.InnerException ?? exception).Message}'"); HttpClient.CancelPendingRequests(); apiResponse = new ApiResponse <User>(); apiResponse.Failure.ErrorsMessages.Add("Request was unsucessfull."); apiResponse.IsSuccess = false; } ).ExecuteAndCapture(() => { httpResponse = HttpClient.PostAsync(FullAPIUri, byteContent).Result; if (httpResponse.IsSuccessStatusCode) { apiResponse = JsonConvert.DeserializeObject <ApiResponse <User> >(httpResponse.Content.ReadAsStringAsync().Result); } else { apiResponse.Failure.ErrorsMessages.Add("Request was unsucessfull."); apiResponse.IsSuccess = false; } }); return(apiResponse); }