/// <summary>
        /// Approves/Reviews/Disburses an expense.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        /// <param name="review">An ExpenseReview object.</param>
        public void ApproveExpense(Expense expense, ExpenseReview review)
        {
            // Create message contract.
               ExpenseWorkflowService.ApproverRequestMessage requestMessage =
                new ExpenseWorkflowService.ApproverRequestMessage(expense.WorkflowID, expense, review);

            ExpenseWorkflowServiceClient proxy = new ExpenseWorkflowServiceClient();
            try
            {
                // For Manager.
                if (expense.Status == ExpenseStatus.Pending)
                {
                    proxy.ReviewExpense(requestMessage);
                }

                // For Head of Department/HR Manager.
                else if (expense.Status == ExpenseStatus.Reviewed ||
                    expense.Status == ExpenseStatus.Escalated)
                {
                    proxy.ApproveExpense(requestMessage);
                }

                // For Financial Controller.
                else if (expense.Status == ExpenseStatus.Approved)
                {
                    proxy.DisburseExpense(requestMessage);
                }

                proxy.Close();
            }
            catch (FaultException<ProcessExecutionFault> ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
        /// <summary>
        /// Approves an Expense request.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        /// <param name="review">An ExpenseReview object.</param>
        public Expense Approve(Expense expense, ExpenseReview review)
        {
            Console.WriteLine("Approving...");

            expense.Status = ExpenseStatus.Approved;
            expense.IsCompleted = false;

            return UpdateExpenseRecord(expense, review);
        }
        /// <summary>
        /// Cancels an Expense request.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        public Expense Cancel(Expense expense)
        {
            Console.WriteLine("Cancelling... ");

            expense.AssignedTo = string.Empty;
            expense.Status = ExpenseStatus.Cancelled;
            expense.IsCompleted = true;

            return UpdateExpenseRecord(expense);
        }
        /// <summary>
        /// Inserts an expense row.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        public Expense Create(Expense expense)
        {
            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                ctx.Expenses.AddObject(expense);
                ctx.SaveChanges();
            }

            return expense;
        }
        /// <summary>
        /// Cancel a pending expense.
        /// </summary>
        /// <param name="expense">An Expense instance.</param>
        /// <returns>A boolean value indicating the request has been made.</returns>
        public bool CancelExpense(Expense expense)
        {
            bool result = false;

            // Cancel the expense.
            try
            {
                ExpenseWorkflowService.SubmitterRequestMessage requestMessage =
                    new ExpenseWorkflowService.SubmitterRequestMessage(expense.WorkflowID, expense);

                ExpenseWorkflowServiceClient proxy = new ExpenseWorkflowServiceClient();

                proxy.CancelExpense(requestMessage);
            }
            catch (FaultException<ProcessExecutionFault> ex)
            {
                throw new ApplicationException(ex.Message);
            }

            result = true;

            return result;
        }
        /// <summary>
        /// Creates a new Expense record in the database.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        private Expense CreateExpense(Expense expense)
        {
            // Business logic.
            expense.IsCompleted = false;
            expense.DateSubmitted = DateTime.Now;
            expense.DateModified = DateTime.Now;

            Console.WriteLine(expense.ToString());

            // Persist data.
            ExpenseDataAccess dac = new ExpenseDataAccess();
            try
            {
                return dac.Create(expense);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
        }
        /// <summary>
        /// Disburses an Approved Expense request.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        /// <param name="review">An ExpenseReview object.</param>
        public Expense Disburse(Expense expense, ExpenseReview review)
        {
            Console.WriteLine("Disbursing...");

            expense.Status = ExpenseStatus.Disbursed;
            expense.AssignedTo = string.Empty;
            expense.IsCompleted = true;

               return UpdateExpenseRecord(expense, review);
        }
        /// <summary>
        /// Submit an expense.
        /// </summary>
        /// <param name="expense">An Expense instance.</param>
        public void SubmitExpense(Expense expense)
        {
            // Submit the expense.
            try
            {
                expense.WorkflowID = Guid.NewGuid();

                ExpenseWorkflowService.SubmitterRequestMessage requestMessage =
                    new ExpenseWorkflowService.SubmitterRequestMessage(expense.WorkflowID, expense);

                ExpenseWorkflowServiceClient proxy = new ExpenseWorkflowServiceClient();
                proxy.SubmitExpense(requestMessage);
                proxy.Close();
            }
            catch (FaultException<ProcessExecutionFault> ex)
            {
                throw new ApplicationException(ex.Message);
            }
        }
Exemplo n.º 9
0
        private void SubmitExpense()
        {
            Expense expense = new Expense();
            expense.Employee = Environment.UserName;
            expense.ExpenseDate = Convert.ToDateTime(expenseDate.Text).Date;
            expense.Amount = Convert.ToDouble(expenseAmount.Text);
            expense.Category = (ExpenseCategory)category.SelectedIndex;
            expense.Description = description.Text;

            try
            {
                _upc.SubmitExpense(expense);

                statusLabel.Text = "Expense submitted successfully.";
                expenseAmount.Text = string.Empty;

                LoadExpenses();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
Exemplo n.º 10
0
        private void CancelExpense()
        {
            int i = 0;

            try
            {
                foreach (GridViewRow row in expenseGrid.Rows)
                {
                    if (((CheckBox)row.FindControl("selectBox")).Checked)
                    {
                        // NOTE: I don't really like this part because it is reconstructing
                        //       the entity from scratch. Any ideas or advice would be appreciated.
                        Expense expense = new Expense();

                        DataKey key = expenseGrid.DataKeys[row.RowIndex];
                        expense.ExpenseID = (long)key.Values[0];
                        expense.WorkflowID = (Guid)key.Values[1];

                        expense.Employee = Environment.UserName;
                        expense.Category = (ExpenseCategory)
                            Enum.Parse(typeof(ExpenseCategory), row.Cells[2].Text);
                        expense.Description = row.Cells[3].Text;
                        expense.Amount = Convert.ToDouble(row.Cells[4].Text);
                        expense.ExpenseDate = Convert.ToDateTime(row.Cells[5].Text);
                        expense.Status = (ExpenseStatus)
                            Enum.Parse(typeof(ExpenseStatus), row.Cells[6].Text);
                        expense.DateSubmitted = Convert.ToDateTime(row.Cells[7].Text);
                        expense.DateModified = Convert.ToDateTime(row.Cells[8].Text);
                        expense.AssignedTo = row.Cells[9].Text;
                        // End of Expense entity reconstruction.

                        if (_upc.CancelExpense(expense))
                            i++;
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

            if (i > 0)
            {
                infoLabel.Text = (i <= 1 ? "Expense" : "Expenses") + " cancelled.";
            }
            else
            {
                infoLabel.Text = "No pending expenses available for cancellation.";
            }

            LoadExpenses();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Updates the Expense information into the database.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        private Expense UpdateExpense(Expense expense)
        {
            // Business logic.
            expense.DateModified = DateTime.Now;

            Console.WriteLine(expense.ToString());

            // Persist data.
            ExpenseDataAccess dac = new ExpenseDataAccess();
            try
            {
                dac.Update(expense);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }

            return expense;
        }
Exemplo n.º 12
0
        private Expense UpdateExpenseRecord(Expense expense, ExpenseReview review)
        {
            using (TransactionScope ts =
                new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    expense = UpdateExpense(expense);
                    CreateExpenseReview(review);
                    LogStatus(expense);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
            }

            return expense;
        }
Exemplo n.º 13
0
        private void SubmitExpense()
        {
            try
            {
                // Validate amount.
                Double amountValue;
                if (!Double.TryParse(amount.Text, out amountValue))
                {
                    MessageBox.Show(this, "Amount must be numeric", "Invalid Data",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    amount.Focus();
                    return;
                }

                // Create a new Expense entity.
                Expense expense = new Expense();
                expense.ExpenseDate = expenseDate.Value.Date;
                expense.Employee = Environment.UserName;
                expense.Amount = amountValue;
                expense.Category = (ExpenseCategory)category.SelectedIndex;
                expense.Description = description.Text;
                expense.DateModified = DateTime.Now;

                _upc.SubmitExpense(expense);

                statusLabel.Text = "Expense submitted.";

                amount.Text = (new Random()).Next(250, 5000).ToString();
                description.Text = "Yet another expense claim.";
                amount.Focus();
            }
            catch (FaultException faultEx)
            {
                MessageBox.Show(faultEx.Message, "Error Submitting Expense", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Submitting Expense", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
            }

            LoadExpenses();
        }
Exemplo n.º 14
0
        private void SubmitExpense()
        {
            try
            {
                // Validate amount.
                Double amountValue;
                if (!Double.TryParse(amount.Text, out amountValue))
                {
                    MessageBox.Show("Amount must be numeric", "Invalid Data",
                        MessageBoxButton.OK, MessageBoxImage.Error);
                    amount.Focus();
                    return;
                }

                // Create a new Expense entity.
                Expense expense = new Expense();
                expense.ExpenseDate = expenseDate.SelectedDate.GetValueOrDefault();
                expense.Employee = Environment.UserName;
                expense.Amount = amountValue;
                expense.Category = (ExpenseCategory)category.SelectedIndex;
                expense.Description = description.Text;
                expense.DateModified = DateTime.Now;

                _upc.SubmitExpense(expense);

                statusLabel.Content = "Expense submitted.";

                amount.Text = string.Empty;
                description.Text = string.Empty;
                amount.Focus();
            }
            catch (FaultException faultEx)
            {
                MessageBox.Show(faultEx.Message, "Error Submitting Expense", MessageBoxButton.OK,
                     MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Submitting Expense", MessageBoxButton.OK,
                     MessageBoxImage.Error);
            }

            LoadExpenses();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Submit an Expense.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        public Expense Submit(Expense expense)
        {
            Console.WriteLine("Submitting... ");

            expense.Status = ExpenseStatus.Pending;

            using (TransactionScope ts =
                new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    expense = CreateExpense(expense);
                    LogStatus(expense);
                    ts.Complete();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    throw ex;
                }
            }

            Console.WriteLine("New ExpenseID = " + expense.ExpenseID.ToString());

            return expense;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Escalates an unattended Expense request.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        public Expense Escalate(Expense expense)
        {
            Console.WriteLine("Escalating... ");

            expense.Status = ExpenseStatus.Escalated;
            return UpdateExpenseRecord(expense);
        }
Exemplo n.º 17
0
        private void ApproveExpense(bool approved)
        {
            int i = 0;

            try
            {
                foreach (GridViewRow row in expenseGrid.Rows)
                {
                    if (((CheckBox)row.FindControl("selectBox")).Checked)
                    {
                        // NOTE: I don't really like this part because it is reconstructing
                        //       the entity. Any ideas or advice would be appreciated.
                        Expense expense = new Expense();

                        DataKey key = expenseGrid.DataKeys[row.RowIndex];
                        expense.ExpenseID = (long)key.Values[0];
                        expense.WorkflowID = (Guid)key.Values[1];

                        expense.Employee = row.Cells[2].Text;
                        expense.Category = (ExpenseCategory)
                            Enum.Parse(typeof(ExpenseCategory), row.Cells[3].Text);
                        expense.Description = row.Cells[4].Text;
                        expense.Amount = Convert.ToDouble(row.Cells[5].Text);
                        expense.ExpenseDate = Convert.ToDateTime(row.Cells[6].Text);
                        expense.Status = (ExpenseStatus)
                            Enum.Parse(typeof(ExpenseStatus), row.Cells[7].Text);
                        expense.DateSubmitted = Convert.ToDateTime(row.Cells[8].Text);
                        expense.DateModified = Convert.ToDateTime(row.Cells[9].Text);
                        // End of Expense entity reconstruction.

                        ExpenseReview review = new ExpenseReview();
                        review.ExpenseID = expense.ExpenseID;
                        review.Reviewer = roleBox.SelectedValue;
                        review.IsApproved = approved;
                        review.Remarks = remarksBox.Text;

                        _upc.ApproveExpense(expense, review);

                    }
                    i++;
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

            LoadExpenses();

            string term = string.Compare(roleBox.Text, "Financial Controller", true) == 0 ?
                    "disbursed. " : "approved. ";

            if (i > 0)
            {
                statusLabel.Text = (i > 1 ? "Expenses " : "Expense ") +
                    (approved ? term : " rejected.") +
                    (expenseGrid.Rows.Count > 0 ? string.Empty :
                        "There are no more pending expenses available for review or approval.");
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Logs the status of the Expense.
        /// </summary>
        /// <param name="expense">An Expense object.</param>
        private void LogStatus(Expense expense)
        {
            ExpenseLog log = new ExpenseLog();
            log.ExpenseID = expense.ExpenseID;
            log.Status = expense.Status;
            log.DateCreated = DateTime.Now;

            // Persist data.
            ExpenseLogDataAccess dac = new ExpenseLogDataAccess();
            try
            {
                dac.Create(log);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Updates an Expense row.
        /// </summary>
        /// <param name="expense">A Expense object.</param>
        public void Update(Expense expense)
        {
            EntityKey key = null;
            object original = null;

            using (ExpenseDataContext ctx = new ExpenseDataContext())
            {
                key = ctx.CreateEntityKey(ENTITY_SET_NAME, expense);
                if (ctx.TryGetObjectByKey(key, out original))
                {
                    ctx.ApplyCurrentValues(key.EntitySetName, expense);
                }
                ctx.SaveChanges();
            }
        }