Esempio n. 1
0
        public HttpResponseMessage GetapproverDetails(string travelRequestId)
        {
            HttpResponseMessage response = null;

            try
            {
                SubmitTravelRequest result = approvalService.GetapproverDetails(travelRequestId);
                response = Request.CreateResponse(HttpStatusCode.OK, result);
            }
            catch (Exception ex)
            {
                LogMessage.Log("GetapproverDetails :" + ex.Message);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Couldn't retrieve approver information " + ex.Message);
            }
            return(response);
        }
Esempio n. 2
0
        public HttpResponseMessage SubmitTravelRequestNew(SubmitTravelRequest submitTravelRequest)
        {
            HttpResponseMessage response = null;

            try
            {
                var result = approvalService.SubmitTravelRequestNew(submitTravelRequest);
                response = Request.CreateResponse(HttpStatusCode.OK, result);
            }
            catch (Exception ex)
            {
                LogMessage.Log("api/approval/submitNew :" + ex.Message);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, "Travel request was not successfully submited. Please try again.");
            }

            return(response);
        }
Esempio n. 3
0
        public bool SubmitTravelRequestNew(SubmitTravelRequest submitTravelRequest)
        {
            var result = approvalRepository.SubmitTravelRequestNew(submitTravelRequest);

            return(result);
        }
