Beispiel #1
0
        // POST: api/Recap
        public string Post(string restUserID, [FromBody] TravelAuthForm value)
        {
            log.WriteLogEntry("Begin RecapController POST...");
            string result = string.Empty;

            log.WriteLogEntry("REST user id " + restUserID);
            if (int.TryParse(restUserID, out int userID))
            {
                log.WriteLogEntry("Starting LoginHelper...");
                LoginHelper loginHelp = new LoginHelper();
                if (loginHelp.LoadUserSession(userID))
                {
                    DomainUser user = new DomainUser();
                    log.WriteLogEntry("Starting UserHelper...");
                    UserHelper userHelp = new UserHelper(user);
                    if (userHelp.LoadDomainUser(userID))
                    {
                        try
                        {
                            log.DumpObject(value);
                            log.WriteLogEntry("Starting FormHelper...");
                            FormHelper travelFormHelp = new FormHelper();
                            if (travelFormHelp.SubmitTravelRecapForm(userID, value))
                            {
                                log.WriteLogEntry("Starting EmailHelper...");
                                EmailHelper emailer = new EmailHelper();
                                emailer.NotifyFinance(Constants.NotificationFinanceRecap);
                                result = "Travel Recap Form Submitted.";
                            }
                            else
                            {
                                result = "Failed to submit recap form!";
                            }
                        }
                        catch (Exception ex)
                        {
                            result = "ERROR in Travel Recap Submit!\n" + ex.Message;
                            log.WriteLogEntry(result);
                            return(result);
                        }
                    }
                    else
                    {
                        result = "Failed to submit travel recap! User not found!";
                    }
                }
                else
                {
                    result = "Failed to submit travel recap! User not recognized!";
                }
            }
            else
            {
                result = "Failed to submit travel recap! Invalid user id!";
            }
            log.WriteLogEntry(result);
            log.WriteLogEntry("End RecapController POST.");
            return(result);
        }
Beispiel #2
0
 // PUT: api/TravelApproval/5
 public void Put([FromUri] string restUserID, [FromBody] TravelAuthForm travelAuthForm)
 {
     log.WriteLogEntry("Begin TravelApprovalController PUT...");
     if (int.TryParse(restUserID, out int userID))
     {
         log.WriteLogEntry("Starting LoginHelper...");
         LoginHelper loginHelp = new LoginHelper();
         if (loginHelp.LoadUserSession(userID))
         {
             DomainUser user = new DomainUser();
             log.WriteLogEntry("Starting UserHelper...");
             UserHelper userHelp = new UserHelper(user);
             if (userHelp.LoadDomainUser(userID))
             {
                 travelAuthForm.TemplateID = TemplateIndex.UpdateTravelAuth;
                 try
                 {
                     if (travelAuthForm.GetType() == typeof(TravelAuthForm))
                     {
                         log.WriteLogEntry("Start form dump...");
                         log.DumpObject(travelAuthForm);
                         log.WriteLogEntry("Starting FormHelper...");
                         FormHelper travelFormHelp = new FormHelper();
                         if (travelFormHelp.ApproveTravelAuthForm(userID, travelAuthForm))
                         {
                             EmailHelper email = new EmailHelper();
                             if (travelAuthForm.DHApproval.ToLower() == Constants.ApprovedColor && travelAuthForm.GMApproval.ToLower() != Constants.ApprovedColor)
                             {
                                 email.NotifyGeneralManager(user);
                             }
                             else if (travelAuthForm.DHApproval.ToLower() == Constants.DeniedColor && travelAuthForm.GMApproval.ToLower() != Constants.ApprovedColor)
                             {
                                 email.NotifySubmitter(travelAuthForm.Email, Constants.NotificationTravelDenied);
                             }
                             else if (travelAuthForm.GMApproval.ToLower() == Constants.ApprovedColor)
                             {
                                 email.NotifySubmitter(travelAuthForm.Email, Constants.NotificationTravelApproved);
                                 if (bool.TryParse(travelAuthForm.Advance, out bool advance))
                                 {
                                     if (advance)
                                     {
                                         email.NotifyFinance(0);
                                     }
                                     else
                                     {
                                         log.WriteLogEntry("No advance requested.");
                                     }
                                 }
                                 else
                                 {
                                     log.WriteLogEntry("FAILED to parse travel form advance boolean!");
                                 }
                             }
                             else
                             {
                                 log.WriteLogEntry("GM has not approved.");
                             }
                         }
                         else
                         {
                             log.WriteLogEntry("FAILED submit travel form!");
                         }
                     }
                     else
                     {
                         log.WriteLogEntry("FAILED submitted form is the wrong type!");
                     }
                 }
                 catch (Exception ex)
                 {
                     log.WriteLogEntry("FAILED to submit travel authorization form! " + ex.Message);
                 }
             }
             else
             {
                 log.WriteLogEntry("FAILED to load current user data!");
             }
         }
         else
         {
             log.WriteLogEntry("FAILED to load active user session!");
         }
     }
     else
     {
         log.WriteLogEntry("FAILED invalid user id!");
     }
     log.WriteLogEntry("End TravelApprovalController PUT.");
 }
