public void BuyStuff() { IDatabase database = CreateDatabase(); IShoppingService shoppingService = new ShoppingService(database); IOrderProcessor orderProcessor = new OrderProcessor(database); IActionHandler actionHandler = new ActionHandler(); User user = shoppingService.SignIn("*****@*****.**", "secret"); Cart cart = shoppingService.GetCart("*****@*****.**"); Product ball = shoppingService.GetProduct("Ball"); cart.AddProduct(ball); cart.AddProduct(ball); cart.AddProduct(shoppingService.GetProduct("Monitor")); var completedOrder = actionHandler .Handle(() => orderProcessor.CompleteOrder(cart)); var order = completedOrder.Item; if (completedOrder.IsValid) { Console.WriteLine($"Order was completed. You've spent {order.TotalPrice} PLN."); return; } Console.WriteLine(completedOrder.ErrorMessage); }
private void LoadControlData(bool forceReload = false) { var paymentOptions = PaymentOptionInfoProvider.GetPaymentOptions(ShoppingCart.ShoppingCartSiteID, true) .Column("PaymentOptionID") .OrderBy("PaymentOptionDisplayName"); if (ShoppingCart.ShippingOption == null || !ShoppingCart.IsShippingNeeded) { paymentOptions.WhereTrue("PaymentOptionAllowIfNoShipping"); } var paymentIds = paymentOptions.GetListResult <int>(); // If there is only one payment method set it if (paymentIds.Count == 1) { var paymentOptionID = paymentIds.First(); ShoppingService.SetPaymentOption(paymentOptionID); drpPayment.SelectedID = paymentOptionID; // Make sure that in-memory changes persist (unsaved address, etc.) Service.Resolve <ICurrentShoppingCartService>().SetCurrentShoppingCart(ShoppingCart); } drpPayment.DisplayOnlyAllowedIfNoShipping = (ShoppingCart.ShoppingCartShippingOptionID <= 0) || !ShoppingCart.IsShippingNeeded; if (!RequestHelper.IsPostBack() || forceReload || ((ShoppingCart.ShoppingCartPaymentOptionID != 0) && !PaymentOptionInfoProvider.IsPaymentOptionApplicable(ShoppingCart, ShoppingCart.PaymentOption))) { // Reset selector on shipping changed event if selected payment is not allowed for current shipping (zero shipping id is Please select state). drpPayment.Reload(); drpPayment.SelectedID = ShoppingService.GetPaymentOption(); } }
public ActionResult CartIcon() { int cartItemNumber = 0; if (FormsAuth.UserManager.User != null) // user has loged in already { ShoppingService service = new ShoppingService(); cartItemNumber = service.getCartItemNumber(UserManager.User.Id); } else // get from cookies { HttpCookie reqIDListCookies = Request.Cookies["ProductDetailIDlist"]; if (reqIDListCookies != null) { string dataAsString = reqIDListCookies.Value; if (!dataAsString.Equals(string.Empty)) { List <int> listdata = new List <int>(); listdata = dataAsString.Split(',').Select(x => Convert.ToInt32(x)).ToList(); cartItemNumber = listdata.Count(); } } } ViewBag.cartItemNumber = cartItemNumber; return(PartialView()); }
static void RunSample(ShoppingService service) { // Build the request. string query = "Camera"; CommandLine.RequestUserInput("Product to search for", ref query); CommandLine.WriteLine(); CommandLine.WriteAction("Executing request ..."); var request = service.Products.List("public"); request.Country = "us"; request.Q = query; // Parse the response. long startIndex = 1; do { request.StartIndex = startIndex; Products response = request.Fetch(); if (response.CurrentItemCount == 0) { break; // Nothing more to list. } // Show the items. foreach (Product item in response.Items) { CommandLine.WriteResult((startIndex++) + ". Result", item.ProductValue.Title.TrimByLength(60)); } } while (CommandLine.RequestUserChoice("Do you want to see more items?")); }
static void Main(string[] args) { Console.WriteLine("Enter Customer Id"); int customerId = Int32.Parse(Console.ReadLine()); while (customerId.ToString() == null) { Console.WriteLine("Enter Customer Id"); customerId = Int32.Parse(Console.ReadLine()); } var stockService = new StockService(new StockRepository()); var discountService = new DiscountService(new DiscountRepository()); var paymentGateway = new PaymentRepository(new PaymentGatewayClient(new System.Net.Http.HttpClient())); List <string> items = new List <string>() { "Breads", "Milk", "Biscuits", "DryFruits" }; ShoppingService shopping = new ShoppingService(customerId, stockService, discountService, paymentGateway, new Logger()); var count = shopping.GetItemsToBuy(items); var resutl = count > 0 ? $"Shopping done for {count} products" : $"Shopping done for {count} products"; Console.WriteLine(resutl); Console.ReadLine(); }
static void Main(string[] args) { ShoppingService shoppingService = new ShoppingService(); //Product apple = new Product { Id = 1, Name = "apple", Price = 1m }; //ShoppingCart cart = new ShoppingCart(); //cart.ShoppingItems.Add(new ShoppingItem { ProductId = 1, Count = 1 }); //Receipt receipt = new Receipt(); //receipt.ShoppingItems.AddRange(cart.ShoppingItems); //MockShoppingCartRepository mockShoppingCartRepository = new MockShoppingCartRepository(); //var shoppingCart1 = mockShoppingCartRepository.Create(); //var shoppingCart2 = mockShoppingCartRepository.Create(); var allproduct = shoppingService.GetAllProducts(); var cart = shoppingService.CreateShoppingCart(); shoppingService.BuyProduct(cart.Id, 1, 2); Console.ReadLine(); }
public void SetUp() { products = new List <ProductsDataModel>(); items = new List <string>(); products.Add(new ProductsDataModel() { Name = "Biscuits", Price = 100, }); products.Add(new ProductsDataModel() { Name = "Milk", Price = 300, }); items.Add("Bread"); items.Add("Milk"); items.Add("cheese"); items.Add("Butter"); items.Add("Biscuits"); _mockdiscountService = new Mock <IDiscountService>(); _mockPaymentRepo = new Mock <IPaymentRepository>(); _mockStockService = new Mock <IStockService>(); _mocklogger = new Mock <ILogger>(); _shoppingService = new ShoppingService(anycustomerId, _mockStockService.Object, _mockdiscountService.Object, _mockPaymentRepo.Object, _mocklogger.Object); _mockStockService.Setup(x => x.GetStockStatus(It.IsAny <List <string> >())).Returns(products); }
public ActionResult CSVExport([DataSourceRequest] DataSourceRequest request) { Expression <Func <Order, bool> > predicate = x => true // && x.OrderStatus != OrderStatus.New // && x.OrderStatus != OrderStatus.Canceled // && x.OrderStatus != OrderStatus.Rejected ; if (request.Filters != null) { predicate = GetPredicate(predicate, request.Filters); } var items = _db.Orders.Where(predicate).Select(x => new PaymentReportItemModel() { ID = x.ID, ShopID = x.ShopID, IsPaidUp = x.IsPaidUp, OrderID = x.ID, Date = x.CreateOn, PaymentMethod = x.PaymentMethod, Total = x.Total }).ToList(); foreach (var item in items) { item.Total = item.Cash + item.Card; item.TotalStr = ShoppingService.FormatPrice(item.Total); item.PayedTo = item.Card > 0 ? PayedToType.ToAdmin : PayedToType.ToShop; item.PayedToStr = RP.T("Enums." + item.PayedTo.ToString()).ToString(); item.PaymentMethodStr = RP.T("Enums." + item.PaymentMethod.ToString()).ToString(); item.DateStr = item.Date.HasValue ? item.Date.Value.ToString("dd/MM HH:mm") : ""; } // var items = _db.AbstractPages.Where(r => r.Visible == true).OrderBy(r => r.Title).ToList(); MemoryStream output = new MemoryStream(); StreamWriter writer = new StreamWriter(output, Encoding.UTF8); writer.Write(RP.M("PaymentReportItemModel", "OrderID") + ","); writer.Write(RP.M("PaymentReportItemModel", "Date") + ","); writer.Write(RP.M("PaymentReportItemModel", "Total") + ","); writer.Write(RP.M("PaymentReportItemModel", "PaymentMethod") + ","); writer.Write(RP.M("PaymentReportItemModel", "PayedTo")); writer.WriteLine(); var csvQuote = "\""; foreach (var item in items) { writer.Write(item.OrderID); writer.Write(",\""); writer.Write(item.DateStr.Replace(csvQuote, csvQuote + csvQuote)); writer.Write("\",\""); writer.Write(item.TotalStr.Replace(csvQuote, csvQuote + csvQuote)); writer.Write("\",\""); writer.Write(item.PaymentMethodStr.Replace(csvQuote, csvQuote + csvQuote)); writer.Write("\",\""); writer.Write(item.PayedToStr.Replace(csvQuote, csvQuote + csvQuote)); writer.Write("\""); writer.WriteLine(); } writer.Flush(); output.Position = 0; Encoding heb = Encoding.GetEncoding("windows-1255"); return(File(heb.GetBytes(new StreamReader(output).ReadToEnd()), "text/csv", "PaymentReport_" + (DateTime.Now.ToString("dd/MM HH:mm")) + ".csv")); }
public CustomerController(CustomerService customerService, ShoppingService shoppingService, UserManager <AppUser> userManager) { this.customerService = customerService; this.shoppingService = shoppingService; this.userManager = userManager; }
public ActionResult _RemoveProductFromFavorite(int productShopID) { if (LS.isLogined()) { ShoppingService.RemoveProductFromFavorite(productShopID, LS.CurrentUser.ID); } return(Content(string.Empty)); }
public void TearDown() { _discountService = null; _paymentGateWay = null; _stockRepository = null; _logger = null; _shoppingService = null; }
public void SetUp() { _discountService = new Mock <IDiscountService>(); _paymentGateWay = new Mock <IPaymentGateway>(); _stockRepository = new Mock <IStockRepository>(); _logger = new Mock <ILogger>(); shoppingService = new ShoppingService(anycustomerId, _stockRepository.Object, _discountService.Object, _paymentGateWay.Object, _logger.Object); }
// GET: Shopping public ActionResult Index() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new ShoppingService(userId); var model = service.GetShopping(); return(View(model)); }
public ActionResult _GetShopInfo(int shopID) { var culture = new System.Globalization.CultureInfo("he-IL"); var data = LS.GetFirst <Shop>(x => x.ID == shopID); UserActivityService.InsertShopOpen(LS.CurrentUser.ID, shopID , Request.RawUrl, Request.UrlReferrer != null ? Request.UrlReferrer.OriginalString : null , LS.GetUser_IP(Request)); data.ShopCommentModels = ShoppingService.GetShopComments(shopID); //data.ShopType = LS.Get<ShopType>() // .FirstOrDefault(x => data.ShopTypeIDs!= null && data.ShopTypeIDs.Contains(x.ID.ToString() ) ); var curdate = DateTime.Now.Date; var lastdate = curdate.AddDays(7); data.WorkTimes = LS.CurrentEntityContext.ShopWorkTimes.Where(x => x.ShopID == shopID && x.Active && (!x.IsSpecial || (x.Date >= curdate && x.Date <= lastdate))) .OrderBy(x => x.IsSpecial).ThenBy(x => x.Day).ThenBy(x => x.Date) .Select(x => new ShipTimeModel() { Date = x.Date, Day = x.Day, TimeFromInt = x.TimeFrom, TimeToInt = x.TimeTo, IsSpecial = x.IsSpecial, }).ToList(); foreach (var t in data.WorkTimes) { t.DayStr = culture.DateTimeFormat.GetDayName(t.Day); t.TimeFromeStr = TimeSpan.FromMinutes(t.TimeFromInt).ToString("hh':'mm"); //ntToTime(t.TimeFromInt); t.TimeToStr = TimeSpan.FromMinutes(t.TimeToInt).ToString("hh':'mm"); t.DateStr = t.Date.ToString("dd/MM"); } data.ShipTimes = _db.ShopShipTimes.Where(x => x.ShopID == shopID && x.Active && !x.IsSpecial) .Select(x => new ShipTimeModel() { Date = x.Date, Day = x.Day, TimeFromInt = x.TimeFrom, TimeToInt = x.TimeTo, }).ToList(); foreach (var t in data.ShipTimes) { t.DayStr = t.DayStr = culture.DateTimeFormat.GetDayName(t.Day); t.TimeFromeStr = TimeSpan.FromMinutes(t.TimeFromInt).ToString("hh':'mm"); t.TimeToStr = TimeSpan.FromMinutes(t.TimeToInt).ToString("hh':'mm"); } if (!string.IsNullOrEmpty(data.Theme)) { this.HttpContext.Items["ShopTheme"] = data.Theme; } return(PartialView("_ShopInfoPopup", data)); }
private object DummyEcommerceMethod2() { SKUInfo sku = null; IOrderRepository orderRepository = null; int orderId = 0; //DocSection:DisplayCatalogDiscounts // Initializes the needed services ShoppingService shoppingService = new ShoppingService(); PricingService pricingService = new PricingService(); // Gets the current shopping cart ShoppingCart shoppingCart = shoppingService.GetCurrentShoppingCart(); // Calculates prices for the specified product ProductPrice price = pricingService.CalculatePrice(sku, shoppingCart, true, false); // Gets the catalog discount decimal catalogDiscount = price.Discount; //EndDocSection:DisplayCatalogDiscounts //DocSection:DisplayOrderList // Gets the current customer Customer currentCustomer = shoppingService.GetCurrentCustomer(); // If the customer does not exist, returns error 404 if (currentCustomer == null) { return(HttpNotFound()); } // Creates a view model representing a collection of the customer's orders OrdersViewModel model = new OrdersViewModel() { Orders = orderRepository.GetByCustomerId(currentCustomer.ID) }; //EndDocSection:DisplayOrderList //DocSection:ReorderExistingOrder // Gets the order based on its ID Order order = orderRepository.GetById(orderId); // Gets the current visitor's shopping cart ShoppingCart cart = shoppingService.GetCurrentShoppingCart(); // Loops through the items in the order and adds them to the shopping cart foreach (OrderItem item in order.OrderItems) { cart.AddItem(item.SKUID, item.Units); } // Saves the shopping cart cart.Save(); //EndDocSection:ReorderExistingOrder return(null); }
public string _AddNoteForProduct(int productID, string text) { if (!string.IsNullOrEmpty(text)) { var data = ShoppingService.AddOrEditNoteForProduct(productID, text); return(data.Text); } return(string.Empty); }
public void TearDown() { _mockdiscountService = null; _mockPaymentRepo = null; _mockStockService = null; _mocklogger = null; _shoppingService = null; products.Clear(); items.Clear(); }
/// <summary> /// Saves the wizard step data. /// </summary> protected override void SaveStepData(object sender, StepEventArgs e) { base.SaveStepData(sender, e); // Clear shipping option if cart does not need shipping if (!ShoppingCart.IsShippingNeeded) { ShoppingService.SetShippingOption(0); } }
public async Task GetOrderedProductListAysnc_Scenario2_ShouldReturn_LeastTrolleyCost(int qtyA, int qtyB, decimal expectedOutput) { var request = new CustomerTrolleyRequest(); request.Products = new List <TrolleyProduct> { new TrolleyProduct { Name = "A", Price = 10 }, new TrolleyProduct { Name = "B", Price = 10 } }; request.Specials = new List <Special> { new Special { Quantities = new List <ProductQuantities> { new ProductQuantities { Name = "A", Quantity = qtyA }, new ProductQuantities { Name = "B", Quantity = 0 } }, Total = 10 }, new Special { Quantities = new List <ProductQuantities> { new ProductQuantities { Name = "A", Quantity = 0 }, new ProductQuantities { Name = "B", Quantity = qtyB } }, Total = 15 } }; request.Quantities = new List <ProductQuantities> { new ProductQuantities { Name = "A", Quantity = qtyA }, new ProductQuantities { Name = "B", Quantity = qtyB } }; var result = await ShoppingService.GetLowestTrolleyTotalAsync(request); Assert.That(result == expectedOutput); }
static void Main(string[] args) { //demo git change ShoppingService shoppingService = new ShoppingService(); var allProducts = shoppingService.GetAllProducts(); allProducts.ForEach(i => Console.WriteLine(i)); var cart = shoppingService.CreateShoppingCart(); string input = ""; bool canExit = false; do { Console.WriteLine("please input product id or command..."); input = Console.ReadLine().ToLower(); switch (input) { case "exit": case "quit": canExit = true; break; case "checkout": // call check out logic canExit = true; break; default: break; } int productId = 0; if (int.TryParse(input, out productId)) { var buy = shoppingService.BuyProduct(cart.Id, productId); Console.WriteLine(buy.ToString()); } else { Console.WriteLine("please input right product id"); } } while (!canExit); cart.ShoppingItems.ForEach(i => Console.WriteLine($"ProductId={i.ProductId}, Count={i.Count}, TotalPrice={i.TotalPrice}")); Console.WriteLine("thank you, bye"); Console.ReadLine(); }
public ActionResult <decimal> Get([FromRoute] Guid id) { var cart = shoppingCartRepository.Find(id); if (cart == null) { return(NotFound()); } var service = new ShoppingService(); return(service.CalculatePrice(cart)); }
public void Add_Item_To_ShoppingList() { // Arrange var item = new Item("item"); var shoppingService = new ShoppingService(_sqliteConnection); // Act shoppingService.AddItem(item); // Assert Assert.Contains <Item>(shoppingService.Items, x => x == item); }
public void FixtureSetUp() { Service.Use <IActivityLogService, ActivityLogServiceFake>(); mEcommerceActivitiesLogger = new EcommerceActivitiesLoggerFake(); SetUpSite(); SetUpOrderStatuses(); SetUpPaymentOptions(); mService = new ShoppingService(mEcommerceActivitiesLogger); }
public void TryAdd_Adds_Item_Like_AddItem_When_Item_Not_Present() { // Arrange var item1 = "item 1"; var shoppingService = new ShoppingService(_sqliteConnection); // Act shoppingService.TryAddItemToShoppingList(new Item(item1)); // Assert Assert.Equal(1, shoppingService.Items.Count); }
public void FixtureSetUp() { ObjectFactory <IActivityLogService> .SetObjectTypeTo <ActivityLogServiceFake>(true); mEcommerceActivitiesLogger = new EcommerceActivitiesLoggerFake(); SetUpSite(); SetUpOrderStatuses(); SetUpPaymentOptions(); mService = new ShoppingService(mEcommerceActivitiesLogger); }
public void Add_Item() { // Arrange var shoppingService = new ShoppingService(_sqliteConnection); var vm = new PastPurchasesViewModel(shoppingService); var item = new BoughtItem("item 1"); // Act vm.Add(item); // Assert Assert.Contains <BoughtItem>(vm.Items, x => x == item); }
public void TestSetUp() { Service.Use <IActivityLogService, ActivityLogServiceFake>(Guid.NewGuid().ToString()); Service.Use <ILocalizationService, LocalizationServiceFake>(Guid.NewGuid().ToString()); OrderInfoProvider.ProviderObject = new OrderInfoProviderWithMailLogging(); SiteContext.CurrentSite = SiteInfo; ShoppingService = new ShoppingService(new EcommerceActivitiesLoggerFake()); // Setting order generates invoice which has a macro in the subject. The macro cannot be resolved and an error is logged. TestsEventLogProvider.FailForErrorEvent = false; }
private void DummyEcommerceMethod3() { //DocSection:DisplayFreeShippingOffers // Initializes the needed services ShoppingService shoppingService = new ShoppingService(); PricingService pricingService = new PricingService(); // Gets the current shopping cart ShoppingCart shoppingCart = shoppingService.GetCurrentShoppingCart(); // Gets the remaining amount for free shipping decimal remainingFreeShipping = pricingService.CalculateRemainingAmountForFreeShipping(shoppingCart); //EndDocSection:DisplayFreeShippingOffers }
public Services(string path) { FileManager = new FileManager(path); BudgetService = new BudgetService(FileManager); CartService = new CartService(FileManager); GoalService = new GoalService(FileManager); HistoryService = new HistoryService(FileManager); PaymentService = new PaymentService(FileManager); SchedulerService = new SchedulerService(FileManager); ShoppingService = new ShoppingService(); StatisticsService = new StatisticsService(FileManager); VerificationService = new VerificationService(); CurrentInfoHolder = new CurrentInfoHolder(); }
public static void Run() { ConsoleColor.Red.WriteLine(nameof(OcpBadExample)); var shoppingService = new ShoppingService(); foreach (var item in GetItems()) { shoppingService.AddItem(item); } var total = shoppingService.GetTotalAmount(); Console.WriteLine($"Total = {total}"); }
public static void Wrong() { ShoppingService shoppingService = new ShoppingService(); shoppingService.AddToCart(1, 2, 3); }
public static void Right() { ShoppingService shoppingService = new ShoppingService(); shoppingService.BeginTransaction(); shoppingService.AddToCart(1, 2, 3); }