Exemplo n.º 1
0
 public async Task <ActionResult> Edit([Bind(Include = "ProductId,ItemId,OldProductId,OldItemId")] ProductItem productItem)
 {
     if (ModelState.IsValid)
     {
         if (await productItem.CanChange(db))
         {
             await productItem.Change(db);
         }
         return(RedirectToAction("Index"));
     }
     return(View(productItem.Convert(db)));
 }
        public async Task <ActionResult> Edit([Bind(Include = "ProductId,ItemId,OldProductId,OldItemId")] ProductItem productItem)
        {
            if (this.ModelState.IsValid)
            {
                var canChange = await productItem.CanChange(this.db);

                if (canChange)
                {
                    await productItem.Change(this.db);
                }

                return(this.RedirectToAction("Index"));
            }
            return(this.View(await productItem.Convert(this.db)));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Edit([Bind(Include = "ProductId,ItemId,OldProductId,OldItemId")] ProductItem productItem)
        {
            if (ModelState.IsValid)
            {
                // check if the ProductItem can be changed
                var canChange = await productItem.CanChange(db);

                if (canChange)
                {
                    // Change the productItem
                    await productItem.Change(db);
                }

                return(RedirectToAction("Index"));
            }
            return(View(productItem));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Edit([Bind(Include = "ProductId,ItemId,OldProductId,OldItemId")]
                                              ProductItem productItem)
        {
            if (ModelState.IsValid)
            {
                //db.Entry(productItem).State = EntityState.Modified;
                //await db.SaveChangesAsync();
                //return RedirectToAction("Index");

                var canChange = await productItem.CanChange(db);

                if (canChange)
                {
                    await productItem.Change(db);
                }
                return(RedirectToAction("Index"));
            }
            return(View(productItem));
        }
        public async Task <ActionResult> Edit(
            ProductItemModel productItem)
        {
            if (ModelState.IsValid)
            {
                ProductItem pd = new ProductItem();
                pd.ItemtId      = productItem.ItemId;
                pd.ProductId    = productItem.ProductId;
                pd.OldItemtId   = productItem.OldItemtId;
                pd.OldProductId = productItem.OldProductId;

                var canchange = await pd.CanChange(db);

                if (canchange)
                {
                    var remove = db.ProductItems.FirstOrDefault(pi =>
                                                                pi.ProductId.Equals(productItem.OldProductId) &&
                                                                pi.ItemtId.Equals(productItem.OldItemtId));

                    db.ProductItems.Remove(remove);
                    db.ProductItems.Add(pd);
                    await db.SaveChangesAsync();
                }

                else
                {
                    var modell = await db.ProductItems.Convert(db);

                    return(RedirectToAction("index", modell));
                }
            }

            var model = await db.ProductItems.Convert(db);

            return(View("Index", model));
        }