public IEnumerable <ApiProducts.Library.Models.ProductoRes> GetProductsIds(object value)
        {
            var ConnectionStringLocal = _configuration.GetValue <string>("CadenaConexion");
            var jsonString            = Newtonsoft.Json.JsonConvert.SerializeObject(value);
            List <ApiProducts.Library.Models.ProductoRes> list = new List <ApiProducts.Library.Models.ProductoRes>();

            ApiProducts.Library.Models.Producto objProducto = new ApiProducts.Library.Models.Producto();
            //string json = @"[ {""idPedido"": 1, ""idProducto"": 1, ""cantidad"": 1 }]";
            //Deserialize the data
            var obj = JsonConvert.DeserializeObject <List <ApiProducts.Library.Models.ProductoMinRes> >(value.ToString());

            //Loop thrrouch values and save the details into database
            foreach (ApiProducts.Library.Models.ProductoMinRes p in obj)
            {
                using (IProduct producto = Factorizador.CrearConexionServicio(ApiProducts.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
                {
                    objProducto = producto.GetProduct(p.Id);

                    list.Add(new ApiProducts.Library.Models.ProductoRes()
                    {
                        Id          = objProducto.Id,
                        Titulo      = objProducto.Titulo,
                        Plataforma  = objProducto.Plataforma,
                        Imagen      = objProducto.Imagen,
                        Imagen2     = objProducto.Imagen2,
                        Imagen3     = objProducto.Imagen3,
                        PrecioVenta = objProducto.PrecioVenta,
                        Edicion     = objProducto.FechaLanzamiento,
                        IdCarrito   = p.IdCarrito
                    });
                }
            }
            return(list);
        }
Exemplo n.º 2
0
        //public IActionResult Login([FromBody]Models.Login user)
        //{
        //    if (user == null)
        //        return BadRequest("Invalid client request");

        //    //Lógica de consulta a una base de datos
        //    if (user.Nick == "mtwdm" && user.Password == "123123")
        //    {
        //        var secretKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("rgatilanov-2019-mtwdm"));
        //        var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);

        //        var tokeOptions = new JwtSecurityToken(
        //            issuer: "https://userapi2.azurewebsites.net",
        //            audience: "https://userapi2.azurewebsites.net",
        //            claims: new List<System.Security.Claims.Claim>(),
        //            expires: DateTime.Now.AddMinutes(5),
        //           signingCredentials: signinCredentials
        //            );

        //        var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions);
        //        return Ok(new { Token = tokenString });
        //    }

        //    else
        //        return Unauthorized();
        //}
        public Api.Library.Models.User Login([FromBody] Api.Library.Models.UserMin user)
        {
            var ConnectionStringLocal = _configuration.GetValue <string>("ConnectionStringLocal");
            var ConnectionStringAzure = _configuration.GetValue <string>("ConnectionStringAzure");

            using (ILogin Login = Factorizador.CrearConexionServicio(Api.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                Api.Library.Models.User objusr = Login.EstablecerLogin(user.Nick, user.Password);

                if (objusr.ID > 0)
                {
                    var secretKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("maestria-mtwdm-2019"));
                    var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);

                    var tokeOptions = new JwtSecurityToken(
                        issuer: "http://localhost:44308",
                        audience: "http://localhost:44308",
                        claims: new List <System.Security.Claims.Claim>(),
                        expires: DateTime.Now.AddMinutes(5),
                        signingCredentials: signinCredentials
                        );

                    var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions);
                    objusr.JWT = tokenString;
                }
                return(objusr);
            }
        }
