public ActionResult Insert(MActionCat viewModel, FormCollection formCollection) { MActionCat mItemCatToInsert = new MActionCat(); TransferFormValuesTo(mItemCatToInsert, viewModel); mItemCatToInsert.SetAssignedIdTo(viewModel.Id); mItemCatToInsert.CreatedDate = DateTime.Now; mItemCatToInsert.CreatedBy = User.Identity.Name; mItemCatToInsert.DataStatus = EnumDataStatus.New.ToString(); _mActionCatRepository.Save(mItemCatToInsert); try { _mActionCatRepository.DbContext.CommitChanges(); } catch (Exception e) { _mActionCatRepository.DbContext.RollbackTransaction(); //throw e.GetBaseException(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
public ActionResult Delete(MActionCat viewModel, FormCollection formCollection) { MActionCat mItemCatToDelete = _mActionCatRepository.Get(viewModel.Id); if (mItemCatToDelete != null) { _mActionCatRepository.Delete(mItemCatToDelete); } try { _mActionCatRepository.DbContext.CommitChanges(); } catch (Exception e) { _mActionCatRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
public ActionResult Update(MActionCat viewModel, FormCollection formCollection) { MActionCat mItemCatToUpdate = _mActionCatRepository.Get(viewModel.Id); TransferFormValuesTo(mItemCatToUpdate, viewModel); mItemCatToUpdate.ModifiedDate = DateTime.Now; mItemCatToUpdate.ModifiedBy = User.Identity.Name; mItemCatToUpdate.DataStatus = EnumDataStatus.Updated.ToString(); _mActionCatRepository.Update(mItemCatToUpdate); try { _mActionCatRepository.DbContext.CommitChanges(); } catch (Exception e) { _mActionCatRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
private void TransferFormValuesTo(MActionCat mItemCatToUpdate, MActionCat mItemCatFromForm) { mItemCatToUpdate.ActionCatName = mItemCatFromForm.ActionCatName; mItemCatToUpdate.ActionCatDesc = mItemCatFromForm.ActionCatDesc; }