Exemple #1
0
        static void Main(string[] args)
        {
            List <Employee> mgrs = new List <Employee>
            {
                new Employee("Prasad Honrao", 1000),
                new Employee("Colin Gray", 2000),
                new Employee("John Papa", 3000),
                new Employee("Dan Wahlin", 4000)
            };

            while (true)
            {
                Console.WriteLine("Enter expense amount");
                var           amount = Console.ReadLine();
                ExpenseReport report = new ExpenseReport(Convert.ToDecimal(amount));

                bool expenseReportProcessed = false;

                foreach (var approver in mgrs)
                {
                    ApprovalResponse response = approver.ApproveExpense(report);
                    if (response != ApprovalResponse.BeyondApprovalLimit)
                    {
                        Console.WriteLine("The expense report with amount {0} was approved by {1}", report.Total, approver.Name);
                        expenseReportProcessed = true;
                        break;
                    }
                }

                if (!expenseReportProcessed)
                {
                    Console.WriteLine("No one was able to approve expense report!");
                }
            }
        }
Exemple #2
0
        public void Approve(UniqueIdentifier workflowInstance, UniqueIdentifier approvalRequest, bool approve, string reason = null)
        {
            if (workflowInstance == null)
            {
                throw new ArgumentNullException(nameof(workflowInstance));
            }

            if (approvalRequest == null)
            {
                throw new ArgumentNullException(nameof(approvalRequest));
            }

            ApprovalResponse response = new ApprovalResponse
            {
                Decision = approve ? ResourceFactoryClient.ApprovedText : ResourceFactoryClient.RejectedText,
                Reason   = reason,
                Approval = approvalRequest.ToString()
            };


            using (Message message = MessageComposer.CreateApprovalMessage(workflowInstance, response))
            {
                using (Message responseMessage = this.Invoke((c) => c.Create(message)))
                {
                    responseMessage.ThrowOnFault();
                }
            }
        }
Exemple #3
0
 // Called if the ApprovalRequestsService gets a response to a approval request generated locally
 public static void ApprovalRequestResponse(ApprovalResponse response)
 {
     if (Context != null)
     {
         Context.ProcessResponse(response);
     }
 }
        public async Task <IActionResult> Post([FromBody] dynamic approvalRequest)
        {
            try
            {
                _logger.LogInformation($"Request JSON received: {approvalRequest}");

                var approval = JsonConvert.DeserializeObject <ApprovalRequest>(approvalRequest.ToString());
                var response = await _approvalService.ProcessRequest(approval);

                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"There was an error processing request. Message: {ex.Message}");

                var errorResponse = new ApprovalResponse {
                    DeliveryApproval = new DeliveryApproval {
                        Global = new ApprovalStatus {
                            Status = "forbid", Message = ex.Message
                        }
                    }
                };

                // For some reason, Seismic DeliveryApproval app needs the error to be sent as a HTTP 200 OK response.
                // This service requires a 200 or 202 response. If 200, conforms to approved response payload, 202 means the provider will get back the answer within 3 seconds with proper 200 code
                return(Ok(errorResponse));
            }
        }
        private static void RequestStupidlyExpensiveExpense(ExpenseHandler manager)
        {
            IExpenseReport   stupidlyExpensiveExpenseReport = new ExpenseReport(25000);
            ApprovalResponse stupidlyExpensiveResponse      = manager.Approve(stupidlyExpensiveExpenseReport);

            Console.WriteLine("The request for {0} was {1}.", stupidlyExpensiveExpenseReport.Total, stupidlyExpensiveResponse);
        }
