public ActionResult AddToBasket(int ProductID)
        {
            var product = _ProductDb.Products.Where(x => x.ProductID == ProductID).First();

            product.BasketID = 1;

            if (ModelState.IsValid)
            {
                _ProductDb.Entry(product).State = EntityState.Modified;
                _ProductDb.SaveChanges();
                return(RedirectToAction("Index", "Basket"));
            }
            return(View());
        }
        public async Task <IHttpActionResult> PutProduct(int id, Product product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ProductExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public static Result EditProduct(ProductModel model)
        {
            Result result = new Result();

            try
            {
                using (var db = new ProductDb())
                {
                    var item = db.Products.Find(model.ProductID);
                    if (item != null)
                    {
                        item.ProductModelToProductMapExtension(model);

                        db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = new Result(new Exception("Unable to edit Product"));
            }

            return(result);
        }
Exemple #4
0
 public ActionResult Edit(UserProfile userprofile)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userprofile).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(userprofile));
 }
Exemple #5
0
 public ActionResult Edit(Client client)
 {
     if (ModelState.IsValid)
     {
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(client));
 }
 public ActionResult Edit(Supplier supplier)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplier).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplier));
 }
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         _db.Entry(product).State = EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(product));
 }
        public async Task <ActionResult> Edit([Bind(Include = "Id,Name,Price")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Entry(product).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
        public async Task <ActionResult> Edit([Bind(Include = "ProductId,UserId,Name,Description,Price,Category,Createtime,StreetNo,StreetRoute,Suburb,State,Postcode")] Product product)
        {
            if (ModelState.IsValid)
            {
                _productDb.Entry(product).State = EntityState.Modified;
                await _productDb.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
        public static Result DeleteProduct(int Id)
        {
            Result result = new Result();

            try
            {
                using (var db = new ProductDb())
                {
                    var ProductModel = db.Products.Find(Id);
                    if (ProductModel != null)
                    {
                        db.Entry(ProductModel).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = new Result(ex);
            }
            return(result);
        }
        public static Result Delete(int id)
        {
            Result result = new Result();

            try
            {
                using (var db = new ProductDb())
                {
                    var item = db.Products.Find(id);
                    if (item != null)
                    {
                        db.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result = new Result(new Exception("Unable to delete Product"));
            }
            return(result);
        }