public ActionResult Update(MEmployee viewModel, FormCollection formCollection) { UpdateNumericData(viewModel, formCollection); MEmployee mEmployeeToUpdate = _mEmployeeRepository.Get(viewModel.Id); TransferFormValuesTo(mEmployeeToUpdate, viewModel); mEmployeeToUpdate.DepartmentId = _mDepartmentRepository.Get(formCollection["DepartmentId"]); mEmployeeToUpdate.ModifiedDate = DateTime.Now; mEmployeeToUpdate.ModifiedBy = User.Identity.Name; mEmployeeToUpdate.DataStatus = EnumDataStatus.Updated.ToString(); RefPerson person = mEmployeeToUpdate.PersonId; if (person == null) { 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); mEmployeeToUpdate.PersonId = person; } else { TransferFormValuesTo(person, formCollection); person.ModifiedDate = DateTime.Now; person.ModifiedBy = User.Identity.Name; person.DataStatus = EnumDataStatus.Updated.ToString(); } _mEmployeeRepository.Update(mEmployeeToUpdate); try { _mEmployeeRepository.DbContext.CommitChanges(); } catch (Exception e) { _mEmployeeRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
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); UpdateNumericData(viewModel, formCollection); MCustomer mCustomerToInsert = new MCustomer(); TransferFormValuesTo(mCustomerToInsert, viewModel); mCustomerToInsert.SetAssignedIdTo(viewModel.Id); mCustomerToInsert.CreatedDate = DateTime.Now; mCustomerToInsert.CreatedBy = User.Identity.Name; mCustomerToInsert.DataStatus = EnumDataStatus.New.ToString(); mCustomerToInsert.AddressId = address; mCustomerToInsert.PersonId = person; _mCustomerRepository.Save(mCustomerToInsert); 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")); }
public ActionResult Registration(MCustomer customer, FormCollection formCollection) { _mCustomerRepository.DbContext.BeginTransaction(); RefAddress address = new RefAddress(); RefPerson person = new RefPerson(); 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(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, cust); if (customer == null) { customer = new MCustomer(); } customer.SetAssignedIdTo(formCollection["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(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success; } catch (Exception e) { _mCustomerRepository.DbContext.RollbackTransaction(); TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed; TempData[EnumCommonViewData.ErrorMessage.ToString()] = e.Message; //throw e.GetBaseException(); var result = new { Success = false, Message = e.Message }; return(Json(result, JsonRequestBehavior.AllowGet)); } var resultx = new { Success = true, Message = //Helper.ViewHelper.RenderPartialToString("~/Views/Shared/Status.ascx", "", null, this.ControllerContext.RequestContext) @" <div class='ui-state-highlight ui-corner-all' style='padding: 5pt; margin-bottom: 5pt;'> <p> <span class='ui-icon ui-icon-info' style='float: left; margin-right: 0.3em;'></span> Data berhasil disimpan.</p> </div>" }; return(Json(resultx, JsonRequestBehavior.AllowGet)); //return View("Status"); }