public ActionResult Insert(MEmployee viewModel, FormCollection formCollection) { MEmployee mEmployeeToInsert = new MEmployee(); RefPerson person = new RefPerson(); RefAddress address = new RefAddress(); TransferFormValuesTo(person, formCollection); person.SetAssignedIdTo(Guid.NewGuid().ToString()); person.CreatedDate = DateTime.Now; person.CreatedBy = User.Identity.Name; person.DataStatus = EnumDataStatus.New.ToString(); _refPersonRepository.Save(person); TransferFormValuesTo(address, formCollection); address.SetAssignedIdTo(Guid.NewGuid().ToString()); address.CreatedDate = DateTime.Now; address.CreatedBy = User.Identity.Name; address.DataStatus = EnumDataStatus.New.ToString(); _refAddressRepository.Save(address); TransferFormValuesTo(mEmployeeToInsert, viewModel); mEmployeeToInsert.DepartmentId = _mDepartmentRepository.Get(formCollection["DepartmentId"]); mEmployeeToInsert.SetAssignedIdTo(viewModel.Id); mEmployeeToInsert.CreatedDate = DateTime.Now; mEmployeeToInsert.CreatedBy = User.Identity.Name; mEmployeeToInsert.DataStatus = EnumDataStatus.New.ToString(); mEmployeeToInsert.PersonId = person; mEmployeeToInsert.AddressId = address; _mEmployeeRepository.Save(mEmployeeToInsert); try { _mEmployeeRepository.DbContext.CommitChanges(); } catch (Exception e) { _mEmployeeRepository.DbContext.RollbackTransaction(); //throw e.GetBaseException(); return(Content(e.GetBaseException().Message)); } return(Content("Data Karyawan Berhasil Disimpan")); }
public ActionResult Delete(MDepartment viewModel, FormCollection formCollection) { MDepartment mCompanyToDelete = _mDepartmentRepository.Get(viewModel.Id); if (mCompanyToDelete != null) { _mDepartmentRepository.Delete(mCompanyToDelete); } try { _mDepartmentRepository.DbContext.CommitChanges(); } catch (Exception e) { _mDepartmentRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }