//dropdowns for other tabs
        private void LoadAdditionalDropdownData()
        {
            var siteCoID = siteusercompanyid;

            ViewBag.CoStages  = new SelectList(db.GetCoStagesBySiteCoID(siteCoID).ToList(), nameof(GetCoStagesBySiteCoID_Result.StageMasterID), nameof(GetCoStagesBySiteCoID_Result.Stage));
            ViewBag.CostCodes = new SelectList(db.GetCoCostCodesBySiteCoID(siteCoID).ToList(), nameof(GetCoCostCodesBySiteCoID_Result.CostCodeID), nameof(GetCoCostCodesBySiteCoID_Result.CostCode));
            ViewBag.PayTypes  = new SelectList(db.GetPayTypesBySiteCoID(siteCoID).ToList(), nameof(GetPayTypesBySiteCoID_Result.ViewID), nameof(GetPayTypesBySiteCoID_Result.Name));
            ViewBag.Taxes     = new SelectList(db.GetCoTaxesBySiteCoID(siteCoID).ToList(), nameof(GetCoTaxesBySiteCoID_Result.ViewID), nameof(GetCoTaxesBySiteCoID_Result.Tax));
            ViewBag.Areas     = new SelectList(db.GetCoAreasBySiteCoID(siteCoID).ToList(), nameof(GetCoAreasBySiteCoID_Result.ViewID), nameof(GetCoAreasBySiteCoID_Result.Area));
            ViewBag.Divisions = new SelectList(db.GetCoDivisionsBySiteCoID(siteCoID).ToList(), nameof(GetCoDivisionsBySiteCoID_Result.ViewID), nameof(GetCoDivisionsBySiteCoID_Result.Divisions));
        }
        public ActionResult Edit(int id)//stage master id
        {
            var stage = db.GetStageMasterEditInfoByID(id).FirstOrDefault();

            if (stage == null)
            {
                return(HttpNotFound());
            }

            var subLabors = db.GetSubLaborInfoByMasterStageID(id).ToList();

            var model = new StageModels.StageMasterEdit()
            {
                CostCodeId    = stage.CostCodeID,
                MiscEquip     = stage.MiscEqp,
                MiscParts     = stage.MiscParts,
                Order         = stage.Order,
                StageMasterID = stage.StageMasterID,
                StageName     = stage.Stage,
            };

            foreach (var sub in subLabors)
            {
                model.StageSubDetails.Add(new StageModels.StageDetails()
                {
                    StageMasterID = id,
                    SubStageID    = sub.SubID,
                    SubName       = sub.SubStage,
                    CostPerHour   = sub.Cost,
                    PricePerHour  = sub.Price,
                    Percent       = sub.Factor,
                    SellPerHour   = sub.Sell
                });
            }

            ViewBag.CostCodes = new SelectList(db.GetCoCostCodesBySiteCoID(siteusercompanyid).ToList(), nameof(GetCoCostCodesBySiteCoID_Result.CostCodeID), nameof(GetCoCostCodesBySiteCoID_Result.CostCode));

            return(View(model));
        }
        public ActionResult Details(int?id)
        {
            var data = db.GetItemInfoByMasterItemID(id).FirstOrDefault();

            if (data.Vendor != null)
            {
                ViewBag.Vendors = new SelectList(db.GetVendorsBySiteCoID(base.siteusercompanyid).ToList(), nameof(GetVendorsBySiteCoID_Result.ViewID), nameof(GetVendorsBySiteCoID_Result.Vendor), data.Vendor);
            }
            else
            {
                ViewBag.Vendors = new SelectList(db.GetVendorsBySiteCoID(base.siteusercompanyid).ToList(), nameof(GetVendorsBySiteCoID_Result.ViewID), nameof(GetVendorsBySiteCoID_Result.Vendor));
            }
            ViewBag.SalesUom  = new SelectList(db.GetSiteDataUom().ToList(), nameof(GetSiteDataUom_Result.ViewID), nameof(GetSiteDataUom_Result.Uom), data.SaleUom);
            ViewBag.OrderUom  = new SelectList(db.GetSiteDataUom().ToList(), nameof(GetSiteDataUom_Result.ViewID), nameof(GetSiteDataUom_Result.Uom), data.OrderUom);
            ViewBag.CostCodes = new SelectList(db.GetCoCostCodesBySiteCoID(siteusercompanyid).ToList(), nameof(GetCoCostCodesBySiteCoID_Result.CostCodeID), nameof(GetCoCostCodesBySiteCoID_Result.CostCode));
            var projectID = db.ProjectItems.Where(p => p.MasterItemID == id).Select(p => p.ProjectID).FirstOrDefault();

            ViewBag.CoStages = new SelectList(db.GetMasterStagesBySiteID(siteusercompanyid).ToList(), nameof(GetMasterStagesBySiteID_Result.ViewID), nameof(GetMasterStagesBySiteID_Result.Stage));
            var stage = db.GetStageMasterEditInfoByID(data.StageID).FirstOrDefault();

            if (stage != null)
            {
                var subLabors = db.GetSubLaborInfoByMasterItemID(id).ToList();
                var Labors    = new StageModels.StageMasterEdit();
                if (subLabors != null)
                {
                    foreach (var sub in subLabors)
                    {
                        Labors.StageSubDetails.Add(new StageModels.StageDetails()
                        {
                            StageMasterID = stage.StageMasterID,
                            SubStageID    = sub.SubID,
                            SubName       = sub.SubStage,
                            CostPerHour   = sub.Cost,
                            PricePerHour  = sub.Price,
                            Percent       = sub.Factor,
                            SellPerHour   = sub.Sell
                        });
                    }
                }
                ViewBag.Labors = Labors;
            }
            if (data == null)
            {
                return(HttpNotFound());
            }
            else
            {
                ViewBag.AcctItemID = data.AcctItemID;
            }
            int siteCoID = base.siteusercompanyid;

            qbModels = new QBModels();
            qbModels.SyncObjectsModel    = new QBSyncdto();
            qbModels.OAuthorizationModel = new QBAuthorizationdto();
            qbModels.IsReadySync         = false;
            var oAuthModel = new QBOAuthService(qbModels.OAuthorizationModel).IsTokenAvailable(this, siteusercompanyid);

            if (oAuthModel.IsConnected)
            {
                qbModels.IsReadySync         = true;
                qbModels.OAuthorizationModel = oAuthModel;
                qbModels.IsConnected         = oAuthModel.IsConnected;
                var syncService = new QBSyncService(oAuthModel);
                qbModels.SyncObjectsModel.OauthToken = oAuthModel;
                qbModels.SyncObjectsModel.CompanyId  = oAuthModel.Realmid;
                Random random = new Random();
                qbModels.SyncObjectsModel = Save(this, qbModels.SyncObjectsModel);
                SyncObjectsModelId        = qbModels.SyncObjectsModel.Id;
            }

            return(View(data));
        }