/// <summary>
 /// Gets all requests.
 /// </summary>
 /// <returns>All requests.</returns>
 /// <remarks>The user must be in the View All Requests role in order to perform this action.</remarks>
 public TravelAndTrainingRequestRepository.RequestViewDataTable GetAllRequests()
 {
     RequestOfficer officer = new RequestOfficer(this.user);
     if (officer.CanViewAllRequests())
         return provider.GetAllRequests();
     else
         throw new System.Security.SecurityException("User is not authorized to view all requests.");
 }
 /// <summary>
 /// Saves this request.
 /// </summary>
 public void Save()
 {
     RequestOfficer officer = new RequestOfficer(this.applicationContext);
     if (officer.CanSave())
     {
         if (this.CanBeSaved)
             ttrProvider.Save(this);
         else
             throw new System.InvalidOperationException(Resources.SaveNotAllowedException);
     }
     else
         throw new System.Security.SecurityException(Resources.SaveNotAuthorizedException);
 }
 /// <summary>
 /// Routes the request to the specified recipient. A request can be routed if:
 /// <list type="bullet">
 /// <item>The status is New.</item>
 /// <item>The status is pending approval and the recipient is a final approver.</item>
 /// <item>The proper rights are granted to the logged user.</item>
 /// </list>
 /// </summary>
 /// <param name="recipient">The recipient of the request.</param>
 public void RouteTo(System.Net.Mail.MailAddress recipient)
 {
     RequestOfficer officer = new RequestOfficer(this.applicationContext);
     if (officer.CanRoute())
     {
         switch (this.Status)
         {
             case RequestStatus.New:
                 this.Status = RequestStatus.PendingApproval;
                 this.Route(recipient);
                 break;
             case RequestStatus.PendingApproval:
                 if (this.CanBeReviewed)
                 {
                     if (officer.IsUserFinalApprover() && !IsRecipientFinalApprover(recipient))
                         throw new System.InvalidOperationException(Resources.RouteToNonApproverException);
                     else
                         this.Route(recipient);
                 }
                 else
                     throw new System.InvalidOperationException(Resources.RouteNotAuthorizedException);
                 break;
             default:
                 throw new System.InvalidOperationException(string.Format(Resources.RouteNotAllowedException, this.Status));
         }
     }
     else
         throw new System.Security.SecurityException(Resources.RouteNotAuthorizedException);
 }
 /// <summary>
 /// Final approves this request with comments.
 /// </summary>
 /// <param name="comments">The comments.</param>
 public void FinalApprove(string comments)
 {
     // if you have the authority and it can be reviewed, then final approve
     RequestOfficer officer = new RequestOfficer(this.applicationContext);
     if (officer.CanApprove())
     {
         if (CanBeReviewed)
         {
             this.Status = RequestStatus.Approved;
             this.FinalReviewedBy = this.applicationContext.Identity.Name;
             this.FinalReviewedOn = DateTime.Now;
             this.PendingReviewBy = "";
             ttrProvider.Save(this);
             // audit the approval
             AddApprovalAudit(ApprovalStatus.FinalApproved, comments);
             // send out an email to the requestor
             RequestNotifier notifier = new RequestNotifier();
             notifier.SendRequestFinalReviewed(this, comments);
         }
         else
             throw new System.InvalidOperationException(Resources.FinalApproveNotAllowedException);
     }
     else
         throw new System.Security.SecurityException(Resources.FinalApproveNotAuthorizedException);
 }
 /// <summary>
 /// Denies this request with comments.
 /// </summary>
 /// <param name="comments">The comments.</param>
 public void Deny(string comments)
 {
     // if you have the authority and it can be reviewed, then deny
     RequestOfficer officer = new RequestOfficer(this.applicationContext);
     if (officer.CanDeny())
     {
         if (CanBeReviewed)
         {
             // comments are required for denial
             if (string.IsNullOrEmpty(comments))
                 throw new System.InvalidOperationException(Resources.CommentsMissingForDenyException);
             else
             {
                 this.PendingReviewBy = "";
                 this.Status = RequestStatus.Denied;
                 this.FinalReviewedBy = this.applicationContext.Identity.Name;
                 this.FinalReviewedOn = DateTime.Now;
                 ttrProvider.Save(this);
                 // audit the reviewal
                 AddApprovalAudit(ApprovalStatus.Denied, comments);
                 // notify the requestor
                 RequestNotifier notifier = new RequestNotifier();
                 notifier.SendRequestFinalReviewed(this, comments);
             }
         }
         else
             throw new System.InvalidOperationException(Resources.DenyNotAllowedException);
     }
     else
         throw new System.Security.SecurityException(Resources.DenyNotAuthorizedException);
 }
 /// <summary>
 /// Approves this request with comments. The request must be reviewable prior to approval.
 /// </summary>
 /// <param name="comments">The comments.</param>
 public void Approve(string comments)
 {
     RequestOfficer officer = new RequestOfficer(this.applicationContext);
     if (officer.CanApprove())
     {
         if (CanBeReviewed)
             AddApprovalAudit(ApprovalStatus.Approved, comments);
         else
             throw new System.InvalidOperationException(Resources.ApproveNotAllowedException);
     }
     else
         throw new System.Security.SecurityException(Resources.ApproveNotAuthorizedException);
 }
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.RequestId = System.Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);
                if (this.RequestId != 0)
                {
                    TravelAndTrainingRequestFinder requestFinder = new TravelAndTrainingRequestFinder(this.User);
                    TravelAndTrainingRequest request = requestFinder.GetRequestById(this.RequestId);

                    // adamsb 2/27/09 Check status for routing
                    if (request != null)
                    {
                        if (request.CanBeReviewed)
                        {
                            RequestOfficer securityOfficer = new RequestOfficer(this.User);
                            if (securityOfficer.CanApprove())
                                Response.Redirect(string.Format("~/Approvers/RequestApproval.aspx?id={0}",
                                    request.Id), false);
                            else
                            {
                                // if not a final approver,
                                // load the request, set the active step to the confirmation page
                                // and load the summary
                                this.UnpackRequest(request);
                                requestIsLoaded = true;
                                this.wzCreateRequest.ActiveStepIndex = 2;
                                this.LoadSummary(request);
                            }
                        }
                        else if (request.CanBeSaved)
                        {
                            // if not a final approver,
                            // load the request, set the active step to the confirmation page
                            // and load the summary
                            this.UnpackRequest(request);
                            requestIsLoaded = true;
                            this.wzCreateRequest.ActiveStepIndex = 2;
                            this.LoadSummary(request);
                        }
                        else
                            Response.Redirect("~/Main.aspx", false);
                    }
                    //if (request != null && request.CanBeSaved)
                    //{
                    //    this.UnpackRequest(request);
                    //    // if its pending review by someone, then load the summary page
                    //    if (request.PendingReviewBy.Length > 0)
                    //    {
                    //        requestIsLoaded = true;
                    //        this.wzCreateRequest.ActiveStepIndex = 2;
                    //        this.LoadSummary(request);
                    //    }
                    //}
                    //else
                    //    Response.Redirect("~/Main.aspx", false);
                }
            }
        }