Exemple #1
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));
         }
     }
 }
 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));
         }
     }
 }
Exemple #3
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));
     }
 }
 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));
     }
 }
 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));
         }
     }
 }
        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);
             * }*/
        }
Exemple #7
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"));
                }
            }
        }
        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));
            }
        }
        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));
            }
        }
        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));
        }