Esempio n. 1
0
        public ActionResult GetData()
        {
            using (BDTestEntities1 db = new BDTestEntities1())
            {
                List <Proveedores> provList      = db.Proveedores.ToList <Proveedores>();
                List <Proveedores> provListFinal = new List <Proveedores>();

                foreach (Proveedores prov in provList)
                {
                    Proveedores provFinal = new Proveedores();
                    provFinal.ProviderID   = prov.ProviderID;
                    provFinal.ProviderName = prov.ProviderName;
                    provFinal.Telefono     = prov.Telefono;
                    provFinal.Email        = prov.Email;
                    provFinal.Direccion    = prov.Direccion;

                    provListFinal.Add(provFinal);
                }

                log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                logger.Error("Error de sistema");

                return(Json(new { data = provListFinal }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 2
0
        public ActionResult GetData()
        {
            using (BDTestEntities1 db = new BDTestEntities1())
            {
                List <Orden> orderList      = db.Orden.ToList <Orden>();
                List <Orden> orderListFinal = new List <Orden>();

                foreach (Orden orden in orderList)
                {
                    Orden orderFinal = new Orden();

                    orderFinal.Ciudad    = orden.Ciudad;
                    orderFinal.Direccion = orden.Direccion;
                    orderFinal.Email     = orden.Email;
                    orderFinal.FirstName = orden.FirstName;
                    orderFinal.LastName  = orden.LastName;
                    orderFinal.OrderId   = orden.OrderId;
                    orderFinal.Phone     = orden.Phone;
                    orderFinal.Total     = orden.Total;
                    orderFinal.Username  = orden.Username;

                    orderListFinal.Add(orderFinal);
                }

                log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                logger.Error("Error de sistema");

                return(Json(new { data = orderListFinal }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 3
0
        public ActionResult GetData()
        {
            using (BDTestEntities1 db = new BDTestEntities1())
            {
                List <Producto> prodList      = db.Producto.ToList <Producto>();
                List <Producto> prodListFinal = new List <Producto>();

                foreach (Producto prod in prodList)
                {
                    Producto prodFinal = new Producto();
                    prodFinal.ProductID          = prod.ProductID;
                    prodFinal.ProductImg         = prod.ProductImg;
                    prodFinal.ProductName        = prod.ProductName;
                    prodFinal.ProductDescription = prod.ProductDescription;
                    prodFinal.Stock  = prod.Stock;
                    prodFinal.Precio = prod.Precio;

                    prodListFinal.Add(prodFinal);
                }

                log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                logger.Error("Error de sistema");

                return(Json(new { data = prodListFinal }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 4
0
 public ActionResult Delete(int id)
 {
     using (BDTestEntities1 db = new BDTestEntities1())
     {
         Orden order = db.Orden.Where(x => x.OrderId == id).FirstOrDefault <Orden>();
         db.Orden.Remove(order);
         db.SaveChanges();
         return(Json(new { success = true, message = "Eliminado con éxito" }, JsonRequestBehavior.AllowGet));
     }
 }
Esempio n. 5
0
 public ActionResult Delete(int id)
 {
     using (BDTestEntities1 db = new BDTestEntities1())
     {
         Producto prod = db.Producto.Where(x => x.ProductID == id).FirstOrDefault <Producto>();
         db.Producto.Remove(prod);
         db.SaveChanges();
         return(Json(new { success = true, message = "Eliminado con éxito" }, JsonRequestBehavior.AllowGet));
     }
 }
Esempio n. 6
0
        public ActionResult AddressAndPayment(Orden order)
        {
            var cart = Carrito.GetCart(this.HttpContext);

            //var orderTotal = cart.GetTotal();

            using (BDTestEntities1 db = new BDTestEntities1())
            {
                order.Total = cart.GetTotal();

                db.Orden.Add(order);
                db.SaveChanges();

                //cart.CreateOrder(order);
                cart.EmptyCart();

                return(RedirectToAction("Complete", new { id = order.OrderId }));
            }

            /*var order = new Orden();
             * TryUpdateModel(order);
             *
             * //try
             * //{
             *
             * try
             * {
             *  storeDB.Orden.Add(order);
             *  storeDB.SaveChanges();
             * } catch(DbEntityValidationException dbEx)
             * {
             *  foreach(var validationErrors in dbEx.EntityValidationErrors)
             *  {
             *      foreach (var validationError in validationErrors.ValidationErrors)
             *      {
             *          Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
             *      }
             *  }
             * }
             *
             *
             *  var cart = Carrito.GetCart(this.HttpContext);
             *  cart.CreateOrder(order);
             *
             *  //storeDB.SaveChanges();
             *
             *  return RedirectToAction("Complete", new { id = order.OrderId });
             * }
             * catch
             * {
             *  //Invalid
             *  return View(order);
             * }*/
        }
Esempio n. 7
0
 public ActionResult AddOrEdit(int id = 0)
 {
     if (id == 0)
     {
         return(View(new Orden()));
     }
     else
     {
         using (BDTestEntities1 db = new BDTestEntities1())
         {
             return(View(db.Orden.Where(x => x.OrderId == id).FirstOrDefault <Orden>()));
         }
     }
 }
Esempio n. 8
0
 public ActionResult AddOrEdit(int id = 0)
 {
     if (id == 0)
     {
         return(View(new Users()));
     }
     else
     {
         using (BDTestEntities1 db = new BDTestEntities1())
         {
             return(View(db.Users.Where(x => x.UserID == id).FirstOrDefault <Users>()));
         }
     }
 }
Esempio n. 9
0
 public ActionResult AddOrEdit(int id = 0)
 {
     if (id == 0)
     {
         return(View(new Producto()));
     }
     else
     {
         using (BDTestEntities1 db = new BDTestEntities1())
         {
             return(View(db.Producto.Where(x => x.ProductID == id).FirstOrDefault <Producto>()));
         }
     }
 }
Esempio n. 10
0
        public ActionResult Register(Users user)
        {
            using (BDTestEntities1 db = new BDTestEntities1())
            {
                if (user.UserID == 0)
                {
                    user.Perfil = "Comprador";
                    db.Users.Add(user);
                    db.SaveChanges();
                    return(Json(new { success = true, message = "Registrado con éxito" }, JsonRequestBehavior.AllowGet));
                }

                // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
                return(View(user));
            }
        }
Esempio n. 11
0
        public ActionResult Register(Users user)
        {
            using (BDTestEntities1 db = new BDTestEntities1())
            {
                if (user.UserID == 0)
                {
                    user.Perfil = "Comprador";
                    db.Users.Add(user);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Login"));
                }

                // Si llegamos a este punto, es que se ha producido un error y volvemos a mostrar el formulario
                return(View(user));
            }
        }
Esempio n. 12
0
 public ActionResult AddOrEdit(Proveedores prov)
 {
     using (BDTestEntities1 db = new BDTestEntities1())
     {
         if (prov.ProviderID == 0)
         {
             db.Proveedores.Add(prov);
             db.SaveChanges();
             return(Json(new { success = true, message = "Guardado con éxito" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(prov).State = System.Data.EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Actualizado con éxito" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Esempio n. 13
0
 public ActionResult AddOrEdit(Orden order)
 {
     using (BDTestEntities1 db = new BDTestEntities1())
     {
         if (order.OrderId == 0)
         {
             db.Orden.Add(order);
             db.SaveChanges();
             return(Json(new { success = true, message = "Guardado con éxito" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(order).State = System.Data.EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Actualizado con éxito" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Esempio n. 14
0
 public ActionResult AddOrEdit(Users user)
 {
     using (BDTestEntities1 db = new BDTestEntities1())
     {
         if (user.UserID == 0)
         {
             user.Perfil = "Comprador";
             db.Users.Add(user);
             db.SaveChanges();
             return(Json(new { success = true, message = "Guardado con éxito" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(user).State = System.Data.EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Actualizado con éxito" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Esempio n. 15
0
 public ActionResult Authorize(Users user)
 {
     using (BDTestEntities1 db = new BDTestEntities1())
     {
         var userDetails = db.Users.Where(x => x.Username == user.Username && x.Password == user.Password).FirstOrDefault();
         if (userDetails == null)
         {
             //user.LoginErrorMessage = "Usuario o contraseña incorrectos";
             return(View("Index", user));
         }
         else
         {
             Session["userID"]     = userDetails.Username;
             Session["userIDNumb"] = userDetails.UserID;
             Session["userRole"]   = userDetails.Perfil;
             return(RedirectToAction("Index", "Home"));
         }
     }
     return(View());
 }
Esempio n. 16
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insertar un nuevo usuario en la base de datos
                using (BDTestEntities1 db = new BDTestEntities1())
                {
                    Users user = db.Users.FirstOrDefault(u => u.Username.ToLower() == model.Username.ToLower());
                    // Comprobar si el usuario ya existe
                    if (user == null)
                    {
                        // Insertar el nombre en la tabla de perfiles
                        db.Users.Add(new Users {
                            Username = model.Username
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.Username);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "El nombre de usuario ya existe. Escriba un nombre de usuario diferente.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Esempio n. 17
0
        public ActionResult AddOrEdit(Producto prod, HttpPostedFileBase postedFile)
        {
            //byte[] bytes;

            /*using(BinaryReader br = new BinaryReader(postedFile.InputStream))
             * {
             *  bytes = br.ReadBytes(postedFile.ContentLength);
             * }*/
            string path     = "";
            var    fileName = "";

            using (BDTestEntities1 db = new BDTestEntities1())
            {
                if (postedFile != null && postedFile.ContentLength > 0)
                {
                    fileName = Path.GetFileName(postedFile.FileName);
                    path     = Path.Combine(Server.MapPath("~/Content/Images/"), fileName);
                    postedFile.SaveAs(path);
                }


                if (prod.ProductID == 0)
                {
                    prod.ProductImg = fileName;

                    db.Producto.Add(prod);
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Productos"));
                }
                else
                {
                    prod.ProductImg = fileName;

                    db.Entry(prod).State = System.Data.EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Productos"));
                }
            }
        }
Esempio n. 18
0
        public ActionResult GetData()
        {
            using (BDTestEntities1 db = new BDTestEntities1())
            {
                List <Users> userList      = db.Users.ToList <Users>();
                List <Users> userListFinal = new List <Users>();

                foreach (Users user in userList)
                {
                    Users userFinal = new Users();
                    userFinal.UserID   = user.UserID;
                    userFinal.Username = user.Username;
                    userFinal.Password = user.Password;
                    userFinal.Email    = user.Email;
                    userFinal.Perfil   = user.Perfil;
                    userListFinal.Add(userFinal);
                }

                log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                logger.Error("Error de sistema");

                return(Json(new { data = userListFinal }, JsonRequestBehavior.AllowGet));
            }
        }