コード例 #1
0
        public IList<Game> Get()
        {
            this.Load();
            var list = new List<Game>();

            foreach (XElement jogo in this.xmlGames.Elements("jogo"))
            {
                string id = jogo.Attribute("id").Value;
                string name = jogo.Element("nome").Value;
                string price = jogo.Element("preco").Value;
                string category = jogo.Element("categoria").Value;
                string available = jogo.Element("disponivel").Value;

                var game = new Game()
                {
                    Id = Convert.ToInt32(id),
                    Name = name,
                    Price = Convert.ToDouble(price),
                    Category = (GameCategory)Enum.Parse(typeof(GameCategory), category),
                    Available = available == "SIM"
                };

                list.Add(game);
            }

            return list;
        }
コード例 #2
0
        public void Add(Game game)
        {
            this.Load();
            game.Id = this.Identity();

            XElement srcTree = new XElement("jogo",
                new XElement("nome", game.Name),
                new XElement("preco", game.Price),
                new XElement("categoria", game.Category),
                new XElement("disponivel", "SIM"));

            srcTree.SetAttributeValue("id", game.Id);

            this.xmlGames.Add(srcTree);
        }
コード例 #3
0
        public void Insert()
        {
            var unitOfWork = new GameUnitOfWork();
            var service = new GameDomainService(unitOfWork);

            var game = new Game()
            {
                Name = "Test",
                Price = 100,
                Category = GameCategory.RPG
            };

            service.Insert(game);
            unitOfWork.Commit();

            //Deve haver ao menos 1 game que o nome inicie com Tes
            Assert.IsTrue(service.FindByName("Tes").Count > 0);
        }
コード例 #4
0
        public void Delete()
        {
            var unitOfWork = new GameUnitOfWork();
            var service = new GameDomainService(unitOfWork);

            var game = new Game()
            {
                Name = "Delete",
                Price = 100,
                Category = GameCategory.RPG
            };

            service.Insert(game);
            unitOfWork.Commit();

            //Deve haver 1 registro (adicionado acima)
            Assert.IsTrue(service.FindByName("Delet").Count > 0);

            service.Delete(game);
            unitOfWork.Commit();

            //Nao deve haver registros
            Assert.IsTrue(service.FindByName("Delet").Count == 0);
        }
コード例 #5
0
 public void Remove(Game game)
 {
     this.Load();
     XElement element = this.XElementById(game.Id);
     element.Remove();
 }
コード例 #6
0
        public void Update(Game game)
        {
            this.Load();
            XElement element = this.XElementById(game.Id);

            element.Element("nome").Value = game.Name;
            element.Element("preco").Value = game.Price.ToString();
            element.Element("categoria").Value = game.Category.ToString();
            element.Element("disponivel").Value = game.Available ? "SIM" : "NÂO";
        }
コード例 #7
0
        public void Insert()
        {
            Console.Clear();

            var unitOfWork = new GameUnitOfWork();

            var service = new GameDomainService(unitOfWork);

            Console.WriteLine("Digite o nome >");
            string name = Console.ReadLine();
            double price;
            try
            {
                Console.WriteLine("Diite o preco >");
                price = Convert.ToDouble(Console.ReadLine(),
                                                System.Globalization.CultureInfo.InvariantCulture);
            }
            catch (Exception e)
            {
                Console.WriteLine("O campo preço aceita somente numeros. Operação abortada, tente novamente! >>>" + e.Message);
                return;
            }

            var game = new Game()
            {
                Name = name,
                Price = price,
                Category = Category()
            };

            service.Insert(game);
            unitOfWork.Commit();
        }
コード例 #8
0
 public void Update(Game game)
 {
     this.unitOfWork.Update(game);
 }
コード例 #9
0
 public void Insert(Game game)
 {
     this.unitOfWork.Add(game);
 }
コード例 #10
0
 public void Delete(Game game)
 {
     this.unitOfWork.Remove(game);
 }