Esempio n. 1
0
        public object Update(Product product, HttpPostedFileBase up)
        {
            var update = db.Products.SingleOrDefault(p => p.id == product.id);

            if (ModelState.IsValid)
            {
                update.name        = product.name;
                update.price       = product.price;
                update.description = product.description;
                update.category_id = product.category_id;
                if (up != null)
                {
                    String path = Path.Combine(Server.MapPath("~/Uploads"), up.FileName);
                    up.SaveAs(path);
                    update.image = up.FileName;
                }

                db.Entry(update).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Details/" + product.id));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Esempio n. 2
0
 public ActionResult Edit([Bind(Include = "Id,Product_Name,Product_Price,Product_Quantity,Product_Description,Id_Provider")] SalesProduct salesProduct)
 {
     if (ModelState.IsValid)
     {
         db.Entry(salesProduct).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Id_Provider = new SelectList(db.SalesProviders, "Id", "Provider_Name", salesProduct.Id_Provider);
     return(View(salesProduct));
 }
        public IHttpActionResult PutProductImage(int id, ProductImage productImage)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != productImage.Id)
            {
                return(BadRequest());
            }

            db.Entry(productImage).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductImageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutDiscount(int id, Discount discount)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != discount.ID)
            {
                return(BadRequest());
            }

            db.Entry(discount).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DiscountExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 5
0
        public virtual T UpdateItem(T entity)
        {
            dbSet.Attach(entity);
            dataContext.Entry(entity).State = EntityState.Modified;

            return(entity);
        }
        public ActionResult Edit([Bind(Include = "productId,categoryId,brandId,Name,Price,ProductImg")] Product product)
        {
            if (ModelState.IsValid)
            {
                WebImage ProductImg  = null;
                var      newFileName = "";
                var      imagePath   = "";
                //RIJEŠITI NESTED IF
                //zašto ne prihvaća HttpPostedFileBase tip??
                if (ProductImg != null)
                {
                    newFileName = Guid.NewGuid().ToString() + "_" +
                                  Path.GetFileName(ProductImg.FileName);
                    imagePath = @"~\Content\Images\" + newFileName;

                    ProductImg.Save(@"~\" + imagePath);
                }

                db.Entry(product).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.brandId    = new SelectList(db.Brands, "BrandId", "Name", product.brandId);
            ViewBag.categoryId = new SelectList(db.Categories, "CategoryId", "Name", product.categoryId);
            return(View(product));
        }
Esempio n. 7
0
        public IHttpActionResult PutOrder_details(int id, Order_details order_details)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != order_details.ID)
            {
                return(BadRequest());
            }

            db.Entry(order_details).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Order_detailsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public virtual void Update(T entity)
        {
            //_dbSet.Attach(entity);
            //_dataContext.Entry(entity).State = EntityState.Modified;
            var entry = _dataContext.Entry(entity);

            if (entry.State == EntityState.Detached || entry.State == EntityState.Modified)
            {
                _dbSet.Attach(entity);              //attach
                entry.State = EntityState.Modified; //do it here
            }
            if (entry.State == EntityState.Unchanged)
            {
                entry.State = EntityState.Detached;
                _dbSet.Attach(entity);
                entry.State = EntityState.Modified;
            }
        }
Esempio n. 9
0
 public ActionResult Edit([Bind(Include = "Id,Provider_Name")] SalesProvider salesProvider)
 {
     if (ModelState.IsValid)
     {
         db.Entry(salesProvider).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(salesProvider));
 }
 public ActionResult Edit([Bind(Include = "GenreId,Name,Description")] Genre genre)
 {
     if (ModelState.IsValid)
     {
         db.Entry(genre).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(genre));
 }
 public ActionResult Edit([Bind(Include = "Id,Name")] ProductCategory productCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(productCategory));
 }
Esempio n. 12
0
 public ActionResult Edit([Bind(Include = "ProveedorId,Nombre,RUC,Celular,Telefono,Correo,Direccion,Estado")] Proveedor proveedor)
 {
     if (ModelState.IsValid)
     {
         db.Entry(proveedor).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(proveedor));
 }
Esempio n. 13
0
 public ActionResult Edit([Bind(Include = "Id,Name,Location")] Store store)
 {
     if (ModelState.IsValid)
     {
         db.Entry(store).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(store));
 }
 public ActionResult Update([Bind(Include = "id,name,number_of_product")] Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("List"));
     }
     return(View(category));
 }
 public ActionResult Edit([Bind(Include = "CategoriaId,Nombre,Descripcion,Estado")] Categoria categoria)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categoria).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(categoria));
 }
 public ActionResult Edit([Bind(Include = "ArtistId,Name")] Artist artist)
 {
     if (ModelState.IsValid)
     {
         db.Entry(artist).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(artist));
 }
