예제 #1
0
        public ActionResult Insert(MWarehouse viewModel, FormCollection formCollection)
        {
            RefAddress address = new RefAddress();

            address.AddressLine1 = formCollection["AddressLine1"];
            address.AddressLine2 = formCollection["AddressLine2"];
            address.AddressLine3 = formCollection["AddressLine3"];
            address.AddressPhone = formCollection["AddressPhone"];
            address.AddressCity  = formCollection["AddressCity"];
            address.SetAssignedIdTo(Guid.NewGuid().ToString());
            _refAddressRepository.Save(address);

            MWarehouse mWarehouseToInsert = new MWarehouse();

            TransferFormValuesTo(mWarehouseToInsert, viewModel);
            mWarehouseToInsert.EmployeeId   = _mEmployeeRepository.Get(formCollection["EmployeeId"]);
            mWarehouseToInsert.CostCenterId = _mCostCenterRepository.Get(formCollection["CostCenterId"]);
            mWarehouseToInsert.SetAssignedIdTo(viewModel.Id);
            mWarehouseToInsert.CreatedDate = DateTime.Now;
            mWarehouseToInsert.CreatedBy   = User.Identity.Name;
            mWarehouseToInsert.DataStatus  = EnumDataStatus.New.ToString();
            mWarehouseToInsert.AddressId   = address;
            _mWarehouseRepository.Save(mWarehouseToInsert);

            //save account persediaan barang
            MAccountRef accountRef = new MAccountRef();

            accountRef.SetAssignedIdTo(Guid.NewGuid().ToString());
            accountRef.ReferenceId    = mWarehouseToInsert.Id;
            accountRef.ReferenceTable = EnumReferenceTable.Warehouse.ToString();
            accountRef.ReferenceType  = EnumReferenceTable.Warehouse.ToString();
            accountRef.AccountId      = _mAccountRepository.Get(formCollection["AccountId"]);
            _mAccountRefRepository.Save(accountRef);

            //save account pemakaian barang
            accountRef = new MAccountRef();
            accountRef.SetAssignedIdTo(Guid.NewGuid().ToString());
            accountRef.ReferenceId    = mWarehouseToInsert.Id;
            accountRef.ReferenceTable = EnumReferenceTable.WarehouseUsing.ToString();
            accountRef.ReferenceType  = EnumReferenceTable.WarehouseUsing.ToString();
            accountRef.AccountId      = _mAccountRepository.Get(formCollection["UsingAccountId"]);
            _mAccountRefRepository.Save(accountRef);

            try
            {
                _mWarehouseRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mWarehouseRepository.DbContext.RollbackTransaction();

                //throw e.GetBaseException();
                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
예제 #2
0
        public ActionResult Insert(MSupplier viewModel, FormCollection formCollection)
        {
            try
            {
                _mSupplierRepository.DbContext.BeginTransaction();

                UpdateNumericData(viewModel, 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);

                MSupplier mSupplierToInsert = new MSupplier();
                TransferFormValuesTo(mSupplierToInsert, viewModel);
                mSupplierToInsert.SetAssignedIdTo(viewModel.Id);
                mSupplierToInsert.CreatedDate = DateTime.Now;
                mSupplierToInsert.CreatedBy   = User.Identity.Name;
                mSupplierToInsert.DataStatus  = EnumDataStatus.New.ToString();

                mSupplierToInsert.AddressId = address;

                _mSupplierRepository.Save(mSupplierToInsert);

                MAccountRef accountRef = new MAccountRef();
                accountRef.SetAssignedIdTo(Guid.NewGuid().ToString());
                accountRef.ReferenceId    = mSupplierToInsert.Id;
                accountRef.ReferenceTable = EnumReferenceTable.Supplier.ToString();
                accountRef.ReferenceType  = EnumReferenceTable.Supplier.ToString();
                accountRef.AccountId      = _mAccountRepository.Get(formCollection["AccountId"]);
                accountRef.CreatedDate    = DateTime.Now;
                accountRef.CreatedBy      = User.Identity.Name;
                accountRef.DataStatus     = EnumDataStatus.New.ToString();
                _mAccountRefRepository.Save(accountRef);

                _mSupplierRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mSupplierRepository.DbContext.RollbackTransaction();

                //throw e.GetBaseException();
                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
예제 #3
0
        public ActionResult Insert(MJobType viewModel, FormCollection formCollection)
        {
            try
            {
                _mJobTypeRepository.DbContext.BeginTransaction();

                MJobType mJobTypeToInsert = new MJobType();
                TransferFormValuesTo(mJobTypeToInsert, viewModel);
                mJobTypeToInsert.SetAssignedIdTo(viewModel.Id);
                mJobTypeToInsert.CreatedDate = DateTime.Now;
                mJobTypeToInsert.CreatedBy   = User.Identity.Name;
                mJobTypeToInsert.DataStatus  = EnumDataStatus.New.ToString();

                _mJobTypeRepository.Save(mJobTypeToInsert);

                MAccountRef accountRef = new MAccountRef();
                accountRef.SetAssignedIdTo(Guid.NewGuid().ToString());
                accountRef.ReferenceId    = mJobTypeToInsert.Id;
                accountRef.ReferenceTable = EnumReferenceTable.JobType.ToString();
                accountRef.ReferenceType  = EnumReferenceTable.JobType.ToString();
                accountRef.AccountId      = _mAccountRepository.Get(formCollection["AccountId"]);
                accountRef.CreatedDate    = DateTime.Now;
                accountRef.CreatedBy      = User.Identity.Name;
                accountRef.DataStatus     = EnumDataStatus.New.ToString();
                _mAccountRefRepository.Save(accountRef);
                _mJobTypeRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mJobTypeRepository.DbContext.RollbackTransaction();

                //throw e.GetBaseException();
                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }