示例#1
0
 public Item(NewItem i)
 {
     Id           = Guid.NewGuid();
     Level        = i.Level;
     ItemType     = i.ItemType;
     CreationDate = DateTime.UtcNow;
 }
示例#2
0
        public Task <Player> AddNewItem(Guid id, [FromBody] NewItem newItem)
        {
            Item i = new Item(newItem);

            Console.WriteLine("AddNewItem");
            return(repo.AddNewItem(id, i));
        }
        public Task <Item> CreateItem(Guid playerId, NewItem item)
        {
            Item createItem = new Item()
            {
                Id = Guid.NewGuid(), Name = item.Name
            };

            return(_repository.CreateItem(playerId, createItem));
        }
示例#4
0
        public static Item Create(NewItem newItem)
        {
            var createdItem = new Item
            {
                Type  = (ItemType)newItem.Type,
                Level = (int)newItem.Level
            };

            return(createdItem);
        }
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            NewItem item = (NewItem)validationContext.ObjectInstance;

            if (item.CreationDate != DateTime.Today)
            {
                return(new ValidationResult(GetErrorMessage()));
            }
            return(ValidationResult.Success);
        }
示例#6
0
        //[Route("{playerId:Guid}")]
        public async Task <Item> CreateItem(Guid playerId, [FromBody] NewItem newItem)
        {
            Item _item = new Item();

            _item.Id           = Guid.NewGuid();
            _item.CreationTime = DateTime.UtcNow;
            _item.Level        = newItem.Level;
            _item.Type         = newItem.Type;

            return(await _repository.CreateItem(playerId, _item));
        }
示例#7
0
        public Task <Item> CreateItem(Guid id, NewItem item)
        {
            Item newItem = new Item()
            {
                Level        = item.Level,
                Type         = item.Type,
                CreationDate = DateTime.Now,
                ItemId       = Guid.NewGuid()
            };

            return(_repo.CreateItem(id, newItem));
        }
示例#8
0
        public async Task <Item> Create(Guid playerId, [FromBody] NewItem newItem)
        {
            var player = await playerRepository.GetPlayerById(playerId);

            if (player.Level < 3 && newItem.Type == ItemType.Sword)
            {
                throw new PlayerLevelException();
            }
            Item createdItem = Item.Create(newItem);

            return(await playerRepository.InsertItem(playerId, createdItem));
        }
示例#9
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            NewItem newItem = (NewItem)validationContext.ObjectInstance;

            Console.WriteLine("Validating new item CreationDate: " + newItem.CreationDate);
            if (newItem.CreationDate > DateTime.UtcNow)
            {
                Console.WriteLine("CreationTime must be in the past");
                return(new ValidationResult("CreationTime must be in the past"));
            }
            Console.WriteLine("New item creation date validated");
            return(ValidationResult.Success);
        }
        public async Task <Player> CreateItemQuery(Guid playerid, NewItem newItem)
        {
            Item item = new Item()
            {
                Level        = newItem.Level,
                Type         = newItem.Type,
                CreationDate = DateTime.Now,
                ItemId       = Guid.NewGuid()
            };
            var filter = Builders <Player> .Filter.Eq(player => player.Id, playerid);

            var push = Builders <Player> .Update.Push("PlayerItems", item);

            return(await _laattapisteCollection.FindOneAndUpdateAsync(filter, push));
        }
示例#11
0
        public async Task <Item> CreateItem(Guid player, NewItem item)
        {
            Player player1    = new Player();
            Item   itemresult = new Item();

            try
            {
                player1 = await _repository.Get(player);
            }
            catch (NotFoundException e)
            {
                Console.WriteLine("Player Guid not found" + e);
            }

            if (player1.Level < 3 && item._type == NewItem.ItemType.SWORD)
            {
                throw new LevelException(player1.Name);
            }


            Guid guid = Guid.NewGuid();

            Console.WriteLine("Comes Here");

            Item origItem = new Item();

            origItem.Name = item.Name;

            origItem.Level = item.Level;

            origItem.Id = guid;

            origItem._type = item._type;               //Item.ItemType.POTION;

            origItem.CreationTime = item.CreationTime; //System.DateTime.Now;



            player1.items.Add(origItem);

            itemresult = await _repository.CreateItem(player1.Id, origItem);

            player1.items.Add(itemresult);


            return(origItem);
        }
示例#12
0
        public async Task <Item> CreateItem(Guid playerId, [FromBody] NewItem item)
        {
            if (item.ItemType == Type.SWORD)
            {
                Player p = await repo.Get(playerId);

                if (p != null)
                {
                    if (p.Level < 3)
                    {
                        throw new NotAllowedException();
                    }
                }
            }

            Console.WriteLine("HttpPost: Create item");
            return(await repo.CreateItem(playerId, item));
        }
示例#13
0
        public Task <Item> CreateItem(Guid id, NewItem item)
        {
            Player p = _playerData.Players.Find(pl => pl.Id == id);

            if (p == null)
            {
                throw new NotFoundException("Not Found");
            }

            Item newItem = new Item()
            {
                Id       = Guid.NewGuid(),
                Price    = item.Price,
                ItemType = item.ItemType,
            };

            p.ItemList.Add(newItem);
            return(Task.FromResult <Item>(newItem));
        }
        public async Task <Item> CreateItem(Guid id, NewItem item)
        {
            var filter = Builders <Player> .Filter.Eq(p => p.Id, id);

            Player pl = _collection.Find(filter).FirstAsync().Result;
            Item   i  = new Item()
            {
                ItemType = item.ItemType,
                Id       = Guid.NewGuid(),
                Price    = item.Price
            };

            pl.ItemList.Add(i);

            var replace = Builders <Player> .Update.Set(player => player.ItemList, pl.ItemList);

            await _collection.UpdateOneAsync(filter, replace);

            return(await Task.FromResult <Item>(pl.ItemList[pl.ItemList.Count - 1]));
        }
示例#15
0
        public async Task <Item> CreateItem(Guid playerId, NewItem newItem)
        {
            ModifiedPlayer modP = new ModifiedPlayer();
            Player         p    = await Get(playerId);

            if (p == null)
            {
                throw new NotFoundException();
            }
            else
            {
                Item i = new Item(newItem);

                if (p != null)
                {
                    modP.Score = p.Score;
                    modP.item  = i;
                }

                await Modify(playerId, modP);

                return(i);
            }
        }
示例#16
0
 public Task <Player> CreateItemQuery(Guid playerid, NewItem newItem)
 {
     throw new NotImplementedException();
 }
示例#17
0
 public Task <Player> CreateItemQuery(Guid playerid, NewItem newItem)
 {
     return(_repo.CreateItemQuery(playerid, newItem));
 }