Exemplo n.º 1
0
        public void Execute()
        {
            TenantDAO     tenantDAO     = new TenantDAO(sqlConnection);
            CostCenterDAO costCenterDAO = new CostCenterDAO(sqlConnection);

            Tenant storedTenant = tenantDAO.GetTenant(tenant.id);

            // Se o tenant já existe no banco bem como sua massa de dados, então só altera alguns dados
            if (storedTenant != null)
            {
                // seta identificador e nome amigável
                tenantDAO.SetTenant(tenant);
                // seta departamento raiz com o nome do tenant
                CostCenter mainCostCenter = costCenterDAO.GetMainCostCenter(tenant.id);
                mainCostCenter.name = tenant.alias;
                costCenterDAO.SetCostCenter(mainCostCenter);
                return;
            }

            // Cria um novo tenant e sua massa de dados inicial
            int?tenantId = tenantDAO.SetTenant(tenant);

            tenant.id = tenantId.Value;

            SetTenantPreference();
            SetTenantAccess();
            SetTenantDefaultSmtp();
            SetTenantRootCC();
        }
Exemplo n.º 2
0
        private void SetTenantRootCC()
        {
            CostCenter rootCC = new CostCenter();

            rootCC.tenantId = tenant.id;
            rootCC.name     = tenant.alias;
            rootCC.parentId = null;

            CostCenterDAO costCenterDAO = new CostCenterDAO(sqlConnection);

            costCenterDAO.SetCostCenter(rootCC);
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            String costCenterName = null;

            foreach (String fieldName in Request.Form)
            {
                if (fieldName.Contains("txtName"))
                {
                    costCenterName = Request.Form[fieldName];
                }
            }
            if (String.IsNullOrEmpty(costCenterName))
            {
                EmbedClientScript.ShowErrorMessage(this, "Os valores informados não estão em um formato válido!");
                return;
            }

            CostCenter costCenter = GetCostCenter();

            costCenter.name = costCenterName;

            try
            {
                CostCenterDAO costCenterDAO = new CostCenterDAO(settingsMasterPage.dataAccess.GetConnection());
                costCenterDAO.SetCostCenter(costCenter);
            }
            catch (Exception genericException)
            {
                if (genericException.Message.Contains("Violation of UNIQUE KEY"))
                {
                    EmbedClientScript.ShowErrorMessage(this, "Este centro de custo já existe!");
                    return;
                }

                EmbedClientScript.ShowErrorMessage(this, genericException.Message);
            }

            EmbedClientScript.CloseWindow(this);
        }