public ActionResult Update(MPartner viewModel, RefAddress addressVm, FormCollection formCollection) { try { _mPartnerRepository.DbContext.BeginTransaction(); MPartner partner = _mPartnerRepository.Get(viewModel.Id); partner.PartnerName = viewModel.PartnerName; partner.PartnerDesc = viewModel.PartnerDesc; partner.PartnerStatus = viewModel.PartnerStatus; partner.ModifiedDate = DateTime.Now; partner.ModifiedBy = User.Identity.Name; partner.DataStatus = EnumDataStatus.Updated.ToString(); RefAddress address = partner.AddressId; if (address == null) { address = new RefAddress(); partner.AddressId = address; address.AddressLine1 = addressVm.AddressLine1; address.SetAssignedIdTo(Guid.NewGuid().ToString()); address.CreatedDate = DateTime.Now; address.CreatedBy = User.Identity.Name; address.DataStatus = EnumDataStatus.New.ToString(); _refAddressRepository.Save(address); } else { address.AddressLine1 = addressVm.AddressLine1; address.ModifiedDate = DateTime.Now; address.ModifiedBy = User.Identity.Name; address.DataStatus = EnumDataStatus.Updated.ToString(); _refAddressRepository.Update(address); } _mPartnerRepository.Update(partner); _mPartnerRepository.DbContext.CommitChanges(); } catch (Exception e) { _mPartnerRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("Data Toko Berhasil Diupdate")); }
public ActionResult Update(MWarehouse viewModel, FormCollection formCollection) { try { MWarehouse mWarehouseToUpdate = _mWarehouseRepository.Get(viewModel.Id); TransferFormValuesTo(mWarehouseToUpdate, viewModel); mWarehouseToUpdate.EmployeeId = _mEmployeeRepository.Get(formCollection["EmployeeId"]); mWarehouseToUpdate.CostCenterId = _mCostCenterRepository.Get(formCollection["CostCenterId"]); mWarehouseToUpdate.ModifiedDate = DateTime.Now; mWarehouseToUpdate.ModifiedBy = User.Identity.Name; mWarehouseToUpdate.DataStatus = EnumDataStatus.Updated.ToString(); bool isSave = false; RefAddress address = mWarehouseToUpdate.AddressId; if (address == null) { address = new RefAddress(); address.SetAssignedIdTo(Guid.NewGuid().ToString()); isSave = true; } address.AddressLine1 = formCollection["AddressLine1"]; address.AddressLine1 = formCollection["AddressLine1"]; address.AddressLine2 = formCollection["AddressLine2"]; address.AddressLine3 = formCollection["AddressLine3"]; address.AddressPhone = formCollection["AddressPhone"]; address.AddressCity = formCollection["AddressCity"]; _refAddressRepository.Save(address); if (isSave) { _refAddressRepository.Save(address); } else { _refAddressRepository.Update(address); } mWarehouseToUpdate.AddressId = address; _mWarehouseRepository.Update(mWarehouseToUpdate); //save account persediaan barang isSave = false; MAccountRef accountRef = GetAccountRef(EnumReferenceTable.Warehouse, mWarehouseToUpdate.Id); if (accountRef == null) { accountRef = new MAccountRef(); accountRef.SetAssignedIdTo(Guid.NewGuid().ToString()); isSave = true; } accountRef.ReferenceId = mWarehouseToUpdate.Id; accountRef.ReferenceTable = EnumReferenceTable.Warehouse.ToString(); accountRef.ReferenceType = EnumReferenceTable.Warehouse.ToString(); accountRef.AccountId = _mAccountRepository.Get(formCollection["AccountId"]); if (isSave) { _mAccountRefRepository.Save(accountRef); } else { _mAccountRefRepository.Update(accountRef); } //save account pemakaian barang isSave = false; accountRef = GetAccountRef(EnumReferenceTable.WarehouseUsing, mWarehouseToUpdate.Id); if (accountRef == null) { accountRef = new MAccountRef(); accountRef.SetAssignedIdTo(Guid.NewGuid().ToString()); isSave = true; } accountRef.ReferenceId = mWarehouseToUpdate.Id; accountRef.ReferenceTable = EnumReferenceTable.WarehouseUsing.ToString(); accountRef.ReferenceType = EnumReferenceTable.WarehouseUsing.ToString(); accountRef.AccountId = _mAccountRepository.Get(formCollection["UsingAccountId"]); if (isSave) { _mAccountRefRepository.Save(accountRef); } else { _mAccountRefRepository.Update(accountRef); } _mWarehouseRepository.DbContext.CommitChanges(); } catch (Exception e) { _mWarehouseRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }