private void TransferFormValuesTo(MUnitType unitType, MUnitType viewModel) { unitType.UnitTypeName = viewModel.UnitTypeName; unitType.UnitTypeStatus = viewModel.UnitTypeStatus; unitType.UnitTypeDesc = viewModel.UnitTypeDesc; unitType.UnitTypeTotal = viewModel.UnitTypeTotal; }
public ActionResult Insert(MUnitType viewModel, FormCollection formCollection) { try { UpdateNumericData(viewModel, formCollection); MUnitType unitType = new MUnitType(); unitType.SetAssignedIdTo(Guid.NewGuid().ToString()); TransferFormValuesTo(unitType, viewModel); unitType.CostCenterId = _mCostCenterRepository.Get(formCollection["CostCenterId"]); unitType.CreatedDate = DateTime.Now; unitType.CreatedBy = User.Identity.Name; _mUnitTypeRepository.Save(unitType); //GenerateEachUnit(unitType); _mUnitTypeRepository.DbContext.CommitChanges(); } catch (Exception e) { _mUnitTypeRepository.DbContext.RollbackTransaction(); //throw e.GetBaseException(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
public static TransactionFormViewModel Create(EnumTransactionStatus enumTransactionStatus, ITTransRepository transRepository, IMWarehouseRepository mWarehouseRepository, IMSupplierRepository mSupplierRepository, IMUnitTypeRepository mUnitTypeRepository, IMJobTypeRepository mJobTypeRepository) { TransactionFormViewModel viewModel = new TransactionFormViewModel(); TTrans trans = SetNewTrans(enumTransactionStatus); viewModel.Trans = trans; Helper.CommonHelper.SetViewModelByStatus(viewModel, enumTransactionStatus); viewModel.TransFactur = trans.TransFactur; viewModel.TransDate = trans.TransDate; viewModel.TransId = trans.Id; viewModel.TransStatus = trans.TransStatus; viewModel.WarehouseId = trans.WarehouseId; viewModel.WarehouseIdTo = trans.WarehouseIdTo; viewModel.UnitTypeId = trans.UnitTypeId; viewModel.JobTypeId = trans.JobTypeId; viewModel.TransDesc = trans.TransDesc; IList <MWarehouse> list = mWarehouseRepository.GetAll(); MWarehouse mWarehouse = new MWarehouse(); mWarehouse.WarehouseName = "-Pilih Gudang-"; list.Insert(0, mWarehouse); viewModel.WarehouseList = new SelectList(list, "Id", "WarehouseName"); viewModel.WarehouseToList = new SelectList(list, "Id", "WarehouseName"); IList <MSupplier> listSupplier = mSupplierRepository.GetAll(); MSupplier mSupplier = new MSupplier(); mSupplier.SupplierName = "-Pilih Supplier-"; listSupplier.Insert(0, mSupplier); viewModel.SupplierList = new SelectList(listSupplier, "Id", "SupplierName"); IList <MUnitType> listUnitType = mUnitTypeRepository.GetAll(); MUnitType mUnitType = new MUnitType(); mUnitType.UnitTypeName = "-Pilih Unit-"; listUnitType.Insert(0, mUnitType); viewModel.UnitTypeList = new SelectList(listUnitType, "Id", "UnitTypeName"); IList <MJobType> listJobType = mJobTypeRepository.GetAll(); MJobType mJobType = new MJobType(); mJobType.JobTypeName = "-Pilih Jenis Pekerjaan-"; listJobType.Insert(0, mJobType); viewModel.JobTypeList = new SelectList(listJobType, "Id", "JobTypeName"); //fill payment method var values = from EnumPaymentMethod e in Enum.GetValues(typeof(EnumPaymentMethod)) select new { ID = e, Name = e.ToString() }; viewModel.PaymentMethodList = new SelectList(values, "Id", "Name"); //viewModel.ViewWarehouseTo = false; //viewModel.ViewSupplier = false; //viewModel.ViewDate = false; //viewModel.ViewFactur = false; return(viewModel); }
private void UpdateNumericData(MUnitType viewModel, FormCollection formCollection) { if (!string.IsNullOrEmpty(formCollection["UnitTypeTotal"])) { string UnitTypeTotal = formCollection["UnitTypeTotal"].Replace(",", ""); int? total = Convert.ToInt32(UnitTypeTotal); viewModel.UnitTypeTotal = total; } }
private void GenerateEachUnit(MUnitType unitType) { if (unitType.UnitTypeTotal.HasValue) { TUnit unit; for (int i = 0; i < unitType.UnitTypeTotal.Value; i++) { unit = new TUnit(); unit.CostCenterId = unitType.CostCenterId; unit.UnitTypeId = unitType; unit.UnitStatus = EnumUnitStatus.New.ToString(); unit.UnitNo = (i + 1).ToString(); unit.SetAssignedIdTo(Guid.NewGuid().ToString()); unit.CreatedDate = DateTime.Now; unit.CreatedBy = User.Identity.Name; unit.DataStatus = EnumDataStatus.New.ToString(); _tUnitRepository.Save(unit); } } }
public ActionResult Delete(MUnitType viewModel, FormCollection formCollection) { MUnitType mUnitTypeToDelete = _mUnitTypeRepository.Get(viewModel.Id); if (mUnitTypeToDelete != null) { _mUnitTypeRepository.Delete(mUnitTypeToDelete); } try { _mUnitTypeRepository.DbContext.CommitChanges(); } catch (Exception e) { _mUnitTypeRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }
public ActionResult Update(MUnitType viewModel, FormCollection formCollection) { MUnitType mUnitTypeToUpdate = _mUnitTypeRepository.Get(viewModel.Id); TransferFormValuesTo(mUnitTypeToUpdate, viewModel); mUnitTypeToUpdate.CostCenterId = _mCostCenterRepository.Get(formCollection["CostCenterId"]); mUnitTypeToUpdate.ModifiedDate = DateTime.Now; mUnitTypeToUpdate.ModifiedBy = User.Identity.Name; mUnitTypeToUpdate.DataStatus = EnumDataStatus.Updated.ToString(); _mUnitTypeRepository.Update(mUnitTypeToUpdate); try { _mUnitTypeRepository.DbContext.CommitChanges(); } catch (Exception e) { _mUnitTypeRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("success")); }