Exemplo n.º 3
0
        public IEnumerable <APIUsers.Library.Models.User> GetUsers()
        {
#if false
            List <User> users = new List <User>();
            users.Add(new Models.User()
            {
                CreateDate  = DateTime.Now,
                ID          = 1,
                Name        = "Ramón Gerardo",
                Nick        = "rgatilanov",
                Password    = null,
                accountType = AccountType.Administrator
            });

            users.Add(new Models.User()
            {
                CreateDate  = DateTime.Now,
                ID          = 2,
                Name        = "Juan Perez",
                Nick        = "juan.perez",
                Password    = null,
                accountType = AccountType.Basic,
            });
#endif

            List <APIUsers.Library.Models.User> listUsers = new List <APIUsers.Library.Models.User>();
            var ConnectionStringLocal = _configuration.GetValue <string>("ServidorLocal");
            using (IUser User = Factorizador.CrearConexionServicio(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                listUsers = User.GetUsers();
            }
            return(listUsers);
        }
Exemplo n.º 4
0
 public ActionResult <List <User> > GetAllUsers()
 {
     using (ILogin Login = Factorizador.CrearConexionServicio(Api.Library.Models.ConnectionType.MSSQL, ConnectionStringAzure))
     {
         List <Api.Library.Models.User> objusrs = Login.ObtenerUsers();
         return(objusrs);
     }
 }
        public IActionResult InsertOrderDetail(ApiProducts.Library.Models.PedidoCabDet value)
        {
            int id       = 0;
            int idPedido = 0;
            var ConnectionStringLocal = _configuration.GetValue <string>("CadenaConexion");
            var jsonString            = Newtonsoft.Json.JsonConvert.SerializeObject(value);

            int insertCodigo = 0;

            ApiProducts.Library.Models.Producto  objProducto = new ApiProducts.Library.Models.Producto();
            ApiProducts.Library.Models.PedidoCab objPedido   = new ApiProducts.Library.Models.PedidoCab();
            //string json = @"[ {""idPedido"": 1, ""idProducto"": 1, ""cantidad"": 1 }]";
            //Deserialize the data
            //var obj = JsonConvert.DeserializeObject<List<ApiProducts.Library.Models.PedidoCabDet>>(value.ToString());
            //Loop thrrouch values and save the details into database


            using (IOrder Order = Factorizador.CrearConexionServicioOrder(ApiProducts.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                idPedido = Order.InsertOrder(value.ClienteId, value.Total, "TC", "");
            }

            foreach (int p in value.ListaProductos)
            {
                using (ICode Code = Factorizador.CrearConexionServicioCode(ApiProducts.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
                {
                    insertCodigo = Code.InsertCode(idPedido, p, Functions.RandomCodigo());
                }

                using (IProduct producto = Factorizador.CrearConexionServicio(ApiProducts.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
                {
                    objProducto = producto.GetProduct(p);
                }

                using (IOrder Order = Factorizador.CrearConexionServicioOrder(ApiProducts.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
                {
                    id = Order.InsertDetail(idPedido, p, insertCodigo, 1, objProducto.PrecioVenta);
                }

                using (IOrder order = Factorizador.CrearConexionServicioOrder(ApiProducts.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
                {
                    objPedido = order.GetOrder(idPedido);
                }
            }

            if (id > 0)
            {
                return(Ok(new
                {
                    Id = objPedido,
                    Estatus = "success",
                    Code = 200,
                    Msg = "Detalle del pedido insertado correctamente!!"
                }));
            }

            return(NotFound());
        }
        public int RemoveFromShoppingCart([FromBody] APIUsers.Library.Models.ShoppingCart shoppingCart)
        {
            int id = 0;

            using (IShoppingCart Shopping = Factorizador.CrearConexionServicioShoppingCart(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal)){
                id = Shopping.removeFromShoppingCart(shoppingCart.ID_User, shoppingCart.ID_Product);
            }
            return(id);
        }
Exemplo n.º 7
0
 public IEnumerable<APIUsers.Library.Models.User> GetUsers()
 {
     List<APIUsers.Library.Models.User> listUsers = new List<APIUsers.Library.Models.User>();
     var ConnectionStringLocal = _configuration.GetValue<string>("ServidorAzure");
     using (IUser User = Factorizador.CrearConexionServicio(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal)){
         listUsers = User.GetUsers();
     }
     return listUsers;
 }
Exemplo n.º 8
0
        public IActionResult UpdateCategory([FromBody] APIUsers.Library.Models.Category value)
        {
            Boolean status;

            using (ICategory Category = Factorizador.CrearConexionServicioCategory(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal)){
                status = Category.UpdateCategory(value);
            }
            return(Ok(status));
        }
Exemplo n.º 9
0
        public IActionResult GetProductBySearch(string search)
        {
            List <APIUsers.Library.Models.Product> listProducts = new List <APIUsers.Library.Models.Product>();

            using (IProduct Product = Factorizador.CrearConexionServicioProduct(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal)) {
                listProducts = Product.GetAllProductsBySearch(search);
            }
            return(Ok(new { listProducts }));
        }
Exemplo n.º 10
0
 public Boolean UpdateUserDomicilio([FromBody] APIUsers.Library.Models.User value)
 {
     Boolean status;
     var ConnectionStringLocal = _configuration.GetValue<string>("ServidorAzure");
     using (IUser User = Factorizador.CrearConexionServicio(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
     {
         status = User.UpdateUser_domicilio(value);
     }
     return status;
 }
        public int UpdateShoppingCartQuantity([FromBody] APIUsers.Library.Models.ShoppingCart shoppingCart)
        {
            int id = 0;

            using (IShoppingCart Shopping = Factorizador.CrearConexionServicioShoppingCart(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                id = Shopping.updateShoppingCart_ProductQuantity(shoppingCart.ID_User, shoppingCart.ID_Product, shoppingCart.Quantity);
            }
            return(id);
        }
        public int RemovefromWishList([FromBody] APIUsers.Library.Models.WishList wishList)
        {
            int id = 0;

            using (IWishList WishList = Factorizador.CrearConexionServicioWishList(ConnectionType.MSSQL, ConnectionStringLocal))
            {
                id = WishList.removeFromWishList(wishList.ID_User, wishList.ID_Product);
            }
            return(id);
        }
Exemplo n.º 13
0
        public IActionResult DeleteProduct(int id)
        {
            Boolean status;

            using (IProduct Product = Factorizador.CrearConexionServicioProduct(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                status = Product.DeleteProduct(id);
            }
            return(Ok(status));
        }
        public IActionResult SearchWishList_Products(int id, string search)
        {
            List <APIUsers.Library.Models.Product> listProducts = new List <APIUsers.Library.Models.Product>();

            using (IWishList WishList = Factorizador.CrearConexionServicioWishList(ConnectionType.MSSQL, ConnectionStringLocal))
            {
                listProducts = WishList.searchProducts_Wishlist(search, id);
            }
            return(Ok(new { listProducts }));
        }
        public IEnumerable <APIUsers.Library.Models.Promotion> GetPromotionsById([FromBody] APIUsers.Library.Models.Promotion value)
        {
            List <APIUsers.Library.Models.Promotion> listPromotions = new List <APIUsers.Library.Models.Promotion>();

            using (IPromotion promotion = Factorizador.CrearConexionServicio3(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                listPromotions = promotion.GetPromotionsById(value.id);
            }
            return(listPromotions);
        }
Exemplo n.º 16
0
        public IActionResult GetAllProductsByParamsPost([FromBody] APIUsers.Library.Models.Parametros value)
        {
            List <APIUsers.Library.Models.Product> listProducts = new List <APIUsers.Library.Models.Product>();

            using (IProduct Product = Factorizador.CrearConexionServicioProduct(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                listProducts = Product.GetAllProductsByParams(value);
            }
            return(Ok(new { listProducts }));
        }
        public string GetPromotions(int idUser)
        {
            string listShopping = "";

            using (ICheckout chk = Factorizador.CrearConexionServicio2(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                listShopping = chk.getShoping(idUser);
            }
            return(listShopping);
        }
Exemplo n.º 18
0
        public IActionResult GetCategoriesBySearch(string search)
        {
            List <APIUsers.Library.Models.Category> list = new List <APIUsers.Library.Models.Category>();

            using (ICategory Category = Factorizador.CrearConexionServicioCategory(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                list = Category.GetAllCategoriesBySearch(search);
            }
            return(Ok(new { list }));
        }
Exemplo n.º 19
0
 public IActionResult GetUserByNick(string nick)
 {
     APIUsers.Library.Models.User user = new APIUsers.Library.Models.User();
     var ConnectionStringLocal = _configuration.GetValue<string>("ServidorAzure");
     using (IUser User = Factorizador.CrearConexionServicio(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
     {
         user = User.GetUser(nick);
     }
     return Ok(new { user });
 }
Exemplo n.º 20
0
        public IActionResult DeleteCategory(int id)
        {
            Boolean status;

            using (ICategory Category = Factorizador.CrearConexionServicioCategory(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                status = Category.DeleteCategory(id);
            }
            return(Ok(status));
        }
Exemplo n.º 21
0
        public int InsertCategory([FromBody] APIUsers.Library.Models.Category value)
        {
            int id = 0;

            using (ICategory Category = Factorizador.CrearConexionServicioCategory(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                id = Category.InsertCategory(value);
            }
            return(id);
        }
        public int GetProductValidbyCode([FromBody] string code)
        {
            int userDAta = 0;

            using (ICheckout chk = Factorizador.CrearConexionServicio2(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                userDAta = chk.getProductValidbyCode(code);
            }
            return(userDAta);
        }
        public IActionResult GetBrandBySelect()
        {
            List <APIUsers.Library.Models.Brand> list = new List <APIUsers.Library.Models.Brand>();

            using (IBrand Brand = Factorizador.CrearConexionServicioBrand(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                list = Brand.obtenerMarcasSelected();
            }
            return(Ok(new { list }));
        }
        public int remove_promotion([FromBody] APIUsers.Library.Models.Promotion value)
        {
            int result = 0;

            using (IPromotion promotion = Factorizador.CrearConexionServicio3(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                result = promotion.removePromotion(value.id);
            }
            return(result);
        }
Exemplo n.º 25
0
        public int InsertProduct([FromBody] APIUsers.Library.Models.Product value)
        {
            int id = 0;
            var ConnectionStringLocal = _configuration.GetValue <string>("ServidorAzure");

            using (IProduct Product = Factorizador.CrearConexionServicioProduct(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                id = Product.InsertProduct(value);
            }
            return(id);
        }
        //[Authorize]
        public IEnumerable <ApiProducts.Library.Models.Producto> GetProductsPlataforma(int id)//[FromBody] ApiProducts.Library.Models.ProductoMin value
        {
            List <ApiProducts.Library.Models.Producto> listProducts = new List <ApiProducts.Library.Models.Producto>();
            var ConnectionStringLocal = _configuration.GetValue <string>("CadenaConexion");

            using (IProduct product = Factorizador.CrearConexionServicio(ApiProducts.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                listProducts = product.GetProductsPlataforma(id);
            }
            return(listProducts);
        }
Exemplo n.º 27
0
        public Boolean UpdateProduct([FromBody] APIUsers.Library.Models.Product value)
        {
            Boolean status;
            var     ConnectionStringLocal = _configuration.GetValue <string>("ServidorAzure");

            using (IProduct Product = Factorizador.CrearConexionServicioProduct(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                status = Product.UpdateProduct(value);
            }
            return(status);
        }
Exemplo n.º 28
0
        public IActionResult GetProduct(int id)
        {
            APIUsers.Library.Models.Product product = new Product();
            var ConnectionStringLocal = _configuration.GetValue <string>("ServidorAzure");

            using (IProduct Product = Factorizador.CrearConexionServicioProduct(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                product = Product.GetProduct(id);
            }
            return(Ok(new { product }));
        }
Exemplo n.º 29
0
        //[Authorize]
        public IEnumerable <ApiProducts.Library.Models.PedidoDet> GetOrderDetail(int id)//[FromBody] ApiProducts.Library.Models.PedidoCabMin value
        {
            List <ApiProducts.Library.Models.PedidoDet> listOrders = new List <ApiProducts.Library.Models.PedidoDet>();
            var ConnectionStringLocal = _configuration.GetValue <string>("CadenaConexion");

            using (IOrder order = Factorizador.CrearConexionServicioOrder(ApiProducts.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                listOrders = order.GetOrderDetail(id);
            }
            return(listOrders);
        }
Exemplo n.º 30
0
        public IActionResult GetTop3ByCategory(string category, int id)
        {
            List <APIUsers.Library.Models.Product> listProducts = new List <APIUsers.Library.Models.Product>();
            var ConnectionStringLocal = _configuration.GetValue <string>("ServidorAzure");

            using (IProduct Product = Factorizador.CrearConexionServicioProduct(APIUsers.Library.Models.ConnectionType.MSSQL, ConnectionStringLocal))
            {
                listProducts = Product.GetTop3ByCategory(category, id);
            }
            return(Ok(new { listProducts }));
        }