Beispiel #3
0
        // POST: api/API

        public string Post([FromUri] string restUserID, [FromBody] TravelAuthForm travelAuthForm)
        {
            log.WriteLogEntry("Begin TravelAuthController POST...");
            string result = string.Empty;

            if (int.TryParse(restUserID, out int userID))
            {
                log.WriteLogEntry("Starting LoginHelper...");
                LoginHelper loginHelp = new LoginHelper();
                if (loginHelp.LoadUserSession(userID))
                {
                    DomainUser user = new DomainUser();
                    log.WriteLogEntry("Starting UserHelper...");
                    UserHelper userHelp = new UserHelper(user);
                    if (userHelp.LoadDomainUser(userID))
                    {
                        travelAuthForm.TemplateID = TemplateIndex.InsertTravelAuth;
                        try
                        {
                            if (travelAuthForm.GetType() == typeof(TravelAuthForm))
                            {
                                log.DumpObject(travelAuthForm);
                                log.WriteLogEntry("Starting FormHelper...");
                                FormHelper travelFormHelp = new FormHelper();
                                if (travelFormHelp.SubmitTravelAuthForm(user, travelAuthForm))
                                {
                                    log.WriteLogEntry("Starting EmailHelper...");
                                    EmailHelper emailer = new EmailHelper();
                                    if (userID == int.Parse(travelAuthForm.DHID))
                                    {
                                        travelFormHelp.ApproveTravelAuthForm(userID, travelAuthForm);
                                        emailer.NotifyGeneralManager(user);
                                    }
                                    else if (userID == int.Parse(travelAuthForm.GMID))
                                    {
                                        travelFormHelp.ApproveTravelAuthForm(userID, travelAuthForm);
                                        if (bool.TryParse(travelAuthForm.Advance, out bool advance))
                                        {
                                            if (advance)
                                            {
                                                emailer.NotifyFinance(Constants.NotificationFinanceAdvance);
                                            }
                                            else
                                            {
                                                log.WriteLogEntry("No advance requested.");
                                            }
                                        }
                                        else
                                        {
                                            log.WriteLogEntry("FAILED to parse travel form advance boolean!");
                                        }
                                    }
                                    else
                                    {
                                        emailer.NotifyDepartmentHead(user);
                                    }
                                }
                                else
                                {
                                    log.WriteLogEntry("Fail FormHelp SubmitForm!");
                                }
                                result = "Travel Authorization Form Submitted.";
                            }
                            else
                            {
                                log.WriteLogEntry("FAILED submitted form is the wrong type!");
                                result = "Failed to submit travel authorization form! Form not recognized!";
                            }
                        }
                        catch (Exception ex)
                        {
                            log.WriteLogEntry("FAILED to submit travel authorization form! " + ex.Message);
                            result = "Failed Travel Authorization Submit " + ex.Message;
                            return(result);
                        }
                    }
                    else
                    {
                        log.WriteLogEntry("FAILED to load current user data!");
                        result = "Failed to submit travel authorization! User not found!";
                    }
                }
                else
                {
                    log.WriteLogEntry("FAILED to load current user session!");
                    result = "Failed to submit travel authorization! User not recognized!";
                }
            }
            else
            {
                log.WriteLogEntry("FAILED invalid user id!");
            }
            log.WriteLogEntry("End TravelAuthController POST.");
            return(result);
        }
