public ActionResult Insert(MDepartment viewModel, FormCollection formCollection) { MDepartment mCompanyToInsert = new MDepartment(); TransferFormValuesTo(mCompanyToInsert, viewModel); mCompanyToInsert.SetAssignedIdTo(viewModel.Id); mCompanyToInsert.CreatedDate = DateTime.Now; mCompanyToInsert.CreatedBy = User.Identity.Name; mCompanyToInsert.DataStatus = EnumDataStatus.New.ToString(); _mDepartmentRepository.Save(mCompanyToInsert); try { _mDepartmentRepository.DbContext.CommitChanges(); } catch (Exception e) { _mDepartmentRepository.DbContext.RollbackTransaction(); //throw e.GetBaseException(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
public ActionResult Insert(MDepartment viewModel, FormCollection formCollection) { bool isSave = true; MDepartment mCompanyToInsert = new MDepartment(); //if (formCollection["oper"].Equals("edit")) //{ // isSave = false; // mCompanyToInsert = _mDepartmentRepository.Get(viewModel.Id); //} TransferFormValuesTo(mCompanyToInsert, viewModel); mCompanyToInsert.SetAssignedIdTo(viewModel.Id); mCompanyToInsert.CreatedDate = DateTime.Now; mCompanyToInsert.CreatedBy = User.Identity.Name; mCompanyToInsert.DataStatus = EnumDataStatus.New.ToString(); //if (isSave) _mDepartmentRepository.Save(mCompanyToInsert); //else // _mDepartmentRepository.Update(mCompanyToInsert); try { _mDepartmentRepository.DbContext.CommitChanges(); } catch (Exception e) { _mDepartmentRepository.DbContext.RollbackTransaction(); //throw e.GetBaseException(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }