Ejemplo n.º 1
0
        public static string ConverttToString(object newObj)
        {
            var currentNode = (Comp_Product)newObj;

            currentNode._name = currentNode._name == null ? string.Empty : currentNode._name;
            return($"{string.Format("{0,-100}", currentNode._id.ToString())}{EncriptarSDES.Cifrado(string.Format("{0,-100}", currentNode._name), true)}{EncriptarSDES.Cifrado(string.Format("{0,-100}", currentNode._price.ToString()), true)}");
        }
Ejemplo n.º 2
0
        public static string ConvertToString(object newObj)
        {
            var currentNode = (Comp_Store)newObj;

            currentNode._name    = currentNode._name == null ? string.Empty : currentNode._name;
            currentNode._address = currentNode._address == null ? string.Empty : currentNode._address;
            return($"{string.Format("{0,-100}", currentNode._id.ToString())}{EncriptarSDES.Cifrado(string.Format("{0,-100}",  currentNode._name), true)}{ EncriptarSDES.Cifrado(string.Format("{0,-100}",currentNode._address),true)}");
        }
        public ActionResult <IEnumerable <string> > Inventory(IFormFile file)
        {
            EncriptarSDES.StartKey();
            if (file == null || file.Length == 0)
            {
                return(BadRequest("El archivo esta vacio o no selecciono ningun archivo."));
            }
            BTree <Comp_Product> .Create(treeFile, new ToObject(Comp_Product.ConvertToObject), new ToString(Comp_Product.ConverttToString));

            Comp_Product.LoadInventory(file.OpenReadStream());
            return(Ok("Se han ingresado los valores con exito."));
        }
        public ActionResult <List <Comp_Product> > getProducts()
        {
            EncriptarSDES.StartKey();
            BTree <Comp_Product> .Create(treeFile, new ToObject(Comp_Product.ConvertToObject), new ToString(Comp_Product.ConverttToString));

            var total = BTree <Comp_Product> .Traversal(null);

            if (total.Count == 0)
            {
                return(NotFound("No se encuentran valores disponibles."));
            }
            return(Ok(total));
        }
        public ActionResult <IEnumerable <string> > postProduct([FromForm] Comp_Product product)
        {
            EncriptarSDES.StartKey();
            if (product._name != null && product._price >= 0)
            {
                BTree <Comp_Product> .Create(treeFile, new ToObject(Comp_Product.ConvertToObject), new ToString(Comp_Product.ConverttToString));

                BTree <Comp_Product> .ValidateIncert(new Comp_Product { _id = BTree <Comp_Product> .KnowId(), _name = product._name, _price = product._price });
            }
            else
            {
                return(BadRequest("Solicitud erronea."));
            }
            return(Ok("Dato ingresado correctamente."));
        }
Ejemplo n.º 6
0
 public ActionResult <List <Comp_Store> > getStore(int id)
 {
     EncriptarSDES.StartKey();
     if (id >= 0)
     {
         BTree <Comp_Store> .Create("TreeStore", new ToObject(Comp_Store.ConvertToObject), new ToString(Comp_Store.ConvertToString));
     }
     else
     {
         return(NotFound("El ID: " + id + " no cuenta con tiendas asignadas."));
     }
     return(Ok(BTree <Comp_Store> .Traversal(new Comp_Store {
         _id = id
     }, 1)));
 }
