public ActionResult Create(DeductionViewModels collection) { try { if (ModelState.IsValid) { Deduction toDB = new Deduction(); toDB.Active = 1; toDB.DeductionDescription = collection.DeductionDescription; toDB.DeductionName = collection.DeductionName; //toDB.DeductionValue = collection.DeductionValue; toDB.Order = collection.Order; deductionBL.InsertDeduction(toDB); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Error."); return(View(collection)); } } catch { ModelState.AddModelError("", "Error."); return(View(collection)); } }
public ActionResult Edit(DeductionViewModels viewModel) { try { if (ModelState.IsValid) { int active = 0; if (viewModel.Active) { active = 1; } Deduction toDB = new Deduction(); toDB.Active = active; toDB.DeductionDescription = viewModel.DeductionDescription; toDB.DeductionName = viewModel.DeductionName; //toDB.DeductionValue = viewModel.DeductionValue; toDB.DeductionId = viewModel.DeductionId; toDB.Order = viewModel.Order; deductionBL.UpdateDeduction(toDB); return(RedirectToAction("Index")); } else { ModelState.AddModelError("", "Error."); return(View(viewModel)); } } catch { ModelState.AddModelError("", "Error."); return(View(viewModel)); } }
public ActionResult Edit(int id) { Deduction deduction = deductionBL.GetDeductionById(id); DeductionViewModels model = new DeductionViewModels(); model = new DeductionViewModels(); model.Active = Convert.ToBoolean(deduction.Active); model.DeductionDescription = deduction.DeductionDescription; model.DeductionId = deduction.DeductionId; model.DeductionName = deduction.DeductionName; //model.DeductionValue = deduction.DeductionValue; model.Order = deduction.Order; return(View(model)); }
public ActionResult Index() { List <DeductionViewModels> listModels = new List <DeductionViewModels>(); DeductionViewModels model = new DeductionViewModels(); List <Deduction> fromDB = deductionBL.GetAllDeductions(); foreach (Deduction item in fromDB) { model = new DeductionViewModels(); model.Active = Convert.ToBoolean(item.Active); model.DeductionDescription = item.DeductionDescription; model.DeductionId = item.DeductionId; model.DeductionName = item.DeductionName; //model.DeductionValue = item.DeductionValue; model.Order = item.Order; listModels.Add(model); } return(View(listModels)); }