Ejemplo n.º 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"));
        }
Ejemplo n.º 2
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.SetAssignedIdTo(viewModel.Id);
            mWarehouseToInsert.CreatedDate = DateTime.Now;
            mWarehouseToInsert.CreatedBy   = User.Identity.Name;
            mWarehouseToInsert.DataStatus  = EnumDataStatus.New.ToString();
            mWarehouseToInsert.AddressId   = address;
            _mWarehouseRepository.Save(mWarehouseToInsert);

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

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

            return(Content("success"));
        }