예제 #1
0
        /// <summary>
        /// Calculates the percent of the step goal reached.
        /// </summary>
        public OperationResult<decimal> CalculatePercentOfGoalStepsOR(string goalSteps, string actualSteps)
        {
            var operationResult = new OperationResult<decimal>(0m, "");

            if (string.IsNullOrWhiteSpace(goalSteps))
            {
                operationResult.AddMessage("Goal steps must be entered");
                return operationResult;
            }
            if (string.IsNullOrWhiteSpace(actualSteps))
            {
                operationResult.AddMessage("Actual steps must be entered");
                return operationResult;
            }

            decimal goalStepCount = 0;
            if (!decimal.TryParse(goalSteps, out goalStepCount))
            {
                operationResult.AddMessage("Goal steps must be numeric");
                return operationResult;
            }

            decimal actualStepCount = 0;
            if (!decimal.TryParse(actualSteps, out actualStepCount))
            {
                operationResult.AddMessage("Actual steps must be numeric");
                return operationResult;
            }

            operationResult.Value = CalculatePercentOfGoalSteps(goalStepCount, actualStepCount);
            return operationResult;
        }
예제 #2
0
 public OperationResult DeleteByRowNumber(string rowNumber)
 {
     var result = new OperationResult();
     try
     {
         _ctx.Rows.Remove(Query.EQ("Number", rowNumber));
     }
     catch (Exception ex)
     {
         result.Success = false;
         result.AddMessage(ex.Message);
     }
     return result;
 }
예제 #3
0
 public OperationResult Add(Row rowToAdd)
 {
     var result = new OperationResult();
     try
     {
         _ctx.Rows.Insert(rowToAdd);
     }
     catch (Exception ex)
     {
         result.Success = false;
         result.AddMessage(ex.Message);
     }
     return result;
 }
예제 #4
0
        /// <summary>
        /// Validates the customer email address.
        /// </summary>
        /// <returns></returns>
        public OperationResult<bool> ValidateEmail()
        {
            var op = new OperationResult<bool>();

            if (string.IsNullOrWhiteSpace(this.EmailAddress))
            {
                op.Value = false;
                op.AddMessage("Email address is null");
            }

            if (op.Value)
            {
                var isValidFormat = true;
                // Code here that validates the format of the email
                // using Regular Expressions.
                if (!isValidFormat)
                {
                    op.Value = false;
                    op.AddMessage("Email address is not in a correct format");
                }
            }

            if (op.Value)
            {
                var isRealDomain = true;
                // Code here that confirms whether domain exists.
                if (!isRealDomain)
                {
                    op.Value = false;
                    op.AddMessage("Email address does not include a valid domain");
                }
            }
            return op;
        }
        public OperationResult PlaceOrder(Customer customer, Order order, Payment payment, bool allowSplitOrders, bool emailReceipt)
        {
            // This program makes assertions that certain functions are running (as functions below)
            // These will throw a warning during debuging if an assertion isn't true
            Debug.Assert(customerRepository != null, "Missing customer repository instance N***A");
            Debug.Assert(orderRepository != null, "Missing order repository instance");
            Debug.Assert(inventoryRepository != null, "Missing inventory repository instance");
            Debug.Assert(emailLibrary != null, "Missing email library instance");

            if (customer == null) throw new ArgumentNullException("Customer instance is null");
            if (order == null) throw new ArgumentNullException("Order instance is null");
            if (payment == null) throw new ArgumentNullException("Payment instance is null");

            var op = new OperationResult();

            customerRepository.Add(customer);

            orderRepository.Add(order);

            inventoryRepository.OrderItems(order, allowSplitOrders);

            payment.ProcessPayment();

            if (emailReceipt)
            {
                var result = customer.ValidateEmail();
                if (result.Success)
                {
                    customerRepository.Update();

                    emailLibrary.SendEmail(customer.EmailAddress, "Here is your receipt");
                }
                else
                {
                    // log the messages
                    if (result.MessageList.Any())
                    {
                        op.AddMessage(result.MessageList[0]);
                    }
                }
            }
            return op;
        }
예제 #6
0
        public OperationResult Update(string rowNumber, Row rowToUpdate)
        {
            var result = new OperationResult();
            try
            {

                var row = _ctx.Rows.FindOne(Query.EQ("Number", rowNumber));
                if (row == null)
                {
                    result.Success = false;
                    result.AddMessage(string.Format("Not found", rowNumber));
                    return result;
                }
                row.Cells = rowToUpdate.Cells;
                _ctx.Rows.Save(row);
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.AddMessage(ex.Message);
            }
            return result;
        }