Ejemplo n.º 7
0
        public ActionResult <IEnumerable <string> > postStore([FromForm] Comp_Store store)
        {
            EncriptarSDES.StartKey();
            if (store._name != null && store._address != null)
            {
                BTree <Comp_Store> .Create(treeFile, new ToObject(Comp_Store.ConvertToObject), new ToString(Comp_Store.ConvertToString));

                BTree <Comp_Store> .ValidateIncert(new Comp_Store { _id = BTree <Comp_Store> .KnowId(), _name = store._name, _address = store._address });
            }
            else
            {
                return(BadRequest("Solicitud erronea."));
            }
            return(Ok("Datos ingresados correctamente."));
        }
        public ActionResult <List <List <Comp_Store_Product> > > putTransferStoreProduct(int product, int transmitter, int receiver, int stock)
        {
            if (transmitter == receiver)
            {
                return(BadRequest("Los id de las tiendas son iguales, intente con ids diferentes"));
            }
            EncriptarSDES.StartKey();
            BTree <Comp_Store_Product> .Create(treeFile, new ToObject(Comp_Store_Product.ConvertToObject), new ToString(Comp_Store_Product.ConvertToString));

            var nodoTransmiter = new List <Comp_Store_Product>(BTree <Comp_Store_Product> .Traversal(new Comp_Store_Product {
                _idProduct = product, _idStore = transmitter
            }, 1));
            var nodoReceiver = new List <Comp_Store_Product>(BTree <Comp_Store_Product> .Traversal(new Comp_Store_Product {
                _idProduct = product, _idStore = receiver
            }, 1));

            if (nodoTransmiter.Count != 0 && nodoTransmiter[0]._stock - stock >= 0)
            {
                if (nodoReceiver.Count == 0)
                {
                    BTree <Comp_Store_Product> .ValidateIncert(new Comp_Store_Product { _idStore = receiver, _idProduct = product, _stock = stock });
                }
                else
                {
                    nodoReceiver[0]._stock = nodoReceiver[0]._stock + stock;
                    BTree <Comp_Store_Product> .ValidateEdit(nodoReceiver[0], new string[2] {
                        nodoReceiver[0]._stock.ToString(), null
                    }, new Edit(Comp_Store_Product.Modify));
                }
                nodoTransmiter[0]._stock = nodoTransmiter[0]._stock - stock;
                BTree <Comp_Store_Product> .ValidateEdit(nodoTransmiter[0], new string[2] {
                    nodoTransmiter[0]._stock.ToString(), null
                }, new Edit(Comp_Store_Product.Modify));
            }
            else
            {
                return(BadRequest("La solicitud no puede ser procesada"));
            }
            var nodoList = new List <List <Comp_Store_Product> >();

            nodoList.Add(new List <Comp_Store_Product>(BTree <Comp_Store_Product> .Traversal(new Comp_Store_Product {
                _idStore = transmitter, _idProduct = product
            }, 1)));
            nodoList.Add(new List <Comp_Store_Product>(BTree <Comp_Store_Product> .Traversal(new Comp_Store_Product {
                _idStore = receiver, _idProduct = product
            }, 1)));
            return(Ok(nodoList));
        }
Ejemplo n.º 9
0
        public static Comp_Store ConvertToObject(string data)
        {
            var dataSeparate = new List <string>();

            for (int i = 0; i < 3; i++)
            {
                dataSeparate.Add(data.Substring(0, 100));
                data = data.Substring(100);
            }

            return(new Comp_Store()
            {
                _id = Convert.ToInt32(dataSeparate[0].Trim()),
                _name = EncriptarSDES.Cifrado(dataSeparate[1], false).Trim(),
                _address = EncriptarSDES.Cifrado(dataSeparate[2], false).Trim()
            });
        }
        public ActionResult <IEnumerable <string> > postStoreProduct([FromForm] Comp_Store_Product storeproduct)
        {
            EncriptarSDES.StartKey();

            if (storeproduct._idStore >= 0 && storeproduct._idProduct >= 0 && storeproduct._stock >= 0)
            {
                BTree <Comp_Store_Product> .Create(treeFile, new ToObject(Comp_Store_Product.ConvertToObject), new ToString(Comp_Store_Product.ConvertToString));

                BTree <Comp_Store_Product> .ValidateIncert(new Comp_Store_Product { _idStore = storeproduct._idStore, _idProduct = storeproduct._idProduct, _stock = storeproduct._stock });
            }
            else
            {
                return(BadRequest("Solicitud erronea."));
            }

            return(Ok("Datos ingresados correctamente."));
        }
        public ActionResult <IEnumerable <string> > putStoreProduct([FromForm] Comp_Store_Product storeProduct)
        {
            EncriptarSDES.StartKey();
            BTree <Comp_Store_Product> .Create(treeFile, new ToObject(Comp_Store_Product.ConvertToObject), new ToString(Comp_Store_Product.ConvertToString));

            if (BTree <Comp_Store_Product> .Traversal(new Comp_Store_Product {
                _idStore = storeProduct._idStore, _idProduct = storeProduct._idProduct
            }, 1).Count == 0)
            {
                return(BadRequest("No se encontro ninguna coincidencia"));
            }

            BTree <Comp_Store_Product> .ValidateEdit(storeProduct, new string[2] {
                storeProduct._stock.ToString(), null
            }, new Edit(Comp_Store_Product.Modify));

            return(Ok("El elemento fue actualizado"));
        }
