Пример #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"));
        }
        public ActionResult Update(MWarehouse viewModel, FormCollection formCollection)
        {
            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();

            mWarehouseToUpdate.AddressId.AddressLine1 = formCollection["AddressLine1"];
            mWarehouseToUpdate.AddressId.AddressLine1 = formCollection["AddressLine1"];
            mWarehouseToUpdate.AddressId.AddressLine2 = formCollection["AddressLine2"];
            mWarehouseToUpdate.AddressId.AddressLine3 = formCollection["AddressLine3"];
            mWarehouseToUpdate.AddressId.AddressPhone = formCollection["AddressPhone"];
            mWarehouseToUpdate.AddressId.AddressCity  = formCollection["AddressCity"];

            _mWarehouseRepository.Update(mWarehouseToUpdate);

            bool        isSave     = false;
            MAccountRef accountRef = GetAccountRef(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);
            }


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

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

            return(Content("success"));
        }
Пример #3
0
        public ActionResult Update(MSupplier viewModel, FormCollection formCollection)
        {
            UpdateNumericData(viewModel, formCollection);
            MSupplier mSupplierToUpdate = _mSupplierRepository.Get(viewModel.Id);

            TransferFormValuesTo(mSupplierToUpdate, viewModel);
            mSupplierToUpdate.ModifiedDate = DateTime.Now;
            mSupplierToUpdate.ModifiedBy   = User.Identity.Name;
            mSupplierToUpdate.DataStatus   = EnumDataStatus.Updated.ToString();

            RefAddress address = mSupplierToUpdate.AddressId;

            TransferFormValuesTo(address, formCollection);
            address.ModifiedDate = DateTime.Now;
            address.ModifiedBy   = User.Identity.Name;
            address.DataStatus   = EnumDataStatus.Updated.ToString();

            _mSupplierRepository.Update(mSupplierToUpdate);


            bool        isSave     = false;
            MAccountRef accountRef = GetAccountRef(mSupplierToUpdate.Id);

            if (accountRef == null)
            {
                accountRef = new MAccountRef();
                accountRef.SetAssignedIdTo(Guid.NewGuid().ToString());
                isSave = true;
            }
            accountRef.ReferenceId    = mSupplierToUpdate.Id;
            accountRef.ReferenceTable = EnumReferenceTable.Supplier.ToString();
            accountRef.ReferenceType  = EnumReferenceTable.Supplier.ToString();
            accountRef.AccountId      = _mAccountRepository.Get(formCollection["AccountId"]);
            if (isSave)
            {
                _mAccountRefRepository.Save(accountRef);
            }
            else
            {
                _mAccountRefRepository.Update(accountRef);
            }
            try
            {
                _mSupplierRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mSupplierRepository.DbContext.RollbackTransaction();

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

            return(Content("success"));
        }
Пример #4
0
        public ActionResult Update(MJobType viewModel, FormCollection formCollection)
        {
            try
            {
                _mJobTypeRepository.DbContext.BeginTransaction();

                MJobType mJobTypeToUpdate = _mJobTypeRepository.Get(viewModel.Id);
                TransferFormValuesTo(mJobTypeToUpdate, viewModel);
                mJobTypeToUpdate.ModifiedDate = DateTime.Now;
                mJobTypeToUpdate.ModifiedBy   = User.Identity.Name;
                mJobTypeToUpdate.DataStatus   = EnumDataStatus.Updated.ToString();

                _mJobTypeRepository.Update(mJobTypeToUpdate);

                bool        isSave     = false;
                MAccountRef accountRef = GetAccountRef(mJobTypeToUpdate.Id);
                if (accountRef == null)
                {
                    accountRef = new MAccountRef();
                    accountRef.SetAssignedIdTo(Guid.NewGuid().ToString());
                    accountRef.CreatedDate = DateTime.Now;
                    accountRef.CreatedBy   = User.Identity.Name;
                    accountRef.DataStatus  = EnumDataStatus.New.ToString();
                    isSave = true;
                }
                else
                {
                    accountRef.ModifiedDate = DateTime.Now;
                    accountRef.ModifiedBy   = User.Identity.Name;
                    accountRef.DataStatus   = EnumDataStatus.Updated.ToString();
                }
                accountRef.ReferenceId    = mJobTypeToUpdate.Id;
                accountRef.ReferenceTable = EnumReferenceTable.JobType.ToString();
                accountRef.ReferenceType  = EnumReferenceTable.JobType.ToString();
                accountRef.AccountId      = _mAccountRepository.Get(formCollection["AccountId"]);
                if (isSave)
                {
                    _mAccountRefRepository.Save(accountRef);
                }
                else
                {
                    _mAccountRefRepository.Update(accountRef);
                }
                _mJobTypeRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mJobTypeRepository.DbContext.RollbackTransaction();

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

            return(Content("success"));
        }
Пример #5
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"));
        }
Пример #6
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"));
        }