Exemplo n.º 1
0
    protected void ButtonAttest_Click(object sender, EventArgs e)
    {
        List <string> identityStrings = new List <string>();

        foreach (string indexString in this.GridAttestables.SelectedIndexes)
        {
            int    index = Int32.Parse(indexString);
            string itemIdentityString = (string)this.GridAttestables.MasterTableView.DataKeyValues[index]["Identity"];
            int    itemIdentity       = Int32.Parse(itemIdentityString.Substring(1));


            // Mark items as attested

            switch (itemIdentityString[0])
            {
            case 'E':
                ExpenseClaim claim = ExpenseClaim.FromIdentity(itemIdentity);

                if (attestationRights.ContainsKey(claim.BudgetId))
                {
                    claim.Attest(_currentUser);
                    Activizr.Logic.Support.PWEvents.CreateEvent(
                        EventSource.PirateWeb, EventType.ExpenseAttested, _currentUser.Identity,
                        claim.OrganizationId, 0, claim.ClaimingPersonId, claim.Identity, string.Empty);
                }
                break;

            case 'I':
                InboundInvoice invoice = InboundInvoice.FromIdentity(itemIdentity);

                if (attestationRights.ContainsKey(invoice.BudgetId))
                {
                    invoice.Attest(_currentUser);
                    Activizr.Logic.Support.PWEvents.CreateEvent(
                        EventSource.PirateWeb, EventType.InboundInvoiceAttested, _currentUser.Identity,
                        invoice.OrganizationId, 0, 0, invoice.Identity, string.Empty);
                }
                break;

            case 'S':
                Salary salary = Salary.FromIdentity(itemIdentity);

                // Mark as attested

                bool mayAttest = false;

                if (attestationRights.ContainsKey(salary.PayrollItem.BudgetId) && salary.PayrollItem.PersonId != _currentUser.Identity)
                {
                    mayAttest = true;
                }

                if (salary.PayrollItem.ReportsToPersonId == _currentUser.Identity)
                {
                    mayAttest = true;
                }

                if (mayAttest)
                {
                    salary.Attest(_currentUser);
                    Activizr.Logic.Support.PWEvents.CreateEvent(
                        EventSource.PirateWeb, EventType.SalaryAttested, _currentUser.Identity,
                        salary.PayrollItem.OrganizationId, 0, 0, salary.Identity, string.Empty);
                }
                break;

            case 'P':
                Parley parley = Parley.FromIdentity(itemIdentity);

                if (attestationRights.ContainsKey(parley.BudgetId))
                {
                    parley.Attest(_currentUser);
                }
                break;
            }
        }

        this.GridAttestables.Rebind();
    }