예제 #1
0
        public static async Task Change(this Product_Item productitem, ApplicationDbContext db)
        {
            var oldProductItem = await db.Products_Items.FirstOrDefaultAsync
                                     (pi => pi.ProductID.Equals(productitem.OldProductID) && pi.ItemID.Equals(productitem.OldItemID));

            var newProductItem = await db.Products_Items.FirstOrDefaultAsync
                                     (pi => pi.ProductID.Equals(productitem.ProductID) && pi.ItemID.Equals(productitem.ItemID));

            if (oldProductItem != null & newProductItem == null)
            {
                newProductItem = new Product_Item()
                {
                    ItemID    = productitem.ItemID,
                    ProductID = productitem.ProductID
                };

                using (var transaction = new System.Transactions.TransactionScope(
                           TransactionScopeAsyncFlowOption.Enabled))
                {
                    try
                    {
                        db.Products_Items.Remove(oldProductItem);
                        db.Products_Items.Add(newProductItem);
                        await db.SaveChangesAsync();

                        transaction.Complete();
                    }
                    catch
                    {
                        transaction.Dispose();
                    }
                }
            }
        }
예제 #2
0
        public async Task <ActionResult> DeleteConfirmed(int itemID, int productID)
        {
            Product_Item product_Item = await GetProductItem(itemID, productID);

            db.Products_Items.Remove(product_Item);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
예제 #3
0
        public async Task <ActionResult> Create([Bind(Include = "ProductID,ItemID")] Product_Item product_Item)
        {
            if (ModelState.IsValid)
            {
                db.Products_Items.Add(product_Item);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(product_Item));
        }
예제 #4
0
 public void UnselectItem()
 {
     if (currentType == BuildingType.None)
     {
         return;
     }
     for (int i = 0; i < ValidProduct.Count; i++)
     {
         Product_Item item = productcontent.transform.GetChild(i).GetComponent <Product_Item>();
         item.gameObject.GetComponent <Image>().color = Color.white;
     }
 }
예제 #5
0
 public void OnItemButton()
 {
     facilityBuildPanel.UpdateBuildPanel();
     for (int i = 0; i < ValidProduct.Count; i++)
     {
         Product_Item item = productcontent.transform.GetChild(i).GetComponent <Product_Item>();
         if (item.type == currentItem)
         {
             item.gameObject.GetComponent <Image>().color = color;
         }
     }
 }
예제 #6
0
        public static async Task <bool> CanChange(this Product_Item proditem, ApplicationDbContext db)
        {
            //Check to see if old product and item exist - for the Edit view
            var oldProdItem = await db.Products_Items.CountAsync
                                  (pi => pi.ProductID.Equals(proditem.OldProductID) && pi.ItemID.Equals(proditem.OldItemID));

            var newProdItem = await db.Products_Items.CountAsync
                                  (pi => pi.ProductID.Equals(proditem.ProductID) && pi.ItemID.Equals(proditem.ItemID));

            //Return true if the old product and item id combination do exist and the new ones don't exist.
            return(oldProdItem.Equals(1) && newProdItem.Equals(0));
        }
예제 #7
0
    public Product_Item GenerateProductItem(int index)
    {
        Product_Item newproduct = Instantiate <Product_Item>(Prefab_product);

        newproduct.transform.SetParent(productcontent);
        newproduct.facilityPallete = this.facilityPallete;

        newproduct.index  = index;
        newproduct.size   = size;
        newproduct.width  = width;
        newproduct.height = height;
        return(newproduct);
    }
예제 #8
0
        public async Task <ActionResult> Edit([Bind(Include = "ProductID,ItemID,OldProductID,OldItemID")] Product_Item product_Item)
        {
            if (ModelState.IsValid)
            {
                var canChange = await product_Item.CanChange(db);

                if (canChange)
                {
                    await product_Item.Change(db);
                }
                return(RedirectToAction("Index"));
            }
            return(View(product_Item));
        }
예제 #9
0
        // GET: Admin/ProductItem/Edit/5
        public async Task <ActionResult> Edit(int?ItemID, int?ProductID)
        {
            if (ItemID == null || ProductID == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Product_Item productItem = await GetProductItem(ItemID, ProductID);

            if (productItem == null)
            {
                return(HttpNotFound());
            }
            return(View(await productItem.Convert(db)));
        }
예제 #10
0
        public static async Task <ProductItemModel> Convert
            (this Product_Item productItem, ApplicationDbContext db, bool addListData = true)
        //Only fill collections if the parameter passed in is true
        {
            var model = new ProductItemModel
            {
                ItemID    = productItem.ItemID,
                ProductID = productItem.ProductID,
                Items     = addListData ? await db.Items.ToListAsync() : null,
                Products  = addListData ? await db.Products.ToListAsync() : null,

                ItemTitle    = (await db.Items.FirstOrDefaultAsync(i => i.ID.Equals(productItem.ItemID))).Title,
                ProductTitle = (await db.Products.FirstOrDefaultAsync(p => p.ID.Equals(productItem.ProductID))).Title
            };

            return(model);
        }
예제 #11
0
    public void UpdateBuildPanel()
    {
        txtname.text  = facilityPallete.currentType.ToString();
        txtlevel.text = facilityPallete.currentLevel + "";
        SetIsSelecting(false);
        if (gameManager == null)
        {
            Debug.Log("GameManager is null");
        }
        gameManager.hexMap.HideIndicator();
        gameManager.hexMap.selectedCell.indicator.gameObject.SetActive(true);
        gameManager.hexMap.selectedCell.indicator.SetColor(Indicator.StartColor);
        selectDestination.transform.gameObject.SetActive(false);
        soulcontent.transform.gameObject.SetActive(false);
        productcontent.gameObject.SetActive(false);
        txtselected.transform.gameObject.SetActive(false);
        switch ((int)facilityPallete.currentType)
        {
        case 0:
        case 1:
            txtsometitle.text = "Product";
            break;

        case 2:
            txtsometitle.text = "Destination";
            selectDestination.transform.gameObject.SetActive(true);
            if (facilityPallete.currentDestination != null)
            {
                txtselected.transform.gameObject.SetActive(true);
                facilityPallete.currentDestination.indicator.gameObject.SetActive(true);
                facilityPallete.currentDestination.indicator.SetColor(Indicator.EndColor);
            }
            break;

        default:
            txtsometitle.text = "";
            break;
        }

        if (IsBuildOK())
        {
            txtdescription.gameObject.SetActive(true);
            facilityPallete.facilityBuildButton.GetComponent <Button>().interactable = true;

            txtdescription.text = "<size=22>" + Building.GetDescription(facilityPallete.currentType, facilityPallete.currentItem, facilityPallete.currentLevel) + "</size>";
        }
        else
        {
            txtdescription.gameObject.SetActive(false);
            facilityPallete.facilityBuildButton.GetComponent <Button>().interactable = false;
        }
        ClearProduct(facilityPallete.ValidProduct.Count);

        if (facilityPallete.currentType != BuildingType.None)
        {
            if (facilityPallete.ValidProduct.Count > 0)
            {
                productcontent.gameObject.SetActive(true);
                for (int i = 0; i < facilityPallete.ValidProduct.Count; i++)
                {
                    Product_Item product = null;

                    if (i < productcontent.childCount)
                    {
                        product = productcontent.GetChild(i).GetComponent <Product_Item>();
                    }
                    else
                    {
                        product = GenerateProductItem(i);
                    }

                    product.type = facilityPallete.ValidProduct[i];
                    product.UpdateItemDisplay();
                }
                if (facilityPallete.currentItem != ItemType.NUM)
                {
                    soulcontent.transform.gameObject.SetActive(true);

                    requireSoul         = Building.GetRequireSouls(facilityPallete.currentType, facilityPallete.currentLevel);
                    soulcontent.num     = gameManager.itemManager.ItemsOwn[ItemType.Soul];
                    soulcontent.numneed = requireSoul;
                }
            }
            else
            {
                soulcontent.transform.gameObject.SetActive(true);

                requireSoul         = Building.GetRequireSouls(facilityPallete.currentType, facilityPallete.currentLevel);
                soulcontent.num     = gameManager.itemManager.ItemsOwn[ItemType.Soul];
                soulcontent.numneed = requireSoul;
            }

            productcontent.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, productcontent.childCount * width * UnityEngine.Screen.height);
        }

        UpdateLevelButton();
        UpdateItem(soulcontent);
    }