public async Task <IActionResult> Create(BoothItem_ViewModel model)
        {
            BoothItem boothItem = new BoothItem();

            boothItem.Color         = model.Color;
            boothItem.IsActive      = model.IsActive;
            boothItem.Name          = model.Name;
            boothItem.Size          = model.Size;
            boothItem.TotalQuantity = model.TotalQuantity;
            boothItem.QuantityRemainingInInventory = boothItem.TotalQuantity; //on creation total quantity and quantity in inventory remaining should be the same


            if (ModelState.IsValid)
            {
                _context.Add(boothItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
        public async Task <IActionResult> Edit(int id, BoothItem_ViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            BoothItem boothItem = _context.BoothItem.FirstOrDefault(b => b.Id == id);

            boothItem.Color                        = model.Color;
            boothItem.IsActive                     = model.IsActive;
            boothItem.Name                         = model.Name;
            boothItem.Size                         = model.Size;
            boothItem.TotalQuantity                = model.TotalQuantity;
            boothItem.QuantityCheckedOut           = model.QuantityCheckedOut;
            boothItem.QuantityRemainingInInventory = boothItem.TotalQuantity - boothItem.QuantityCheckedOut;

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(boothItem);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BoothItemExists(boothItem.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
예제 #3
0
        public Boolean BuyItem(Player Buyer, Int32 ItemUID)
        {
            if (ItemUID == 0)
            {
                return(false);
            }

            if (!World.AllPlayers.ContainsKey(User.UniqId))
            {
                return(false);
            }

            if (OwnerUID == Buyer.UniqId)
            {
                return(false);
            }

            if (!Items.ContainsKey(ItemUID))
            {
                return(false);
            }

            Item Item = User.GetItemByUID(ItemUID);

            if (Item == null)
            {
                DelItem(ItemUID);
                return(false);
            }

            BoothItem BoothItem = Items[ItemUID];

            if (BoothItem.Price <= 0)
            {
                return(false);
            }

            if (Buyer.Money < BoothItem.Price)
            {
                Buyer.SendSysMsg(StrRes.STR_NOT_SO_MUCH_MONEY);
                return(false);
            }

            if (Buyer.ItemInInventory() > 39)
            {
                Buyer.SendSysMsg(StrRes.STR_FULL_CANNOT_PICK);
                return(false);
            }

            DelItem(ItemUID);

            Buyer.Money -= BoothItem.Price;
            User.Money  += BoothItem.Price;

            Buyer.Send(new MsgUserAttrib(Buyer, Buyer.Money, MsgUserAttrib.AttributeType.Money));
            User.Send(new MsgUserAttrib(User, User.Money, MsgUserAttrib.AttributeType.Money));

            Database.Save(Buyer, true);
            Database.Save(User, true);

            User.DelItem(Item, true);
            Buyer.AddItem(Item, true);

            User.SendSysMsg(StrRes.STR_BOOTH_BUY, Buyer.Name, BoothItem.Price, "$", Item.Name);
            return(true);
        }