public void Run() { int a = 100, b = 500, angle = 90; CalculatorCreator calculatorCreator = new CalculatorCreator(); Calculator calculator = calculatorCreator.CreateCalculator(angle); float result = calculator.Calculate(a, b, angle); Console.WriteLine($"Result: if Angle is {angle} is {result}"); Console.WriteLine("*******"); angle = 0; calculator = calculatorCreator.CreateCalculator(angle); result = calculator.Calculate(a, b, angle); Console.WriteLine($"Result: if Angle is {angle} is {result}"); Console.WriteLine("*******"); angle = 30; calculator = calculatorCreator.CreateCalculator(angle); result = calculator.Calculate(a, b, angle); Console.WriteLine($"Result: if Angle is {angle} is {result}"); Console.WriteLine("*******"); }
public async Task <IActionResult> Create(OrderCustomerViewModel order) { try { if (ModelState.IsValid) { var pricePoint = CalculatorCreator.Create((CalculateType)order.OrderType).Calculate(order.Days); var customer = _uow.customerRepository.List.Where(r => r.Name == order.CustomerName)?.FirstOrDefault(); if (customer == null) { _uow.customerRepository.Save(new RentalProducts.DAL.Models.Customer { Name = order.CustomerName }); var custId = _uow.customerRepository.List.Where(r => r.Name == order.CustomerName)?.FirstOrDefault(); _customer.Id = custId.Id; } else { _customer.Id = customer.Id; } var orderEntity = new RentalProducts.DAL.Models.Order { CustomerId = _customer.Id, ProductId = _product.Id, Price = pricePoint.Price, Days = order.Days, LoyaltyPoint = pricePoint.LoyaltyPoint, Type = order.OrderType }; _uow.orderRepository.Save(orderEntity); EventLogger.WriteLog($"Create {customer.Name}'s Order", _context); return(Redirect("/Orders/Index")); } return(View(order)); } catch (Exception ex) { Logger.WriteLog(ex, _context); return(BadRequest()); } }
public void ClientCode(CalculatorCreator calculator) { decimal price = calculator.CalculatePrice(Model.A, 500); }
public void TestInit() { Creator = new CalculatorCreator(); Calculator = Creator.Create <int[]>(); }
static void Main(string[] args) { Logger.SetLogger(new ConsoleLogger()); CalculatorCreator calculatorCreator = new CalculatorCreator(); Logger.Write("Type: "); string type = Logger.Read(); try { if (type == "int") { var calculator = calculatorCreator.Create <int>(); Logger.Write("First: "); int a = Convert.ToInt32(Logger.Read()); Logger.Write("Sign: "); string sign = Logger.Read(); Logger.Write("Second: "); int b = Convert.ToInt32(Logger.Read()); switch (sign) { case "+": Logger.Write(calculator.Sum(a, b) + "\n"); break; case "-": Logger.Write(calculator.Sub(a, b) + "\n"); break; case "*": Logger.Write(calculator.Mul(a, b) + "\n"); break; case "/": Logger.Write(calculator.Div(a, b) + "\n"); break; } } else if (type == "int array") { var calculator = calculatorCreator.Create <int[]>(); Logger.Write("First: "); string[] line = Logger.Read().Split(); int[] a = new int[line.Length]; for (var i = 0; i < line.Length; i++) { a[i] = Convert.ToInt32(line[i]); } Logger.Write("Sign: "); string sign = Logger.Read(); Logger.Write("Second: "); line = Logger.Read().Split(); int[] b = new int[line.Length]; for (var i = 0; i < line.Length; i++) { b[i] = Convert.ToInt32(line[i]); } switch (sign) { case "+": foreach (var element in calculator.Sum(a, b)) { Logger.Write(element + "\n"); } break; case "-": foreach (var element in calculator.Sub(a, b)) { Logger.Write(element + "\n"); } break; case "*": foreach (var element in calculator.Mul(a, b)) { Logger.Write(element + "\n"); } break; case "/": foreach (var element in calculator.Div(a, b)) { Logger.Write(element + "\n"); } break; } } else { Logger.Write("Invalid type\n"); } } catch (DivideByZeroException e) { Logger.Write(e.Message + " from " + e.InnerException.Source + "\n"); } catch (NullReferenceException e) { Logger.Write(e.Message + " from " + e.InnerException.Source + "\n"); } catch (IndexOutOfRangeException e) { Logger.Write(e.Message + " from " + e.InnerException.Source + "\n"); } catch (InvalidCastException e) { Logger.Write(e.Message + " from " + e.InnerException.Source + "\n"); } Logger.Read(); }