public async Task <ActionResult <QuestItem> > Put(QuestItem questItem)
        {
            if (questItem == null)
            {
                return(BadRequest());
            }
            if (!_db.QuestItems.Any(x => x.Id == questItem.Id))
            {
                return(NotFound());
            }

            var itemId         = _db.QuestItems.AsNoTracking().First(x => x.Id == questItem.Id).ItemId;
            var amountReady    = _db.Items.AsNoTracking().First(x => x.Id == itemId).AmountReady;
            var amountReserved = _db.QuestItems
                                 .AsNoTracking()
                                 .Where(x => x.ItemId == itemId && x.Id != questItem.Id && x.IsReady)
                                 .Sum(x => x.AmountNeeded);

            questItem.IsReady     = amountReady - amountReserved >= questItem.AmountNeeded;
            questItem.Quest       = null;
            questItem.StartingNpc = null;
            questItem.Item        = null;

            _db.Update(questItem);
            await _db.SaveChangesAsync();

            return(Ok(questItem));
        }
Esempio n. 2
0
        public async Task <ActionResult <Location> > Put(Location location)
        {
            if (location == null)
            {
                return(BadRequest());
            }
            if (!_db.Locations.Any(x => x.Id == location.Id))
            {
                return(NotFound());
            }

            var oldLocation = _db.Locations.AsNoTracking().First(x => x.Id == location.Id);

            if (oldLocation.RequestsPayed == 0 && location.RequestsPayed > 0)
            {
                AddMaterialsRequest(location);
            }

            if (oldLocation.RequestsPayed > 0 && location.RequestsPayed == 0)
            {
                DeleteMaterialsRequest(location);
            }

            _db.Update(location);
            await _db.SaveChangesAsync();

            return(Ok(location));
        }
Esempio n. 3
0
        public async Task <ActionResult <Material> > Put(Material material)
        {
            if (material == null)
            {
                return(BadRequest());
            }
            if (!_db.Materials.Any(x => x.Id == material.Id))
            {
                return(NotFound());
            }

            var oldMaterial = _db.Materials.AsNoTracking().First(x => x.Id == material.Id);

            if (oldMaterial.AmountPerPayedRequestInLocation == 0 && material.AmountPerPayedRequestInLocation > 0)
            {
                AddSingleMaterialRequests(material.Name);
            }

            if (oldMaterial.AmountPerPayedRequestInLocation > 0 && material.AmountPerPayedRequestInLocation == 0)
            {
                DeleteSingleMaterialRequests(material.Name);
            }

            _db.Update(material);
            await _db.SaveChangesAsync();

            return(Ok(material));
        }
Esempio n. 4
0
        public async Task <ActionResult <Item> > Put(Item item)
        {
            if (item == null)
            {
                return(BadRequest());
            }
            if (!_db.Items.Any(x => x.Id == item.Id))
            {
                return(NotFound());
            }

            _db.Update(item);
            await _db.SaveChangesAsync();

            await UpdateQuestItemsReadiness(item.Id, item.AmountReady);

            return(Ok(item));
        }
Esempio n. 5
0
        public async Task <ActionResult <Quest> > Put(Quest quest)
        {
            if (quest == null)
            {
                return(BadRequest());
            }
            if (!_db.Quests.Any(x => x.Id == quest.Id))
            {
                return(NotFound());
            }

            _db.Update(quest);
            await _db.SaveChangesAsync();

            return(Ok(quest));
        }
        public async Task <ActionResult <Npc> > Put(Npc npc)
        {
            if (npc == null)
            {
                return(BadRequest());
            }
            if (!_db.Npcs.Any(x => x.Id == npc.Id))
            {
                return(NotFound());
            }

            _db.Update(npc);
            await _db.SaveChangesAsync();

            return(Ok(npc));
        }
Esempio n. 7
0
        public async Task <ActionResult <Player> > Put(Player player)
        {
            if (player == null)
            {
                return(BadRequest());
            }
            if (!_db.Players.Any(x => x.Id == player.Id))
            {
                return(NotFound());
            }

            _db.Update(player);
            await _db.SaveChangesAsync();

            return(Ok(player));
        }
Esempio n. 8
0
        public async Task <ActionResult <Chain> > Put(Chain chain)
        {
            if (chain == null)
            {
                return(BadRequest());
            }
            if (!_db.Chains.Any(x => x.Id == chain.Id))
            {
                return(NotFound());
            }

            _db.Update(chain);
            await _db.SaveChangesAsync();

            return(Ok(chain));
        }
Esempio n. 9
0
        public async Task <ActionResult <SingleMaterialRequestInfoView> > Put(SingleMaterialRequestInfoView singleMaterialRequestInfoView)
        {
            if (singleMaterialRequestInfoView == null)
            {
                return(BadRequest());
            }
            if (!_db.SingleMaterialRequests.Any(x => x.Id == singleMaterialRequestInfoView.Id))
            {
                return(NotFound());
            }
            var singleMaterialRequest = _db.SingleMaterialRequests.First(x => x.Id == singleMaterialRequestInfoView.Id);

            singleMaterialRequest.QuantityServed = singleMaterialRequestInfoView.QuantityServed;
            _db.Update(singleMaterialRequest);
            await _db.SaveChangesAsync();

            return(Ok(singleMaterialRequest));
        }