public void DeleteVoucherBatch(VoucherBatch voucherBatch)
        {
            var voucherCodes = voucherBatch.VoucherCodes;
            for (int i = 0; i < voucherCodes.Count(); i++)
            {
                VoucherCodeService.DeleteVoucherCode(voucherCodes.ToArray()[i]);
            }

            VoucherBatchRepository.Delete(voucherBatch);
            SaveVoucherBatch();
        }
        public ActionResult Create(CreateViewModel createViewModel)
        {
            if (!ModelState.IsValid)
            {
                return View(createViewModel);
            }

            var selectedTrip = TripService.FindById(createViewModel.DropDownList_Trip_Property.SelectedTrip);
            var selectedCruise = CruiseService.FindById(createViewModel.DropDownList_Cruise_Property.SelectedCruise);
            var selectedVoucherTemplate = VoucherTemplateService.FindById(createViewModel.DropDownList_VoucherTemplate_Property.SelectedVoucherTemplate);

            var voucherBatch = new VoucherBatch()
            {
                Name = createViewModel.Name,
                Description = createViewModel.Description,
                ValidUntil = createViewModel.ValidUntil,
                IssueDate = createViewModel.IssueDate,
                Note = createViewModel.Note,
                Value = createViewModel.Value,
                Trip = selectedTrip,
                TripId = createViewModel.DropDownList_Trip_Property.SelectedTrip != -1 ? (int?)createViewModel.DropDownList_Trip_Property.SelectedTrip : null,
                Cruise = selectedCruise,
                CruiseId = createViewModel.DropDownList_Cruise_Property.SelectedCruise != -1 ? (int?)createViewModel.DropDownList_Cruise_Property.SelectedCruise : null,
                VoucherTemplate = selectedVoucherTemplate,
                VoucherTemplateId = createViewModel.DropDownList_VoucherTemplate_Property.SelectedVoucherTemplate != -1 ? (int?)createViewModel.DropDownList_VoucherTemplate_Property.SelectedVoucherTemplate : null
            };

            VoucherBatchService.CreateVoucherBatch(voucherBatch);

            var voucherCodes = (List<string>)TempData["VoucherCodes"];
            for (int i = 0; i < voucherCodes.Count(); i++)
            {
                var voucherCode = new VoucherCode()
                {
                    VoucherCodeString = voucherCodes.ToArray()[i],
                    VoucherBatchId = voucherBatch.VoucherBatchId,
                    VoucherBatch = voucherBatch
                };

                if (voucherCode.VoucherBatch != null)
                {
                    voucherCode.VoucherBatchId = voucherCode.VoucherBatch.VoucherBatchId;
                }
                else
                {
                    voucherCode.VoucherBatchId = null;
                }
                VoucherCodeService.CreateVoucherCode(voucherCode);
            }
            TempData["VoucherBatchId"] = voucherBatch.VoucherTemplateId;
            TempData["VoucherBatchName"] = voucherBatch.Name;
            TempData["Message"] = VoucherBatchesMessage.CreateSuccess;
            return RedirectToAction("index", "voucherbatches");
        }
 public void UpdateVoucherBatch(VoucherBatch voucherBatch)
 {
     VoucherBatchRepository.Update(voucherBatch);
     SaveVoucherBatch();
 }
 public void CreateVoucherBatch(VoucherBatch voucherBatch)
 {
     VoucherBatchRepository.Add(voucherBatch);
     SaveVoucherBatch();
 }