Example #1
0
        //Покупка
        public string Sell(string destination, DateTime nowTime)
        {
            //Выбираем все рейсы в искомую точку и сортируем по времени
            var basicReises = BasicReisEntitie.GetAll().Where(x => x.To.Trim() == destination.Trim()).Select(x => x.CodeBasicReis);
            var reises      = ReisEntitie.GetAll().Where(x => basicReises.Contains((int)x.CodeBasicReis)).OrderBy(x => x.Date);
            //Выбираем из подходящих рейсов, рейсы на которые есть места
            var freeReises = reises.Where(x => PlainsEntitie.GetAll().Single(plain => plain.CodePlane == x.BasicReis.CodePlain).NumberOfSeats - ClientsEntitie.GetAll().Where(client => client.CodeReis == x.CodeReis).Count() > 0);
            //Выбираем первый, по времени, рейс на который есть места
            var total = freeReises.SkipWhile(x => x.Date < nowTime).DefaultIfEmpty(null).First();

            if (total != null)
            {
                Clients tempClient = new Clients();
                tempClient.BookOrBuy = true;
                tempClient.CodeReis  = total.CodeReis;
                ClientsEntitie.AddElement(tempClient);

                Bank tempBank = new Bank();
                tempBank.Ammount = total.BasicReis.Price;
                tempBank.Date    = total.Date;
                tempBank.Comment = String.Format("Платеж за билет на рейс {0}", total.CodeReis);
                BankEntitie.AddElement(tempBank);
                return(String.Format("Продан билет на рейс {0} в {1} на {2}", total.CodeReis, total.BasicReis.To.Trim(), total.Date));
            }
            else
            {
                return(String.Format("Билетов в {0} нет на допустимый период", destination));
            }
        }
Example #2
0
        public void TestBankAddGetUpdateDelete()
        {
            //Add-Get-Тест
            decimal? ammount = 2000;
            DateTime date    = DateTime.Now;

            Bank expectedBank = new Bank();

            expectedBank.Ammount = ammount;
            expectedBank.Date    = date;

            DataAccessBank bank = new DataAccessBank();

            bank.AddElement(expectedBank);
            var actualBank = bank.GetAll().Last();

            Assert.AreEqual(expectedBank, actualBank);

            //Update - Тест
            expectedBank         = actualBank;
            expectedBank.Ammount = 3000;
            bank.UpdateElement(expectedBank);
            actualBank = bank.GetElement(expectedBank.CodePayment);
            Assert.AreEqual(expectedBank, actualBank);

            //Delete-Тест
            int expectedCount = bank.GetAll().Count() - 1;

            bank.DeleteElement(actualBank);
            int actualCount = bank.GetAll().Count();

            Assert.AreEqual(expectedCount, actualCount);
        }
        public void TestBankAddGetUpdateDelete()
        {
            //Add-Get-Тест
            decimal? ammount = 2000;
            DateTime date = DateTime.Now;

            Bank expectedBank = new Bank();
            expectedBank.Ammount = ammount;
            expectedBank.Date = date;

            DataAccessBank bank = new DataAccessBank();
            bank.AddElement(expectedBank);
            var actualBank = bank.GetAll().Last();
            Assert.AreEqual(expectedBank, actualBank);

            //Update - Тест
            expectedBank = actualBank;
            expectedBank.Ammount = 3000;
            bank.UpdateElement(expectedBank);
            actualBank = bank.GetElement(expectedBank.CodePayment);
            Assert.AreEqual(expectedBank, actualBank);

            //Delete-Тест
            int expectedCount = bank.GetAll().Count() - 1;
            bank.DeleteElement(actualBank);
            int actualCount = bank.GetAll().Count();
            Assert.AreEqual(expectedCount, actualCount);
        }