Exemplo n.º 1
0
        public async void Create()
        {
            try
            {
                if (pckProductSegment.SelectedIndex < 0)
                {
                    throw new Exception("Selecione o tipo do produto.");
                }


                Acr.UserDialogs.UserDialogs.Instance.ShowLoading(AppResource.alertLoading);

                string value = txtPrice.Text.Replace(',', '.').Replace("R$", "").Replace("$", "");

                var culture  = App.AppCurrent.Culture;
                var valorNow = Decimal.Parse(value, culture.NumberFormat);


                Product _product = new Product();
                if (imageStream != null)
                {
                    //faz upload da imagem
                    ApiService service = new ApiService();
                    _product.ImageUri = await service.UploadImage(imageStream);
                }

                _product.Name            = txtName.Text;
                _product.Price           = valorNow;
                _product.Quantity        = Convert.ToInt32(txtQuantity.Text);
                _product.Description     = txtDescription.Text;
                _product.IsDisabled      = !swtActive.IsToggled;
                _product.CategoryGroupId = Group.Id;
                _product.CompanyId       = Helpers.Settings.DisplayUserCompany;
                _product.OrderingNumber  = Convert.ToInt32(txtPosition.Text);
                _product.ProductSegment  = (EProductSegment)pckProductSegment.SelectedIndex;

                var result = await companyService.CreateProduct(_product);

                Acr.UserDialogs.UserDialogs.Instance.Toast(AppResource.lblItemCreatedSucess);
                await App.AppCurrent.NavigationService.GoBack();
            }
            catch (Exception ex)
            {
                this.DisplayAlert(MocoApp.Resources.AppResource.alertAlert, ex.Message, AppResource.textOk);
            }
            finally
            {
                Acr.UserDialogs.UserDialogs.Instance.HideLoading();
            }
        }