Exemple #6
0
        public async Task <PendingApprovalResponse> GetPendingApproval()
        {
            PendingApprovalResponse objPendingApproval = new PendingApprovalResponse();
            var events = await _eventBookingRepository.GetPendingApprovalDB();

            if (events.Count > 0)
            {
                for (int i = 0; i < events.Count; i++)
                {
                    ApprovalResponse ObjResponse = new ApprovalResponse();
                    ObjResponse.UserID             = events[i].UserID;
                    ObjResponse.AadharNum          = events[i].AadharNum;
                    ObjResponse.AadharImage        = Convert.ToBase64String(events[i].AadharImage);
                    ObjResponse.AdditionalDocImage = Convert.ToBase64String(events[i].AdditionalDocImage);
                    ObjResponse.AddtionDocDetails  = events[i].AddtionDocDetails;
                    ObjResponse.RequestID          = events[i].RequestID;
                    ObjResponse.Status             = events[i].Status;
                    objPendingApproval.response.Add(ObjResponse);
                }
                objPendingApproval.ResponseMessage = "Sucess";
            }
            else
            {
                objPendingApproval.ResponseMessage = "No new Reqests found for Customer Partnership Approval";
            }
            return(objPendingApproval);
        }
        private static void RequestRatherExpensiveExpense(ExpenseHandler manager)
        {
            IExpenseReport   ratherExpensiveExpenseReport = new ExpenseReport(5500);
            ApprovalResponse ratherExpensiveResponse      = manager.Approve(ratherExpensiveExpenseReport);

            Console.WriteLine("The request for {0} was {1}.", ratherExpensiveExpenseReport.Total, ratherExpensiveResponse);
        }
        private static void RequestCheapExpense(ExpenseHandler manager)
        {
            IExpenseReport   cheapExpenseReport   = new ExpenseReport(500);
            ApprovalResponse cheapExpenseResponse = manager.Approve(cheapExpenseReport);

            Console.WriteLine("The request for {0} was {1}.", cheapExpenseReport.Total, cheapExpenseResponse);
        }
        private static void RequestMildlyCheapExpense(ExpenseHandler manager)
        {
            IExpenseReport   mildlyCheapExpenseReport  = new ExpenseReport(1250);
            ApprovalResponse mildlyCheapExpenseReponse = manager.Approve(mildlyCheapExpenseReport);

            Console.WriteLine("The request for {0} was {1}.", mildlyCheapExpenseReport.Total, mildlyCheapExpenseReponse);
        }
Exemple #10
0
        private static void Main(string[] args)
        {
            List <Employee> managers = new List <Employee>()
            {
                new Employee("Rajiv Ranjan", Decimal.Zero),
                new Employee("Arun Chaudhary", new Decimal(1000)),
                new Employee("Sanjeev Dhawan", new Decimal(5000)),
                new Employee("Avirag Jain", new Decimal(20000))
            };

            Decimal expenseReportAmount = 500;
            bool    expenseProcessed    = false;

            // Problem : Requester has to go to each manager for approval.
            // Requestor should only go to manager for approval.
            // If manager is not able to approve then its manager's responsibility to forward request to next lever for approval
            foreach (Employee approver in managers)
            {
                ApprovalResponse response = approver.ApproveExpense(expenseReportAmount);
                if (response != ApprovalResponse.BeyondApprovalLimit)
                {
                    Console.WriteLine("The request was {0}", response);
                    expenseProcessed = true;
                    break;
                }
            }

            if (!expenseProcessed)
            {
                Console.WriteLine("No one was able to approve your expense.");
            }

            Console.Read();
        }
