public ActionResult JogosDisponiveis()
        {
            var listJogoModel = new List<JogoModel>();

            string path = @"C:\Users\eric.gottschalk\Documents\CWICrescer2015-2\crescer-2015-2\src\modulo-04-c-sharp\dia-05\Locadora\Locadora.Web\files\game-store.xml";
            var unit = new GameUnitOfWork(path);
            var service = new GameDomainService(unit);
            var list = service.Get().ToList();

            foreach (var jogo in list)
            {
                var jogoModel = new JogoModel()
                {
                    Id = jogo.Id,
                    Name = jogo.Name,
                    Category = jogo.Category,
                    Price = jogo.Price,
                    Available = jogo.Available
                };

                listJogoModel.Add(jogoModel);
            }

            var relatrio = new RelatorioModel(listJogoModel);
            return View(relatrio);
        }
예제 #2
0
        public void Delete()
        {
            Console.Clear();

            var unitOfWork = new GameUnitOfWork();
            var service = new GameDomainService(unitOfWork);

            var game = Find();

            if (game == null)
            {
                Console.WriteLine("Nenhum registro encontrado!");
                return;
            }

            service.Delete(game);
            unitOfWork.Commit();
        }
        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);
        }
        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
        private Game Find()
        {
            var unitOfWork = new GameUnitOfWork();
            var service = new GameDomainService(unitOfWork);

            Console.WriteLine("Digite o id a ser pesquisado:");
            int id;
            try
            {
                id = Convert.ToInt32(Console.ReadLine());
            }
            catch (Exception e)
            {
                Console.WriteLine("Este campo só aceita numeros! Tente novamente. >>> " + e.Message);
                return null;
            }

            return service.FindById(id);
        }
예제 #6
0
        public void Update()
        {
            Console.Clear();

            var unitOfWork = new GameUnitOfWork();
            var service = new GameDomainService(unitOfWork);

            var game = Find();

            if (game == null)
            {
                Console.WriteLine("Nenhum registro encontrado!");
                return;
            }

            Console.WriteLine("Digite o nome >");
            game.Name = Console.ReadLine();
            try
            {
                Console.WriteLine("Diite o preco >");
                game.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;
            }

            game.Category = Category();
            game.Available = Availabe();

            service.Update(game);
            unitOfWork.Commit();
        }
예제 #7
0
        public void Show()
        {
            Console.Clear();
            List<Game> list;

            var unitOfWork = new GameUnitOfWork();
            var service = new GameDomainService(unitOfWork);
            list = service.Get();

            if (list == null || list.Count == 0)
            {
                Console.WriteLine("Nenhum registro encontrado!");
                return;
            }

            foreach (var game in list)
            {
                Console.WriteLine(game.ToString());
            }
        }
예제 #8
0
 public void SaveTxt()
 {
     var unitOfWork = new GameUnitOfWork();
     var service = new GameDomainService(unitOfWork);
     service.SaveTxt();
 }
예제 #9
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();
        }
예제 #10
0
        public void FindByName()
        {
            Console.Clear();

            List<Game> list;

            var unitOfWork = new GameUnitOfWork();

            var service = new GameDomainService(unitOfWork);

            Console.WriteLine("Digite o nome a ser procurado:");
            string name = Console.ReadLine();
            list = service.FindByName(name);

            if (list == null || list.Count == 0)
            {
                Console.WriteLine("Nenhum registro encontrado!");
                return;
            }

            foreach (var game in list)
            {
                Console.WriteLine(game.ToString());
            }
        }
 public GameDomainService(GameUnitOfWork unitOfWork)
 {
     this.unitOfWork = unitOfWork;
 }