public virtual IActionResult TierPriceCreatePopup(TierPriceModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) { return(AccessDeniedView()); } //try to get a category with the specified id var category = _categoryService.GetCategoryById(model.CategoryId) ?? throw new ArgumentException("No category found with the specified id"); if (ModelState.IsValid) { //fill entity from model var tierPrice = model.ToEntity <TierPrice>(); tierPrice.ProductId = 1; tierPrice.CategoryId = category.Id; tierPrice.CustomerRoleId = model.CustomerRoleId > 0 ? model.CustomerRoleId : (int?)null; _tierpriceService.InsertTierPrice(tierPrice); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = _tirePriceModelFactory.PrepareTierPriceModel(model, category, null, true); //if we got this far, something failed, redisplay form return(View(model)); }
/// <summary> /// Prepare tier price model /// </summary> /// <param name="model">Tier price model</param> /// <param name="product">Product</param> /// <param name="tierPrice">Tier price</param> /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param> /// <returns>Tier price model</returns> public virtual TierPriceModel PrepareTierPriceModel(TierPriceModel model, Category category, TierPrice tierPrice, bool excludeProperties = false) { if (category == null) { throw new ArgumentNullException(nameof(category)); } if (tierPrice != null) { //fill in model values from the entity if (model == null) { model = tierPrice.ToModel <TierPriceModel>(); } } //prepare available stores _baseAdminModelFactory.PrepareStores(model.AvailableStores); //prepare available customer roles _baseAdminModelFactory.PrepareCustomerRoles(model.AvailableCustomerRoles); return(model); }
public override TierPriceModel PrepareTierPriceModel(TierPriceModel model, Product product, TierPrice tierPrice, bool excludeProperties = false) { if (product == null) { throw new ArgumentNullException(nameof(product)); } if (tierPrice != null) { //fill in model values from the entity if (model == null) { model = tierPrice.ToModel <TierPriceModel>(); } } //prepare available stores _baseAdminModelFactory.PrepareStores(model.AvailableStores); //prepare available customer roles IEnumerable <CustomerRole> availableCustomerRoles = _customerService.GetAllCustomerRoles() .Where(x => x.SystemName.Contains(B2BRole.RoleSuffix)); foreach (var customerRole in availableCustomerRoles) { model.AvailableCustomerRoles.Add(new SelectListItem { Value = customerRole.Id.ToString(), Text = customerRole.Name }); } return(model); }
/// <summary> /// Adds the new tier price. /// </summary> /// <param name="tierPricingModel">The tier pricing model.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">tierPricingModel</exception> public virtual TierPricesComponent AddNewTierPrice( TierPriceModel tierPricingModel) { if (tierPricingModel == null) { throw new ArgumentNullException(nameof(tierPricingModel)); } var cachedWindowHandle = WrappedDriver.CurrentWindowHandle; var cachedWindowHandles = WrappedDriver.WindowHandles; AddNewTierPriceElement.Click(); WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .Until(d => d.WindowHandles.Count > cachedWindowHandles.Count); // Switch to new window. var newHandle = WrappedDriver.WindowHandles .Except(cachedWindowHandles) .First(); WrappedDriver.SwitchTo().Frame(newHandle); // Load the StartDate/EndDate components. StartDateComponent.Load(); EndDateComponent.Load(); // Enter values. QuantityElement.SetValue(tierPricingModel.Quantity); PriceElement.SetValue(tierPricingModel.Price); StoreElement.SelectByText(tierPricingModel.Store); CustomerRoleElement.SelectByText(tierPricingModel.CustomerRole); StartDateComponent.SetValue(tierPricingModel.StartDate); EndDateComponent.SetValue(tierPricingModel.EndDate); // Save. var saveEl = SaveElement; // Cache this to avoid extra lookups. saveEl.Click(); WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .Until(d => saveEl.IsStale()); // Switch back to the original handle. WrappedDriver.SwitchTo().Frame(cachedWindowHandle); return(this); }
/// <summary> /// Gets the listed tier prices. /// </summary> /// <returns></returns> public virtual IEnumerable <TierPriceModel> GetListedTierPrices() { var enCulture = CultureInfo.GetCultureInfo("en-US"); var totalRows = TierPricesGrid.GetNumberOfRows(); for (var rowIndex = 0; rowIndex < totalRows; rowIndex++) { var storeCell = TierPricesGrid.GetCell(rowIndex, 0); var customerRoleCell = TierPricesGrid.GetCell(rowIndex, 1); var quantityCell = TierPricesGrid.GetCell(rowIndex, 2); var priceCell = TierPricesGrid.GetCell(rowIndex, 3); var startDateCell = TierPricesGrid.GetCell(rowIndex, 4); var endDateCell = TierPricesGrid.GetCell(rowIndex, 5); var model = new TierPriceModel { Store = storeCell.TextHelper().InnerText, CustomerRole = customerRoleCell.TextHelper().InnerText, Quantity = quantityCell.TextHelper().ExtractInteger(), Price = priceCell.TextHelper().ExtractPrice() }; var startDateTxt = startDateCell.TextHelper().InnerText; var endDateTxt = endDateCell.TextHelper().InnerText; if (!String.IsNullOrEmpty(startDateTxt)) { var startDate = DateTime.ParseExact( startDateTxt, "M/d/yyyy h/mm/ss tt", enCulture); model.StartDate = startDate; } if (!String.IsNullOrEmpty(endDateTxt)) { var endDate = DateTime.ParseExact( endDateTxt, "M/d/yyyy h/mm/ss tt", enCulture); model.EndDate = endDate; } yield return(model); } }
public virtual IActionResult TierPriceEditPopup(TierPriceModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts)) { return(AccessDeniedView()); } //try to get a tier price with the specified id var tierPrice = _productService.GetTierPriceById(model.Id); if (tierPrice == null) { return(RedirectToAction("List", "Product")); } //try to get a product with the specified id var product = _productService.GetProductById(tierPrice.ProductId) ?? throw new ArgumentException("No product found with the specified id"); //a vendor should have access only to his products if (_workContext.CurrentVendor != null && product.VendorId != _workContext.CurrentVendor.Id) { return(RedirectToAction("List", "Product")); } if (ModelState.IsValid) { //fill entity from model tierPrice = model.ToEntity(tierPrice); tierPrice.CustomerRoleId = model.CustomerRoleId > 0 ? model.CustomerRoleId : (int?)null; _productService.UpdateTierPrice(tierPrice); ViewBag.RefreshPage = true; return(View(model)); } //prepare model model = _productModelFactory.PrepareTierPriceModel(model, product, tierPrice, true); //if we got this far, something failed, redisplay form return(View(model)); }