Esempio n. 17
0
 public ActionResult Edit([Bind(Include = "Id,Name,Price,Image,Description,Category_Id")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Category_Id = new SelectList(db.Categories, "Id", "Name", product.Category_Id);
     return(View(product));
 }
Esempio n. 18
0
 public static bool CUD(Payment e, EntityState state)
 {
     using (StoreEntities s = new StoreEntities()) {
         s.Entry(e).State = state;
         if (s.SaveChanges() > 0)
         {
             return(true);
         }
         return(false);
     }
 }
Esempio n. 19
0
 public ActionResult Edit([Bind(Include = "Id,Name,Price,ProductCategoryId,Discontinued,FeaturedProduct")] Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductCategoryId = new SelectList(db.ProductCategories, "Id", "Name", product.ProductCategoryId);
     return(View(product));
 }
 public ActionResult Edit([Bind(Include = "OrderId,OrderDate,Username,FirstName,LastName,City,Phone,Total,AlbumId")] Order order)
 {
     if (ModelState.IsValid)
     {
         db.Entry(order).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AlbumId = new SelectList(db.Album, "AlbumId", "Title", order.AlbumId);
     return(View(order));
 }
Esempio n. 21
0
 public ActionResult Edit([Bind(Include = "ProductId,StoreId,AmountInStock")] ProductStore productStore)
 {
     if (ModelState.IsValid)
     {
         db.Entry(productStore).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProductId = new SelectList(db.Products, "Id", "Name", productStore.ProductId);
     ViewBag.StoreId   = new SelectList(db.Stores, "Id", "Name", productStore.StoreId);
     return(View(productStore));
 }
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId);
     ViewBag.BrandId    = new SelectList(db.Brands, "BrandId", "Name", product.BrandId);
     return(View(product));
 }
 public ActionResult Edit([Bind(Include = "AlbumId,GenreId,ArtistID,Title,Price,AlbumArtUrl")] Album album)
 {
     if (ModelState.IsValid)
     {
         db.Entry(album).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ArtistID = new SelectList(db.Artist, "ArtistId", "Name", album.ArtistID);
     ViewBag.GenreId  = new SelectList(db.Genre, "GenreId", "Name", album.GenreId);
     return(View(album));
 }
Esempio n. 24
0
 public ActionResult Edit([Bind(Include = "ProductoId,CategoriaId,ProveedorId,Denominacion,Descripcion,PrecioUnitario,Existencias,Estado")] Producto producto)
 {
     if (ModelState.IsValid)
     {
         db.Entry(producto).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoriaId = new SelectList(db.Categoria, "CategoriaId", "Nombre", producto.CategoriaId);
     ViewBag.ProveedorId = new SelectList(db.Proveedor, "ProveedorId", "Nombre", producto.ProveedorId);
     return(View(producto));
 }
Esempio n. 25
0
 public ActionResult Edit([Bind(Include = "OrderDetailId,OrderId,AlbumId,Quantity,UnitPrice")] OrderDetail orderDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.AlbumId = new SelectList(db.Album, "AlbumId", "Title", orderDetail.AlbumId);
     ViewBag.OrderId = new SelectList(db.Order, "OrderId", "Username", orderDetail.OrderId);
     return(View(orderDetail));
 }
Esempio n. 26
0
        public IHttpActionResult PutCat(int id, Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != category.ID)
            {
                return(BadRequest());
            }

            context.Entry(category).State = EntityState.Modified;
            context.SaveChanges();
            return(Ok());
        }
        public object Add(Product product, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                String path = Path.Combine(Server.MapPath("~/Uploads"), upload.FileName);
                upload.SaveAs(path);
                product.image = upload.FileName;

                db.Products.Add(product);
                db.SaveChanges();
                var add = db.Categories.SingleOrDefault(m => m.id == product.category_id);
                add.number_of_products++;
                db.Entry(add).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }
        public ActionResult Addtocart(int id)
        {
            var search = db.Carts.SingleOrDefault(c => c.product_id == id);

            if (search == null)
            {
                Cart cart = new Cart();
                cart.product_id = id;
                cart.added_at   = DateTime.Now;
                db.Carts.Add(cart);
                db.SaveChanges();
            }
            else
            {
                search.countProduct++;
                db.Entry(search).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }
Esempio n. 29
0
        public static ResultSet ResultCUD(Customers cus, EntityState state)
        {
            using (StoreEntities s = new StoreEntities()) {
                s.Entry(cus).State = state;

                if (s.SaveChanges() > 0)
                {
                    r.isSuccess = true;
                    r.Message   = "Kayıt eklendi.";
                    r.Customer  = cus;
                    r.iconType  = IconType.ok;
                }
                else
                {
                    r.isSuccess = false;
                    r.Message   = "Hata!!";
                    r.Customer  = cus;
                    r.iconType  = IconType.warning;
                }
                return(r);
            }
        }
Esempio n. 30
0
        public IHttpActionResult PutOrder(int id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != order.ID)
            {
                return(BadRequest());
            }

            db.Entry(order).State = EntityState.Modified;
            foreach (var od in order.Order_details)
            {
                var ordDet = new OrderDetailsController();
                ordDet.PutOrder_details(od.ID, od);
            }
            db.SaveChanges();

            //try
            //{
            //    db.SaveChanges();
            //}
            //catch (DbUpdateConcurrencyException)
            //{
            //    if (!OrderExists(id))
            //    {
            //        return NotFound();
            //    }
            //    else
            //    {
            //        throw;
            //    }
            //}

            return(StatusCode(HttpStatusCode.NoContent));
        }