public EditProductViewModel() { var types = Enum.GetValues(typeof(ProductType)); ProductTypes = new List <string>(); foreach (var item in types) { ProductTypes.Add(item.ToString()); } //Verificar bug al no seleccionar imagen por segunda vez IPickPhotoCommand = new Command(async() => { try { await CrossMedia.Current.Initialize(); files.Clear(); if (!CrossMedia.Current.IsPickPhotoSupported) { await Shell.Current.DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK"); return; } var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions { PhotoSize = PhotoSize.Full, }); if (file == null) { ProductImg = ImageSource.FromFile("imgPlaceholder.jpg"); return; } else { ImgArray = ConvertToByteArray(file.GetStream()); ProductImg = ImageSource.FromStream(() => file.GetStream()); } //files.Add(file); } catch (Exception e) { Console.WriteLine(e); } }); UpdateCommand = new Command(async() => { List <string> values = new List <string>(); values.Add(ProductName); values.Add(ProductDescription); values.Add(ProductPrice); values.Add(ProductQuantity.ToString()); values.Add(SelectedType); if (GlobalValidator.CheckNullOrEmptyPropertiesOfListValues(values)) { ProductType productType = (ProductType)Enum.Parse(typeof(ProductType), SelectedType); var toupdate = new Product() { InventoryQuantity = ProductQuantity, Price = Convert.ToDouble(ProductPrice), ProductDescription = ProductDescription, ProductId = ToEditProduct.ProductId, ProductImage = ImgArray, ProductName = ProductName, StoreId = ToEditProduct.StoreId, Type = productType }; var itemUpdateResult = await productDataStore.UpdateItemAsync(toupdate); if (itemUpdateResult) { await Shell.Current.DisplayAlert("Notification", "Item Update.", "OK"); MessagingCenter.Send <Product>(toupdate, "InventoryItemUpdated"); } } else { await Shell.Current.DisplayAlert("Notification", "Some values are empty", "OK"); } }); }
public RegisterStoreViewModel() { ValidatorInitializer(); StoreImage = ImageSource.FromFile("imgPlaceholder.jpg"); StoreTypes = new List <string>(Enum.GetNames(typeof(StoreType)).ToList()); #region WorkHourPresenter Initialize WorkHourPresenters = new ObservableCollection <WorkHourPresenter>(); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Monday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Tuesday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Wednesday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Thursday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Friday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Saturday.ToString())); WorkHourPresenters.Add(new WorkHourPresenter(DayOfWeek.Sunday.ToString())); #endregion PickPhotoCommand = new Command(async() => { //Stream stream = await DependencyService.Get<IPickPhotoService>().GetImageStreamAsync(); //if (stream != null) //{ // ImgArray = ConvertToByteArray(stream); // StoreImage = ImageSource.FromStream(() => stream); //} try { await CrossMedia.Current.Initialize(); files.Clear(); if (!CrossMedia.Current.IsPickPhotoSupported) { await Shell.Current.DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK"); return; } var mediOptions = new PickMediaOptions() { PhotoSize = PhotoSize.Full, }; var selectedImgFile = await CrossMedia.Current.PickPhotoAsync(mediOptions); if (selectedImgFile == null) { return; } ImgArray = ConvertToByteArray(selectedImgFile.GetStream()); StoreImage = ImageSource.FromStream(() => selectedImgFile.GetStream()); } catch (Exception e) { Console.WriteLine(e); } }); CompleteRegisterCommand = new Command(async() => { TokenExpManger tokenExpManger = new TokenExpManger(App.TokenDto.Exp); if (tokenExpManger.IsExpired()) { await tokenExpManger.CloseSession(); } else { List <string> valuesToCheck = new List <string>(); valuesToCheck.Add(StoreName); valuesToCheck.Add(LicenseCode); valuesToCheck.Add(StripeSecretKey); valuesToCheck.Add(StripePublicKey); StoreNameValidator = ValidatorRules.EmptyOrNullValueRule(StoreName); StoreDescriptionValidator = ValidatorRules.EmptyOrNullValueRule(StoreDescription); LicenseCodeValidator = ValidatorRules.EmptyOrNullValueRule(LicenseCode); SkStripeValidator = ValidatorRules.EmptyOrNullValueRule(StripeSecretKey); PKeyStripeValidator = ValidatorRules.EmptyOrNullValueRule(StripePublicKey); if (!StoreNameValidator.HasError && !StoreDescriptionValidator.HasError && !LicenseCodeValidator.HasError && !SkStripeValidator.HasError && !PKeyStripeValidator.HasError && GlobalValidator.CheckNullOrEmptyImage(StoreImage)) { bool isSKKeyCorrect = StripeSecretKey.StartsWith("sk"); bool isPBkeyCorrect = StripePublicKey.StartsWith("pk"); if (isSKKeyCorrect || isSKKeyCorrect) { Guid licenseCodeGuid = Guid.Parse(LicenseCode); var licenseResult = storeLicenseDataStore.StoreLicenseExists(licenseCodeGuid); if (licenseResult) { var licenseIsInUsed = await storeLicenseDataStore.IsLicenseInUsed(LicenseCode); if (!licenseIsInUsed) { StoreType value; Enum.TryParse(StoreTypeSelected, out value); var newStoreRegister = new Store() { StoreId = Guid.NewGuid(), StoreName = StoreName, UserId = App.LogUser.UserId, StoreImage = ImgArray, StoreType = value, StoreRegisterLicenseId = licenseCodeGuid, StoreDescription = StoreDescription, SKKey = StripeSecretKey, PBKey = StripePublicKey, }; List <WorkHour> workHours = new List <WorkHour>(); foreach (var item in WorkHourPresenters) { var workHour = new WorkHour() { CloseTime = Convert.ToDateTime(item.Close.ToString()), Day = item.Day, OpenTime = Convert.ToDateTime(item.Open.ToString()), WorkHourId = Guid.NewGuid(), StoreId = newStoreRegister.StoreId }; workHours.Add(workHour); } newStoreRegister.WorkHours = workHours; var storeaddedResult = await StoreDataStore.AddItemAsync(newStoreRegister); if (storeaddedResult) { var licenceUpdateResult = await storeLicenseDataStore.UpdateLicenceInCode(licenseCodeGuid); if (licenceUpdateResult) { await Shell.Current.DisplayAlert("Notification", "Store Added...!", "OK"); } } } else { await Shell.Current.DisplayAlert("Notification", "This License is in used.", "OK"); } } else { await Shell.Current.DisplayAlert("Notification", "License Code Incorrect", "OK"); } } else { await Shell.Current.DisplayAlert("Notification", "Srtipe Secret Key or Public Key are set in incorrect entry check again.", "OK"); } } else { await Shell.Current.DisplayAlert("Notification", "Some fields are empty", "OK"); } } }); }
public StoreControlPanelViewModel() { ProductTypes = new List <string>(Enum.GetNames(typeof(ProductType)).ToList()); EmpWorkHour = new ObservableCollection <EmployeeWorkHour>(); Store = new Store(); ProductImg = ImageSource.FromFile("imgPlaceholder.jpg"); GoAddProduct = new Command(async() => { await Shell.Current.GoToAsync($"AddProductRoute", animate: true); }); ProductPickPhotoCommand = new Command(async() => { await CrossMedia.Current.Initialize(); files.Clear(); if (!CrossMedia.Current.IsPickPhotoSupported) { await Shell.Current.DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK"); return; } var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions { PhotoSize = PhotoSize.Full, }); if (file == null) { return; } ImgArray = ConvertToByteArray(file.GetStream()); ProductImg = ImageSource.FromStream(() => file.GetStream()); }); CompleteCommand = new Command(async() => { List <string> Values = new List <string>(); Values.Add(ProductName); Values.Add(Description); Values.Add(ProductPrice); Values.Add(ProductQuantity.ToString()); if (GlobalValidator.CheckNullOrEmptyPropertiesOfListValues(Values)) { ProductType _productType = (ProductType)Enum.Parse(typeof(ProductType), SelectedType); var newStoreProduct = new Product() { ProductId = Guid.NewGuid(), InventoryQuantity = ProductQuantity, Price = Convert.ToDouble(ProductPrice), ProductImage = ImgArray, ProductName = ProductName, Type = _productType, StoreId = YourSelectedStore.StoreId, ProductDescription = ProductDescription }; var productAddedResult = await productDataStore.AddItemAsync(newStoreProduct); if (productAddedResult) { await Shell.Current.DisplayAlert("Notification", "Product Added", "OK"); } } else { await Shell.Current.DisplayAlert("Notification", "Some fields are empty", "OK"); } }); GoDashboards = new Command(async() => { await Shell.Current.DisplayAlert("Notification", "Is not developed yet. Coming Soon.", "OK"); }); GoOrdersCommand = new Command(async() => { await Shell.Current.GoToAsync($"EmployeeOrderControl?Id={YourSelectedStore.StoreId.ToString()}", animate: true); }); GoOrdersEmployeeCommand = new Command(async() => { await EmployeeShell.Current.GoToAsync($"EmployeeOrderControl?Id={Store.StoreId.ToString()}", animate: true); }); GoEmployeesCommand = new Command(async() => { await Shell.Current.GoToAsync($"StoreEmployeeRoute?Id={YourSelectedStore.StoreId.ToString()}", animate: true); //await Shell.Current.GoToAsync($"OrderPageRoute", animate: true); }); GoInventory = new Command(async() => { await Shell.Current.GoToAsync($"InventoryRoute", animate: true); }); GoSearchEmployeeCommand = new Command(async() => { await Shell.Current.GoToAsync($"{SearchEmployeePage.Route}?id={StoreId}", animate: true); }); GoOrderScanner = new Command(async() => { await Shell.Current.GoToAsync($"{OrderScannerPage.Route}"); }); MessagingCenter.Subscribe <Store>(this, "UpdatedStore", (sender) => { Store = sender; }); }