public ActionResult Create(PriceListViewModel viewModel) { if (!ModelState.IsValid) { return View(viewModel); } PriceList priceList = Mapper.Map<PriceList>(viewModel); ServiceResult result = _priceListService.AddPriceList(priceList); if (!result.IsValid) { result.Errors.ToList().ForEach(x => ModelState.AddModelError(x.Key.ToString(), x.Value)); return View(); } TempData["message"] = "price list has been added"; return RedirectToAction("Index"); }
public ActionResult Edit(PriceListViewModel viewModel) { if (viewModel == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } if (!ModelState.IsValid) { return View(viewModel); } PriceList priceList = _priceListService.GetPriceList(viewModel.ID); priceList.PriceListItems.ToList().ForEach(x => { priceList.PriceListItems.Remove(x); _priceListService.RemovePriceListItem(x); }); Mapper.Map(viewModel, priceList); ServiceResult result = _priceListService.UpdatePriceList(priceList); if (!result.IsValid) { result.Errors.ToList().ForEach(x => ModelState.AddModelError(x.Key.ToString(), x.Value)); return View(); } TempData["message"] = "Price List has been edited"; return RedirectToAction("Index"); }