public void PaymentVoucherRepository_Create_ShouldSaveANewVoucherInTheDB()
        {
            var voucher = createTestVoucher();
            var vouchers = new PaymentVoucherRepository();

            vouchers.Create(voucher);
        }
        public void PaymentVoucherRepository_Get_ShouldReturnAVoucherWithEntries()
        {
            var voucher = createTestVoucher();
            var vouchers = new PaymentVoucherRepository();

            vouchers.Create(voucher);

            var foundVoucher = vouchers.Get(voucher.ID);
            Assert.IsNotNull(foundVoucher);
            Assert.AreEqual(voucher.ApprovedBy, foundVoucher.ApprovedBy);
            Assert.AreEqual(voucher.CheckNumber, foundVoucher.CheckNumber);
            Assert.AreEqual(voucher.Date, foundVoucher.Date);
            Assert.AreEqual(voucher.PaidTo, foundVoucher.PaidTo);
            Assert.AreEqual(voucher.PreparedBy, foundVoucher.PreparedBy);
            Assert.AreEqual(voucher.ProjectID, foundVoucher.ProjectID);
            Assert.AreEqual(voucher.RBCApproval, foundVoucher.RBCApproval);

            Assert.IsNotNull(foundVoucher.Entries);
            Assert.AreEqual(PaymentVoucher.NumberOfEntriesInAVoucher, foundVoucher.Entries.Count);
        }
        public void PaymentVoucherRepository_Create_ShouldSaveEntries()
        {
            //Create test voucher with a few entries
            var voucher = createTestVoucher();
            var vouchers = new PaymentVoucherRepository();

            var entries = new List<PaymentVoucherEntry>();
            for (int i = 0; i < 10; i++)
            {
                var entry = createTestVoucherEntry(voucher.ID);
                entries.Add(entry);
            }

            //save it
            voucher.Entries = entries;
            vouchers.Create(voucher);

            //query it back out
            var newFoundVoucher = vouchers.Get(voucher.ID);

            Assert.IsNotNull(newFoundVoucher.Entries);
            Assert.AreEqual(PaymentVoucher.NumberOfEntriesInAVoucher, newFoundVoucher.Entries.Count);
        }
        public ActionResult Delete(Guid VoucherID)
        {
            var vouchers = new PaymentVoucherRepository();
            var voucher = vouchers.Get(VoucherID);
            var projID = voucher.ProjectID;

            vouchers.Delete(voucher);

            return RedirectToAction("Index", new { ProjectID = projID });
        }
        public ActionResult Print(Guid VoucherID)
        {
            var voucher = new PaymentVoucherRepository().Get(VoucherID);

            return File(voucher.Print(), "application/pdf");
        }
        public ActionResult Edit(PaymentVoucher model)
        {
            var vouchers = new PaymentVoucherRepository();
            model.PreparedBy = UserRepository.CurrentUserName;

            if (ModelState.IsValid)
            {
                vouchers.Update(model);
                return RedirectToAction("Index", new { ProjectID = model.ProjectID });
            }
            else
            {
                var v = vouchers.Get(model.ID);
                model.Project = v.Project;
                return View("Edit", model);
            }
        }
        public ActionResult Edit(Guid VoucherID)
        {
            var voucher = new PaymentVoucherRepository().Get(VoucherID);

            //If there is no such Payment Voucher,then go back to the list of Vouchers
            if (voucher == null)
            {
                return HttpNotFound();
            }

            return View("Edit", voucher);
        }