Beispiel #4
0
        // PUT: api/TravelFinance/5
        // for restButtonID 0 = Approve Advance 1 = Approve Recap (closes auth form) 2 = Deny Advance 3 = Deny Recap
        public void Put([FromUri] string restUserID, [FromUri] string restButtonID, [FromBody] TravelAuthForm travelAuthForm)
        {
            log.WriteLogEntry("Begin TravelFinanceController PUT...");
            if (int.TryParse(restUserID, out int userID))
            {
                if (int.TryParse(restButtonID, out int buttonID))
                {
                    log.WriteLogEntry("Starting LoginHelper...");
                    LoginHelper loginHelp = new LoginHelper();
                    if (loginHelp.LoadUserSession(userID))
                    {
                        DomainUser user = new DomainUser();
                        log.WriteLogEntry("Starting UserHelper...");
                        UserHelper userHelp = new UserHelper(user);
                        if (userHelp.LoadDomainUser(userID))
                        {
                            try
                            {
                                if (travelAuthForm.GetType() == typeof(TravelAuthForm))
                                {
                                    log.DumpObject(travelAuthForm);
                                    log.WriteLogEntry("Starting FormHelper...");
                                    FormHelper travelFormHelp = new FormHelper();
                                    if (travelFormHelp.HandleFinanceAction(buttonID, travelAuthForm))
                                    {
                                        log.WriteLogEntry("Starting EmailHelper...");
                                        EmailHelper email = new EmailHelper();
                                        switch (buttonID)
                                        {
                                        case 0:
                                        {
                                            email.NotifySubmitter(travelAuthForm.Email, Constants.NotificationTravelAdvance);
                                            break;
                                        }

                                        case 1:
                                        {
                                            email.NotifySubmitter(travelAuthForm.Email, Constants.NotificationTravelRecap);
                                            break;
                                        }

                                        case 2:
                                        {
                                            string message = string.Format("{0}{1}{2}{3}{4}", travelAuthForm.EventTitle, Environment.NewLine, travelAuthForm.Location, Environment.NewLine, travelAuthForm.MailMessage);
                                            email.NotifySubmitter(travelAuthForm.Email, message);
                                            break;
                                        }

                                        case 3:
                                        {
                                            string message = string.Format("{0}{1}{2}{3}{4}", travelAuthForm.EventTitle, Environment.NewLine, travelAuthForm.Location, Environment.NewLine, travelAuthForm.MailMessage);
                                            email.NotifySubmitter(travelAuthForm.Email, message);
                                            break;
                                        }

                                        default:
                                        {
                                            log.WriteLogEntry("Fell through button ID switch. No email sent.");
                                            break;
                                        }
                                        }
                                    }
                                }
                                else
                                {
                                    log.WriteLogEntry("FAILED submitted form is the wrong type!");
                                }
                            }
                            catch (Exception ex)
                            {
                                log.WriteLogEntry("FAILED to submit travel authorization form! " + ex.Message);
                            }
                        }
                        else
                        {
                            log.WriteLogEntry("FAILED to load current user data!");
                        }
                    }
                    else
                    {
                        log.WriteLogEntry("FAILED to load active user session!");
                    }
                }
                else
                {
                    log.WriteLogEntry("FAILED invalid button id!");
                }
            }
            else
            {
                log.WriteLogEntry("FAILED invalid user id!");
            }
            log.WriteLogEntry("End TravelFinanceController PUT.");
        }
