public ActionResult Insert(MCustomer viewModel, FormCollection formCollection) { RefAddress address = new RefAddress(); 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); RefPerson person = new RefPerson(); 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); MCustomer customer = new MCustomer(); TransferFormValuesTo(customer, viewModel); customer.SetAssignedIdTo(viewModel.Id); customer.CreatedDate = DateTime.Now; customer.CreatedBy = User.Identity.Name; customer.DataStatus = EnumDataStatus.New.ToString(); customer.AddressId = address; customer.PersonId = person; _mCustomerRepository.Save(customer); try { _mCustomerRepository.DbContext.CommitChanges(); } catch (Exception e) { _mCustomerRepository.DbContext.RollbackTransaction(); //throw e.GetBaseException(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
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")); }