Ejemplo n.º 12
0
        public ActionResult <IEnumerable <string> > putProduct([FromForm] Comp_Store store)
        {
            EncriptarSDES.StartKey();
            BTree <Comp_Store> .Create(treeFile, new ToObject(Comp_Store.ConvertToObject), new ToString(Comp_Store.ConvertToString));

            if (BTree <Comp_Store> .Traversal(new Comp_Store {
                _id = store._id
            }, 1).Count == 0)
            {
                return(NotFound("El ID no se encontró."));
            }

            BTree <Comp_Store> .ValidateEdit(store, new string[2] {
                store._name, store._address
            }, new Edit(Comp_Store.Modify));

            return(Ok("El id: " + store._id + " fue actualizado."));
        }
        public ActionResult <List <Comp_Store_Product> > getStoreProduct(int store, int product)
        {
            EncriptarSDES.StartKey();
            if (store >= 0 && product >= 0)
            {
                BTree <Comp_Store_Product> .Create(treeFile, new ToObject(Comp_Store_Product.ConvertToObject), new ToString(Comp_Store_Product.ConvertToString));
            }
            else
            {
                return(BadRequest("Solicitud Erronea"));
            }
            var total = BTree <Comp_Store_Product> .Traversal(new Comp_Store_Product { _idStore = store, _idProduct = product }, 1);

            if (total.Count == 0)
            {
                return(NotFound("No se encuentran valores disponibles."));
            }
            return(Ok(total));
        }
Ejemplo n.º 14
0
        public ActionResult <List <Comp_Product> > getProduct(int id)
        {
            EncriptarSDES.StartKey();
            if (id >= 0)
            {
                BTree <Comp_Product> .Create("TreeProduct", new ToObject(Comp_Product.ConvertToObject), new ToString(Comp_Product.ConverttToString));
            }
            else
            {
                return(BadRequest("ID invalido"));
            }
            var total = BTree <Comp_Product> .Traversal(new Comp_Product { _id = id }, 1);

            if (total.Count == 0)
            {
                return(NotFound("No se encuentran valores disponibles."));
            }
            return(Ok(total));
        }
Ejemplo n.º 15
0
        public static Comp_Product ConvertToObject(string data)
        {
            var dataSeparate = new List <string>();

            for (int i = 0; i < 3; i++)
            {
                dataSeparate.Add(data.Substring(0, 100));
                data = data.Substring(100);
            }

            var price = 0.00;

            double.TryParse(EncriptarSDES.Cifrado(dataSeparate[2], false).Trim(), out price);

            return(new Comp_Product()
            {
                _id = Convert.ToInt32(dataSeparate[0].Trim()),
                _name = EncriptarSDES.Cifrado(dataSeparate[1], false).Trim(),
                _price = price
            });
        }
        public static Comp_Store_Product ConvertToObject(string data)
        {
            var separateData = new List <string>();

            for (int i = 0; i < 3; i++)
            {
                separateData.Add(data.Substring(0, 100));
                data = data.Substring(100);
            }

            var price = 0;

            int.TryParse(EncriptarSDES.Cifrado(separateData[2], false), out price);

            return(new Comp_Store_Product()
            {
                _idStore = Convert.ToInt32(separateData[0].Trim()),
                _idProduct = Convert.ToInt32(separateData[1].Trim()),
                _stock = price
            });
        }
        public ActionResult <List <Comp_Store_Product> > getStoreProductsoneStore(int store)
        {
            EncriptarSDES.StartKey();
            BTree <Comp_Store_Product> .Create(treeFile, new ToObject(Comp_Store_Product.ConvertToObject), new ToString(Comp_Store_Product.ConvertToString));

            var OneStore = new List <Comp_Store_Product>();
            var total    = BTree <Comp_Store_Product> .Traversal(null);

            if (total.Count == 0)
            {
                return(NotFound("No se encuentran valores disponibles."));
            }
            foreach (var item in total)
            {
                if (item._idStore == store)
                {
                    OneStore.Add(item);
                }
            }
            return(Ok(OneStore));
        }
Ejemplo n.º 18
0
        public ActionResult <IEnumerable <string> > putProduct([FromForm] Comp_Product product)
        {
            EncriptarSDES.StartKey();
            if (product._price < 0)
            {
                return(BadRequest("El precio del producto debe ser mayor a 0."));
            }
            BTree <Comp_Product> .Create(treeFile, new ToObject(Comp_Product.ConvertToObject), new ToString(Comp_Product.ConverttToString));

            if (BTree <Comp_Product> .Traversal(new Comp_Product {
                _id = product._id
            }, 1).Count == 0)
            {
                return(NotFound("El id no se encontro."));
            }

            BTree <Comp_Product> .ValidateEdit(product, new string[2] {
                product._name, product._price.ToString()
            }, new Edit(Comp_Product.Modify));

            return(Ok("El id: " + product._id + " fue actualizado."));
        }
        public static string ConvertToString(object newObj)
        {
            var currentNode = (Comp_Store_Product)newObj;

            return($"{string.Format("{0,-100}", currentNode._idStore.ToString())}{string.Format("{0,-100}", currentNode._idProduct.ToString())}{EncriptarSDES.Cifrado(string.Format("{0,-100}", currentNode._stock.ToString()),true)}");
        }