Exemple #1
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TaxRate taxRate = taxRateService.Find(id.Value);
            var     model   = Mapper.Map <TaxRateEditViewModel>(taxRate);

            foreach (var taxClass in taxClassService.FindAll().ToList())
            {
                var taxClassRateEditViewModel = new TaxClassRateEditViewModel
                {
                    TaxClassId   = taxClass.Id,
                    TaxClassName = taxClass.Name,
                };

                var taxClassRate = taxRate.ClassRates.FirstOrDefault(r => r.TaxClassId == taxClass.Id);
                if (taxClassRate != null)
                {
                    taxClassRateEditViewModel.Amount = taxClassRate.Amount;
                }
                model.ClassRates.Add(taxClassRateEditViewModel);
            }
            ViewBag.TaxZoneId =
                new SelectList(taxZoneService.FindAll().Where(z => z.IsActive || z.Id == model.TaxZoneId).ToList(), "Id",
                               "Name", model.TaxZoneId);
            return(View(model));
        }
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            TaxRate taxRate = taxRateService.Find(id.Value);
            var model = Mapper.Map<TaxRateEditViewModel>(taxRate);

            foreach (var taxClass in taxClassService.FindAll().ToList())
            {
                var taxClassRateEditViewModel = new TaxClassRateEditViewModel
                {
                    TaxClassId = taxClass.Id,
                    TaxClassName = taxClass.Name,
                };

                var taxClassRate = taxRate.ClassRates.FirstOrDefault(r => r.TaxClassId == taxClass.Id);
                if (taxClassRate != null)
                    taxClassRateEditViewModel.Amount = taxClassRate.Amount;
                model.ClassRates.Add(taxClassRateEditViewModel);
            }
            ViewBag.TaxZoneId =
                new SelectList(taxZoneService.FindAll().Where(z => z.IsActive || z.Id == model.TaxZoneId).ToList(), "Id",
                    "Name", model.TaxZoneId);
            return View(model);
        }