Exemple #11
0
        private static void Main(string[] args)
        {
            ExpenseHandler william = new ExpenseHandler(new ApprovalManager("William Worker", Decimal.Zero));
            ExpenseHandler mary    = new ExpenseHandler(new ApprovalManager("Mary Manager", new Decimal(1000)));
            ExpenseHandler victor  = new ExpenseHandler(new ApprovalManager("Victor Vice-president", new Decimal(5000)));
            ExpenseHandler paula   = new ExpenseHandler(new ApprovalManager("Paula President", new Decimal(20000)));

            william.RegisterNext(mary);
            mary.RegisterNext(victor);
            victor.RegisterNext(paula);

            do
            {
                Console.Clear();
                Console.WriteLine("Enter expense amount");
                decimal expenseReportAmount;
                string  approver = String.Empty;
                if (decimal.TryParse(Console.ReadLine(), out expenseReportAmount))
                {
                    IExpenseReport   expense  = new ExpenseReport(expenseReportAmount);
                    ApprovalResponse response = mary.Approve(expense, ref approver);
                    Console.WriteLine($"Your expense request is {response} and the approver is { approver} ")
                    ;

                    Console.WriteLine("Press a key to continue, Escape to exit");
                }
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
Exemple #12
0
        public void ApproveExpenseWithInstanceExpenseApprover()
        {
            ExpenseHandler   mary     = new ExpenseHandler(new Employee("Mary Manager", new Decimal(1000)));
            ApprovalResponse response = mary.Approve(new ExpenseReport(500));

            Assert.Equal(ApprovalResponse.Approved, response);
        }
Exemple #13
0
        public void ProcessResponse(ApprovalResponse response)
        {
            object requestToDel = null;

            foreach (object o in PendingList.Items)
            {
                if (((ApprovalRequest)o).Id.Equals(response.Id))
                {
                    requestToDel = o;
                    break;
                }
            }
            if (requestToDel != null)
            {
                lock (PendingList)
                {
                    // This function may have been called from another thread so we must
                    //  schedule the work with the WPF dispatcher
                    PendingList.Items.Dispatcher.Invoke((Action <ApprovalRequest>) delegate(ApprovalRequest r)
                                                        { PendingList.Items.Remove(r); PendingList_SelectionChanged(this, null); },
                                                        requestToDel);
                }
                lock (ApprovedList)
                {
                    ApprovedList.Items.Dispatcher.Invoke((Action <ApprovalResponse>) delegate(ApprovalResponse r) { ApprovedList.Items.Add(r); },
                                                         response);
                }
            }
        }
Exemple #14
0
        public ApprovalResponse Approve(IExpenseReport expenseReport)
        {
            ApprovalResponse response = _approver.ApproveExpense(expenseReport);

            return(response == ApprovalResponse.BeyondApprovalLimit
                ? _next.Approve(expenseReport)
                : response);
        }
Exemple #15
0
        public void ApprovalProcessResults(bool Approved, System.Guid Id)
        {
            ApprovalResponse inValue = new ApprovalResponse();

            inValue.Approved = Approved;
            inValue.Id       = Id;
            ((IApprovalResults)(this)).ApprovalProcessResults(inValue);
        }
Exemple #16
0
        internal static Message CreateApprovalMessage(UniqueIdentifier workflowID, ApprovalResponse response)
        {
            Message message = Message.CreateMessage(MessageVersion.Default, Namespaces.Create, new SerializerBodyWriter(response));

            message.Headers.Add(new ContextHeader(workflowID.Value));

            return(message);
        }
Exemple #17
0
        public void DenyAnyExpenseReport(decimal expenseAmount)
        {
            EndOfChainExpenseHandler handler = EndOfChainExpenseHandler.Instance;

            ApprovalResponse response = handler.Approve(new ExpenseReport(expenseAmount));

            Assert.Equal(ApprovalResponse.Denied, response);
        }
Exemple #18
0
        public ApprovalResponse Approve(IExpenseReport expense)
        {
            ApprovalResponse response = _approver.ApproveExpense(expense);

            if (response == ApprovalResponse.BeyondApprovalLimit)
            {
                return(_next.Approve(expense));
            }
            return(response);
        }
        public ApprovalResponse Approve(decimal expenseAmount)
        {
            ApprovalResponse response = _approver.Approve(expenseAmount);

            if (response == ApprovalResponse.BeyondApprovalLimit)
            {
                return(_next.Approve(expenseAmount));
            }
            return(response);
        }
Exemple #20
0
        public void DeclineExpenseReportWithBeyondApprovalLimitIfExpenseAmountIsGreaterThanApprovalLimit()
        {
            Employee employee = new Employee("Tom", 1000m);

            ExpenseReport report = new ExpenseReport(1500);

            ApprovalResponse response = employee.ApproveExpense(report);

            Assert.Equal(ApprovalResponse.BeyondApprovalLimit, response);
        }
Exemple #21
0
        public void ApproveExpenseReportIfExpenseAmountIsLessThanApprovalLimit()
        {
            Employee employee = new Employee("Tom", 1000m);

            ExpenseReport report = new ExpenseReport(500);

            ApprovalResponse response = employee.ApproveExpense(report);

            Assert.Equal(ApprovalResponse.Approved, response);
        }
        public ApprovalResponse HandleRequest(ExpenseReport expenseReport)
        {
            ApprovalResponse response = _employee.ApproveExpense(expenseReport.Total);

            if (response == ApprovalResponse.BeyondApprovalLimit)
            {
                return(_next.HandleRequest(expenseReport));
            }
            return(response);
        }
Exemple #23
0
        public void DeclineExpenseForAmountThatNoExpenseHandlerCanApprove()
        {
            ExpenseHandler mary   = new ExpenseHandler(new Employee("Mary Manager", new Decimal(1000)));
            ExpenseHandler victor = new ExpenseHandler(new Employee("Victor Vicepres", new Decimal(5000)));

            mary.RegisterNext(victor);

            ApprovalResponse response = mary.Approve(new ExpenseReport(15000));

            Assert.Equal(ApprovalResponse.Denied, response);
        }
Exemple #24
0
        public void ApproveExpenseWithInstanceNextExpenseHandler()
        {
            ExpenseHandler mary   = new ExpenseHandler(new Employee("Mary Manager", new Decimal(1000)));
            ExpenseHandler victor = new ExpenseHandler(new Employee("Victor Vicepres", new Decimal(5000)));

            mary.RegisterNext(victor);

            ApprovalResponse response = mary.Approve(new ExpenseReport(1500));

            Assert.Equal(ApprovalResponse.Approved, response);
        }
        public void It_has_a_constructor_that_takes_an_IdmResource_without_Creator()
        {
            var resource = new IdmResource
            {
                DisplayName = "My Display Name",
            };
            var it = new ApprovalResponse(resource);

            Assert.AreEqual("My Display Name", it.DisplayName);
            Assert.IsNull(it.Creator);
        }
Exemple #26
0
        public ApprovalResponse Approve(IExpenceReport expenceReport)
        {
            ApprovalResponse response = this.approver.ApproveExpence(expenceReport);

            if (response == ApprovalResponse.BeyondTheLimit)
            {
                return(next.Approve(expenceReport));
            }

            return(response);
        }
Exemple #27
0
        public ApprovalResponse Approve(IExpenseReport expenseReport)
        {
            ApprovalResponse response = this.approver.ApproveExpense(expenseReport);

            if (response == ApprovalResponse.BeyondApprovalLimit)
            {
                return(this.nextHandler.Approve(expenseReport));
            }

            return(response);
        }
        public ApprovalResponse Approve(IExpenseReport expenseReport)
        {
            ApprovalResponse response = _approver.ApproveExpense(expenseReport);

            if (response == ApprovalResponse.BeyondApprovalLimit)
            {
                return(_next.Approve(expenseReport));
            }
            Console.WriteLine($"Approved by {(_approver as Employee).Name}");
            return(response);
        }
Exemple #29
0
        public ApprovalResponse Approve(IExpenseReport expenseReport, ref string approval)
        {
            ApprovalResponse response = _approver.ApproveExpense(expenseReport);

            if (response == ApprovalResponse.BeyondApprovalLimit)
            {
                return(_next.Approve(expenseReport, ref approval));
            }

            approval = _approver.Name;
            return(response);
        }
Exemple #30
0
        public void Run()
        {
            ExpenseHandler william = new ExpenseHandler(new Employee("William Worker", Decimal.Zero));
            ExpenseHandler mary    = new ExpenseHandler(new Employee("Mary Manager", new Decimal(1000)));
            ExpenseHandler victor  = new ExpenseHandler(new Employee("Victor VP", new Decimal(5000)));
            ExpenseHandler paula   = new ExpenseHandler(new Employee("Paula President", new decimal(20000)));

            william.RegisterNext(mary);
            mary.RegisterNext(victor);
            victor.RegisterNext(paula);
            Decimal expenseReportAmount;

            if (ConsoleInput.TryReadDecimal("Input Expense Amount Report: ", out expenseReportAmount))
            {
                IExpenseReport expense = new ExpenseReport(expenseReportAmount);

                ApprovalResponse response = william.Approve(expense);

                Console.WriteLine($"The request was {response}");
            }

            /*
             * IEnumerable <Employee> managers = new List<Employee>()
             * {
             *  new Employee("William Worker",Decimal.Zero),
             *  new Employee("Mary Manager",new Decimal(1000)),
             *  new Employee("Victor VP",new Decimal(5000)),
             *  new Employee("Paula President",new decimal(20000))
             * };
             * Decimal expenseReportAmount;
             * while (Console.ReadLine())
             * {
             *  IExpenseReport expense = new ExpenseReport(expenseReportAmount);
             *  bool expenseProcessed = false;
             *
             *  foreach (Employee approver in managers)
             *  {
             *      ApprovalResponse response = approver.ApprovalExpense(expense);
             *      if (response != ApprovalResponse.BeyondApprovalLimit)
             *      {
             *          Console.WriteLine($"The request was {response}");
             *          expenseProcessed = true;
             *          break;
             *      }
             *  }
             *  if (!expenseProcessed)
             *  {
             *      Console.WriteLine("No one was able to approve your expense.");
             *  }
             * }
             */
        }