Beispiel #5
0
        public int LoadTravelForms(int commandID, int fieldID)
        {
            log.WriteLogEntry("Begin LoadTravelForms...");
            log.WriteLogEntry("Command ID: " + commandID + " Field ID: " + fieldID);
            int result = 0;

            string[] formFields = new string[0];
            string[,] formFilters = new string[0, 0];
            this.WebForms         = new List <BaseForm>();
            List <BaseForm> travelForms    = new List <BaseForm>();
            FormDataHandler formDataHandle = new FormDataHandler(dbServer, dbName);

            switch (commandID)
            {
            case Constants.GetFinanceTravelForms:     // Load Finance Travel Forms
            {
                log.WriteLogEntry("Handling command ID: " + commandID);
                string cmdString = string.Format(@"select * from valhalla.dbo.travel where close_status = 2 and approval_status = 1 and ((request_advance = 1 and advance_status = 2) or (advance_status = 1 and recap_status = 2))", dbName);

                log.WriteLogEntry("Starting FormDataHandler...");
                if (formDataHandle.LoadTravelForms(travelForms, cmdString) > 0)
                {
                    foreach (TravelAuthForm travelForm in travelForms)
                    {
                        if (ConvertStatusValues(travelForm))
                        {
                            log.DumpObject(travelForm);
                            this.WebForms.Add(travelForm);
                            result++;
                        }
                        else
                        {
                            log.WriteLogEntry("FAILED to convert status colors!");
                            break;
                        }
                    }
                }
                else
                {
                    log.WriteLogEntry("No forms found.");
                }
                break;
            }

            case Constants.GetUserTravelForms:     // Load User Travel Forms
            {
                log.WriteLogEntry("Handling command ID: " + commandID);
                int userID = fieldID;
                try
                {
                    formFields  = new string[] { "*" };
                    formFilters = new string[, ] {
                        { "submitter_id", userID.ToString(), "=", "and" },
                        { "close_status", Constants.PendingValue.ToString(), "=", "and" }
                    };
                }
                catch (Exception ex)
                {
                    log.WriteLogEntry("ERROR building SQL field and filter arrays!\n" + ex.Message);
                    return(result);
                }

                log.WriteLogEntry("Starting FormDataHandler...");
                if (formDataHandle.LoadTravelForms(travelForms, formFields, formFilters) > 0)
                {
                    foreach (TravelAuthForm travelForm in travelForms)
                    {
                        if (ConvertStatusValues(travelForm))
                        {
                            log.DumpObject(travelForm);
                            this.WebForms.Add(travelForm);
                            result++;
                        }
                        else
                        {
                            log.WriteLogEntry("FAILED to convert status colors!");
                            break;
                        }
                    }
                }
                else
                {
                    log.WriteLogEntry("No forms found.");
                }
                break;
            }

            case Constants.GetApproverTravelForms:     // Load Approver Travel Forms
            {
                log.WriteLogEntry("Handling command ID: " + commandID);
                int userID = fieldID;
                try
                {
                    formFields  = new string[] { "*" };
                    formFilters = new string[, ] {
                        { "supervisor_id", userID.ToString(), "=", "or" },
                        { "manager_id", userID.ToString(), "=", "or" },
                        { "approval_status", Constants.PendingValue.ToString(), "=", "and" }
                    };
                }
                catch (Exception ex)
                {
                    log.WriteLogEntry("ERROR building SQL field and filter arrays!\n" + ex.Message);
                    return(result);
                }

                log.WriteLogEntry("Starting FormDataHandler...");
                if (formDataHandle.LoadTravelForms(travelForms, formFields, formFilters) > 0)
                {
                    foreach (TravelAuthForm travelForm in travelForms)
                    {
                        if (ConvertStatusValues(travelForm))
                        {
                            if (userID == int.Parse(travelForm.GMID) && travelForm.DHApproval.ToLower() == Constants.ApprovedColor)
                            {
                                this.WebForms.Add(travelForm);
                                result++;
                            }
                            else if (userID == int.Parse(travelForm.DHID) && travelForm.DHApproval.ToLower() == Constants.PendingColor)
                            {
                                this.WebForms.Add(travelForm);
                                result++;
                            }
                            else
                            {
                                log.WriteLogEntry("No forms available for approval by user " + userID);
                            }
                            log.DumpObject(travelForm);
                        }
                        else
                        {
                            log.WriteLogEntry("FAILED to convert status colors!");
                            break;
                        }
                    }
                }
                else
                {
                    log.WriteLogEntry("No forms available for approval by user " + userID);
                }
                break;
            }

            default:
            {
                log.WriteLogEntry("Fell through switch button ID. No action taken.");
                return(result);
            }
            }
            log.WriteLogEntry("Count loaded forms " + result);
            log.WriteLogEntry("End LoadTravelForms.");
            return(result);
        }