Exemplo n.º 1
0
 public EditProdctsViewModel(ProductsLuis productsLuis)
 {
     this.productsLuis = productsLuis;
     this.isEnabled    = true;
     this.apiService   = new ApiService();
     this.ImageSource  = productsLuis.ImageFullPath;
 }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> PutProductsLuis(string id, ProductsLuis productsLuis)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productsLuis.CVE_PRODUCTO_VAR)
            {
                return(BadRequest());
            }


            if (productsLuis.ImageArray != null && productsLuis.ImageArray.Length > 0)
            {
                var stream   = new MemoryStream(productsLuis.ImageArray);
                var guid     = Guid.NewGuid().ToString();
                var file     = $"{guid}.jpg";
                var folder   = "~/Content/ProductsLuis";
                var fullPath = $"{folder}/{file}";
                var response = FilesHelper.UploadPhoto(stream, folder, file);

                if (response)
                {
                    productsLuis.RUTA_IMAGEN_VAR = fullPath;
                }
            }



            this.db.Entry(productsLuis).State = EntityState.Modified;

            try
            {
                await this.db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductsLuisExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(productsLuis));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> DeleteProductsLuis(string id)
        {
            ProductsLuis productsLuis = await this.db.ProductsLuis.FindAsync(id);

            if (productsLuis == null)
            {
                return(NotFound());
            }

            this.db.ProductsLuis.Remove(productsLuis);
            await this.db.SaveChangesAsync();

            return(Ok(productsLuis));
        }
Exemplo n.º 4
0
        // GET: ProductsLuis/Details/5
        public async Task <ActionResult> Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ProductsLuis productsLuis = await db.ProductsLuis.FindAsync(id);

            if (productsLuis == null)
            {
                return(HttpNotFound());
            }
            return(View(productsLuis));
        }
Exemplo n.º 5
0
 private ProductView ToView(ProductsLuis product)
 {
     return(new ProductView
     {
         NOM_PROD_VAR = product.NOM_PROD_VAR,
         RUTA_IMAGEN_VAR = product.RUTA_IMAGEN_VAR,
         IS_AVAILABLE_BIT = product.IS_AVAILABLE_BIT,
         PRECIO_DEC = product.PRECIO_DEC,
         CVE_PRODUCTO_VAR = product.CVE_PRODUCTO_VAR,
         PUBLISH_ON_DATE = product.PUBLISH_ON_DATE,
         REMARK_VAR = product.REMARK_VAR,
         UNIDAD_MEDIDA_VAR = product.UNIDAD_MEDIDA_VAR,
     });
 }
Exemplo n.º 6
0
        public async Task <IHttpActionResult> PostProductsLuis(ProductsLuis productsLuis)
        {
            productsLuis.IS_AVAILABLE_BIT = true;
            productsLuis.PUBLISH_ON_DATE  = DateTime.Now.ToUniversalTime();


            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (productsLuis.ImageArray != null && productsLuis.ImageArray.Length > 0)
            {
                var stream   = new MemoryStream(productsLuis.ImageArray);
                var guid     = Guid.NewGuid().ToString();
                var file     = $"{guid}.jpg";
                var folder   = "~/Content/ProductsLuis";
                var fullPath = $"{folder}/{file}";
                var response = FilesHelper.UploadPhoto(stream, folder, file);

                if (response)
                {
                    productsLuis.RUTA_IMAGEN_VAR = fullPath;
                }
            }


            this.db.ProductsLuis.Add(productsLuis);

            try
            {
                await this.db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (ProductsLuisExists(productsLuis.CVE_PRODUCTO_VAR))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = productsLuis.CVE_PRODUCTO_VAR }, productsLuis));
        }
Exemplo n.º 7
0
        private async void Save()
        {
            //clave del producto vacía
            if (string.IsNullOrEmpty(this.KeyProduct))
            {
                await Application.Current.MainPage.DisplayAlert
                (
                    Languages.Error,
                    Languages.KeyProduct,
                    Languages.Accept
                );


                return;
            }


            //nombre del producto vacío
            if (string.IsNullOrEmpty(this.Name))
            {
                await Application.Current.MainPage.DisplayAlert
                (
                    Languages.Error,
                    Languages.DescriptionError,
                    Languages.Accept
                );


                return;
            }



            //precio vacío
            if (string.IsNullOrEmpty(this.Price))
            {
                await Application.Current.MainPage.DisplayAlert
                (
                    Languages.Error,
                    Languages.PriceError,
                    Languages.Accept
                );


                return;
            }


            //precio menor o igual a cero
            var price = decimal.Parse(this.Price);

            if (price <= 0)
            {
                await Application.Current.MainPage.DisplayAlert
                (
                    Languages.Error,
                    Languages.PriceError,
                    Languages.Accept
                );


                return;
            }


            //unidad de medida vacía
            if (string.IsNullOrEmpty(UnitOfMeasurement))
            {
                await Application.Current.MainPage.DisplayAlert
                (
                    Languages.Error,
                    Languages.UnitOfMeasurement,
                    Languages.Accept
                );


                return;
            }


            this.IsRunning = true;
            this.IsEnabled = false;


            //checamos si el cel tiene conexión a internet
            var connection = await this.apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;

                await Application.Current.MainPage.DisplayAlert
                (
                    Languages.Error,
                    connection.Message,
                    Languages.Accept
                );

                return;
            }



            //checamos si el usuario seleccionó una imagen
            // si es así la convertimos en un array de bites
            byte[] imageArray = null;
            if (this.file != null)
            {
                imageArray = FileHelper.ReadFully(this.file.GetStream());
            }


            //vamos a agregar un nuevo producto
            var product = new ProductsLuis
            {
                CVE_PRODUCTO_VAR  = KeyProduct,
                NOM_PROD_VAR      = this.Name,
                PRECIO_DEC        = price,
                REMARK_VAR        = this.Remarks,
                UNIDAD_MEDIDA_VAR = this.UnitOfMeasurement,
                ImageArray        = imageArray,
            };


            //enviamos el nuevo producto
            /* var url = Application.Current.Resources["urlApi"].ToString();*/  //la url está en una llave en el ApnewProduct.xaml
            var response = await this.apiService.PostList("http://salesapi.somee.com/", "/api", "/ProductsLuis", product, Settings.TokenType, Settings.AccessToken);

            if (!response.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert
                (
                    Languages.Error,
                    response.Message,
                    Languages.Accept
                );

                return;
            }



            // cargamos el nuevo producto para mostrarlo en la página principal de productos
            var newProduct            = (ProductsLuis)response.Result;
            var productsLuisViewModel = ProductsLuisViewModel.GetInstance();

            productsLuisViewModel.MyProducts.Add(newProduct);
            productsLuisViewModel.RefreshList();

            this.IsRunning = false;
            this.IsEnabled = true;

            //volvemos a la página principal
            await App.Navigator.PopAsync();
        }