Exemple #1
0
        public JsonResult EditProduct(ProductViewModel product)
        {
            Product Product = Mapper.Map <Product>(product);

            db.Entry(Product).State = EntityState.Modified;
            db.SaveChanges();
            if (!String.IsNullOrEmpty(product.UpLoad))
            {
                System.Drawing.Image img = AspMantraBase64ToImage(product.UpLoad.Split(',')[1]);
                var path = "/Content/images/" + DateTime.Now.Ticks.ToString() + "1.jpg";
                img.Save(Server.MapPath(path));
                Image image = db.Images.FirstOrDefault(x => x.ProductID == Product.ID);
                image.Path = path;
                db.SaveChanges();
            }
            if (!String.IsNullOrEmpty(product.UpLoad2))
            {
                System.Drawing.Image img2 = AspMantraBase64ToImage(product.UpLoad2.Split(',')[1]);
                var path2 = "/Content/images/" + DateTime.Now.Ticks.ToString() + "2.jpg";
                img2.Save(Server.MapPath(path2));
                Image image = db.Images.Where(x => x.ProductID == Product.ID).ToList().Last();

                image.Path = path2;
                db.SaveChanges();
            }

            return(Json(null, JsonRequestBehavior.AllowGet));
        }
 public ActionResult EditOrder([Bind(Include = "JugadorId,cedula,nombres,apellidos,carnet,profesion,intruccion,estadocivil,foto_jugador,EquipoId")] Jugador order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EquipoId = new SelectList(db.Equipo, "EquipoId", "nombre", order.EquipoId);
     return(View(order));
 }
 public ActionResult EditOrder([Bind(Include = "OrderId,ProductName,Quantity,Price,Amount,CustomerId")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "Name", order.CustomerId);
     return(View(order));
 }
        public void Update(T item, Func <T, bool> findByIDPredicate)
        {
            var local = Context.Set <T>()
                        .Local
                        .FirstOrDefault(findByIDPredicate);

            if (local != null)
            {
                Context.Entry(local).State = EntityState.Detached;
            }
            Context.Entry(item).State = EntityState.Modified;
        }
        /// <summary>
        /// Update a given product
        /// </summary>
        // PUT api/products/5
        public HttpResponseMessage Put(int id, [FromBody] ProductViewModel productViewModel)
        {
            if (ModelState.IsValid)
            {
                if (db.ProductCategory.Find(productViewModel.ProductCategoryId) == null)
                {
                    ModelState.AddModelError("ProductCategoryId", "Not found key");
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }

                Product product = db.Product.Find(id);
                if (product == null)
                {
                    ModelState.AddModelError("ProductId", "Not found key");
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }
                product.Name              = productViewModel.Name;
                product.Description       = productViewModel.Description;
                product.Price             = productViewModel.Price;
                product.Quantity          = productViewModel.Quantity;
                product.ProductCategoryId = productViewModel.ProductCategoryId;
                product.ImagePath         = productViewModel.ImageName;
                db.Entry(product).State   = EntityState.Modified;
                db.SaveChanges();
                return(new HttpResponseMessage(HttpStatusCode.OK));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
        }
        public ActionResult Buy(CheckoutPurchase checkoutPurchase)
        {
            Product product;

            foreach (var item in checkoutPurchase)
            {
                product = db.Product.Find(item.ProductId);
                if (product != null)
                {
                    // update quantities products
                    product.Quantity -= item.Quantity;
                    db.Product.Attach(product);
                    db.Entry(product).Property(p => p.Quantity).IsModified = true;

                    // add new purchase
                    Purchase purchase = new Purchase
                    {
                        ClientId    = User.Identity.GetUserId(),
                        ProductId   = item.ProductId,
                        StorageDate = DateTime.Now
                    };
                    db.Purchase.Add(purchase);
                    db.SaveChanges();
                }
                else
                {
                    return(View(checkoutPurchase));
                }
            }
            checkoutPurchase.Clear();
            return(RedirectToAction("Index", "Products"));
        }
Exemple #7
0
        public ActionResult Edit([Bind(Include = "ProductId,Name,ProductCategoryId,Price,Quantity,Description,ImagePath,ImageName,IsChangeImage")] ProductViewModel productViewModel)
        {
            if (ModelState.IsValid)
            {
                var imagePath = productViewModel.ImageName;
                if (productViewModel.IsChangeImage)
                {
                    var myHelper = new ControllersHelper();
                    imagePath = myHelper.SaveFile(productViewModel.ImagePath, ModelState, Server);
                }

                Product product = new Product
                {
                    ProductId         = productViewModel.ProductId,
                    Name              = productViewModel.Name,
                    Description       = productViewModel.Description,
                    Price             = productViewModel.Price,
                    Quantity          = productViewModel.Quantity,
                    ProductCategoryId = productViewModel.ProductCategoryId,
                    ImagePath         = imagePath
                };
                db.Entry(product).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.ProductCategoryId = new SelectList(db.ProductCategory, "ProductCategoryId", "Name", productViewModel.ProductCategoryId);
            return(View(productViewModel));
        }
 public ActionResult Edit(BeanBag beanbag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(beanbag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(beanbag));
 }
Exemple #9
0
 public ActionResult Edit([Bind(Include = "CustomerId,Name,Address,OrderDate")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customer));
 }
Exemple #10
0
 public ActionResult Edit([Bind(Include = "Id,UserName,Password")] AdminUser adminUser)
 {
     if (ModelState.IsValid)
     {
         db.Entry(adminUser).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(adminUser));
 }
Exemple #11
0
        public bool UpdateCategory(ItemCategory category)
        {
            if (context.ItemCategories.Find(category.ID) != null)
            {
                context.Entry(category).State = EntityState.Modified;
                return(true);
            }

            return(false);
        }
        public bool UpdateItem(Item item)
        {
            if (GetItem(item.ID) != null)
            {
                context.Entry(item).State = EntityState.Modified;
                return(true);
            }

            return(false);
        }
Exemple #13
0
        public bool UpdateOrder(Order order)
        {
            if (context.Orders.Find(order.ID) != null)
            {
                context.Entry(order).State = EntityState.Modified;
                return(true);
            }

            return(false);
        }
Exemple #14
0
        public bool UpdateUser(User user)
        {
            if (GetUser(user.ID) != null)
            {
                context.Entry(user).State = EntityState.Modified;
                return(true);
            }

            return(false);
        }
Exemple #15
0
 public ActionResult Edit(BeanBag beanbag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(beanbag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.beanBagTypeID = new SelectList(db.BeanBagTypes, "id", "name", beanbag.beanBagTypeID);
     return(View(beanbag));
 }
Exemple #16
0
        public ActionResult SignUp(Customer customer)
        {
            if (ModelState.IsValid)
            {
                customer.Type            = 2;
                db.Entry(customer).State = EntityState.Added;
                db.SaveChanges();
                return(RedirectToAction("HomePage"));
            }

            return(View("SignUp"));
        }
        public ActionResult Edit([Bind(Include = "ProductCategoryId,Name,Description,ImagePath,ImageName,IsChangeImage")] ProductCategoryViewModel productCategoryViewModel)
        {
            if (ModelState.IsValid)
            {
                var imagePath = productCategoryViewModel.ImageName;
                if (productCategoryViewModel.IsChangeImage)
                {
                    var myHelper = new ControllersHelper();
                    imagePath = myHelper.SaveFile(productCategoryViewModel.ImagePath, ModelState, Server);
                }

                ProductCategory productCategory = new ProductCategory
                {
                    ProductCategoryId = productCategoryViewModel.ProductCategoryId,
                    Name        = productCategoryViewModel.Name,
                    Description = productCategoryViewModel.Description,
                    ImagePath   = imagePath
                };
                db.Entry(productCategory).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(productCategoryViewModel));
        }