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"));
        }
Exemple #2
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"));
        }
        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"));
        }