Esempio n. 4
0
        public bool SubmitTravelRequestNew(SubmitTravelRequest submitTravelRequest)
        {
            try
            {
                var isSubmitterRequesting = false;

                using (dbConn = ConnectionFactory.GetOpenDefaultConnection())
                {
                    OracleCommand cmd2 = new OracleCommand();

                    cmd2.Connection  = (OracleConnection)dbConn;
                    cmd2.CommandText = string.Format(@"Select * from TRAVELREQUEST_APPROVAL where TravelRequestId = {0}", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId);
                    DbDataReader dataReader = cmd2.ExecuteReader();
                    if (dataReader.HasRows)
                    {
                        foreach (var item in submitTravelRequest.HeirarchichalApprovalRequest.ApproverList)
                        {
                            if (item.ApproverBadgeNumber != 0)
                            {
                                cmd2.CommandText = string.Format(@"Select * from TRAVELREQUEST_APPROVAL where TravelRequestId = {0} AND BADGENUMBER = {1}", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId, item.ApproverBadgeNumber);
                                dataReader       = cmd2.ExecuteReader();
                                if (dataReader.HasRows)
                                {
                                    //  Check if the approval already exists
                                    OracleCommand cmd = new OracleCommand();
                                    cmd.Connection  = (OracleConnection)dbConn;
                                    cmd.CommandText = string.Format(@"Update TRAVELREQUEST_APPROVAL SET                                                   
                                                            BADGENUMBER = :p1,
                                                            APPROVERNAME = :p2,                                                                                                                     
                                                            APPROVEROTHERBADGENUMBER = :p3 WHERE TRAVELREQUESTID = {0} AND APPROVALORDER = {1} ", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId, item.ApprovalOrder);
                                    cmd.Parameters.Add(new OracleParameter("p1", item.ApproverBadgeNumber));
                                    cmd.Parameters.Add(new OracleParameter("p2", item.ApproverName));
                                    cmd.Parameters.Add(new OracleParameter("p6", item.ApproverOtherBadgeNumber));
                                    var rowsUpdated = cmd.ExecuteNonQuery();
                                    cmd.Dispose();
                                }
                                else
                                {
                                    OracleCommand cmd = new OracleCommand();
                                    cmd.Connection  = (OracleConnection)dbConn;
                                    cmd.CommandText = @"INSERT INTO TRAVELREQUEST_APPROVAL (                                                  
                                                            TRAVELREQUESTID,
                                                            BADGENUMBER,
                                                            APPROVERNAME,
                                                            APPROVALSTATUS,
                                                            APPROVALORDER,
                                                            APPROVEROTHERBADGENUMBER
                                                        )
                                                        VALUES
                                                            (:p1,:p2,:p3,:p4,:p5,:p6)";
                                    cmd.Parameters.Add(new OracleParameter("p1", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId));
                                    cmd.Parameters.Add(new OracleParameter("p2", item.ApproverBadgeNumber));
                                    cmd.Parameters.Add(new OracleParameter("p3", item.ApproverName));
                                    cmd.Parameters.Add(new OracleParameter("p4", Common.ApprovalStatus.Pending.ToString()));
                                    cmd.Parameters.Add(new OracleParameter("p5", item.ApprovalOrder));
                                    cmd.Parameters.Add(new OracleParameter("p6", item.ApproverOtherBadgeNumber));
                                    var rowsUpdated = cmd.ExecuteNonQuery();
                                    cmd.Dispose();
                                }
                            }
                            else
                            {
                                OracleCommand cmd = new OracleCommand();
                                cmd.Connection  = (OracleConnection)dbConn;
                                cmd.CommandText = string.Format(@"Delete from TRAVELREQUEST_APPROVAL where TravelRequestId = {0} AND APPROVALORDER = {1}", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId, item.ApprovalOrder);
                                cmd.ExecuteNonQuery();
                            }
                        }
                    }
                    else
                    {
                        cmd2.Connection  = (OracleConnection)dbConn;
                        cmd2.CommandText = string.Format(@"Delete from TRAVELREQUEST_APPROVAL where TravelRequestId = {0}", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId);
                        cmd2.ExecuteNonQuery();
                        if ((submitTravelRequest.HeirarchichalApprovalRequest.SignedInBadgeNumber != submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestBadgeNumber) && (submitTravelRequest.HeirarchichalApprovalRequest.SignedInBadgeNumber != 85163))
                        {
                            // submit to approval
                            isSubmitterRequesting = true;

                            cmd2.Connection  = (OracleConnection)dbConn;
                            cmd2.CommandText = @"INSERT INTO TRAVELREQUEST_APPROVAL (                                                  
                                                                TRAVELREQUESTID,
                                                                BADGENUMBER,
                                                                APPROVERNAME,
                                                                APPROVALSTATUS,
                                                                APPROVALORDER 
                                                            )
                                                            VALUES
                                                                (:p1,:p2,:p3,:p4,:p5)";
                            cmd2.Parameters.Add(new OracleParameter("p1", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId));
                            cmd2.Parameters.Add(new OracleParameter("p2", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestBadgeNumber));
                            cmd2.Parameters.Add(new OracleParameter("p3", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestName));
                            cmd2.Parameters.Add(new OracleParameter("p4", Common.ApprovalStatus.Pending.ToString()));
                            cmd2.Parameters.Add(new OracleParameter("p5", "0"));
                            var rowsUpdated = cmd2.ExecuteNonQuery();
                            cmd2.Dispose();
                        }
                        foreach (var item in submitTravelRequest.HeirarchichalApprovalRequest.ApproverList)
                        {
                            if (item.ApproverBadgeNumber != 0)
                            {
                                // submit to approval
                                OracleCommand cmd = new OracleCommand();
                                cmd.Connection  = (OracleConnection)dbConn;
                                cmd.CommandText = @"INSERT INTO TRAVELREQUEST_APPROVAL (                                                  
                                                            TRAVELREQUESTID,
                                                            BADGENUMBER,
                                                            APPROVERNAME,
                                                            APPROVALSTATUS,
                                                            APPROVALORDER,
                                                            APPROVEROTHERBADGENUMBER
                                                        )
                                                        VALUES
                                                            (:p1,:p2,:p3,:p4,:p5,:p6)";
                                cmd.Parameters.Add(new OracleParameter("p1", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId));
                                cmd.Parameters.Add(new OracleParameter("p2", item.ApproverBadgeNumber));
                                cmd.Parameters.Add(new OracleParameter("p3", item.ApproverName));
                                cmd.Parameters.Add(new OracleParameter("p4", Common.ApprovalStatus.Pending.ToString()));
                                cmd.Parameters.Add(new OracleParameter("p5", item.ApprovalOrder));
                                cmd.Parameters.Add(new OracleParameter("p6", item.ApproverOtherBadgeNumber));
                                var rowsUpdated = cmd.ExecuteNonQuery();
                                cmd.Dispose();
                            }
                        }
                        //send new submission email
                        sendNewRequestEmail(submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestBadgeNumber, "Travel Request Submitted Successfully", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId);
                    }
                    OracleCommand cmd1 = new OracleCommand();
                    cmd1.Connection  = (OracleConnection)ConnectionFactory.GetOpenDefaultConnection();
                    cmd1.CommandText = string.Format(@"UPDATE TRAVELREQUEST SET                                                 
                                                       SUBMITTEDBYUSERNAME = :p1 ,
                                                        SUBMITTEDDATETIME = :p2,
                                                        STATUS = :p3,
                                                        AGREE = :p4
                                                   WHERE TRAVELREQUESTID = {0}", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId);

                    cmd1.Parameters.Add(new OracleParameter("p1", submitTravelRequest.HeirarchichalApprovalRequest.SubmittedByUserName));
                    cmd1.Parameters.Add(new OracleParameter("p2", DateTime.Now));
                    cmd1.Parameters.Add(new OracleParameter("p3", Common.ApprovalStatus.Pending.ToString()));
                    cmd1.Parameters.Add(new OracleParameter("p4", (submitTravelRequest.HeirarchichalApprovalRequest.AgreedToTermsAndConditions) ? "Y" : "N"));
                    var rowsUpdated1 = cmd1.ExecuteNonQuery();


                    var result = getNextApproverBadgeNumber(cmd1.Connection, submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId, "TRAVELREQUEST_APPROVAL");

                    string subject = string.Format(@"Travel Request Approval for Id - {0} ", submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId);


                    if (submitTravelRequest.HeirarchichalApprovalRequest.SignedInBadgeNumber != result)
                    {
                        var dateTime = System.DateTime.Now.Ticks;
                        //Generate Crystal report
                        travelRequestReportService.RunReport("Travel_Request.rpt", "TravelRequest_" + submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId + "_" + dateTime, submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId.ToString());

                        if (isSubmitterRequesting)
                        {
                            sendEmail(submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestBadgeNumber, subject, submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId, "Form1", "TravelRequest_" + submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId + "_" + dateTime);
                        }
                        else
                        {
                            sendEmail(result, subject, submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId, "Form1", "TravelRequest_" + submitTravelRequest.HeirarchichalApprovalRequest.TravelRequestId + "_" + dateTime);
                        }
                    }

                    cmd1.Dispose();
                    dbConn.Close();
                    dbConn.Dispose();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogMessage.Log("Repository : SubmitTravelRequestNew " + ex.Message);
                throw new Exception(ex.Message);
            }
        }
Esempio n. 5
0
        public SubmitTravelRequest GetapproverDetails(string travelRequestId)
        {
            SubmitTravelRequest result = approvalRepository.GetApproverDetails(travelRequestId);

            return(result);
        }