public InitiateOnlineOfferCommandHandler(IMediator mediator, IApplicationRepository applicationRepository, IEventBus eventBus, ILogger <InitiateOnlineOfferCommand> logger, OfferPriceCalculation priceCalculator, IConfigurationService configurationService, IContentService contentService, MessageEventFactory messageEventFactory, IMasterPartyDataService partyDataService, ApplicationDocumentsResolver applicationDocumentsResolver, OfferUtility offerUtility, ArrangementRequestFactory requestFactory, IAuditClient auditClient ) { _applicationRepository = applicationRepository; _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _priceCalculator = priceCalculator; _messageEventFactory = messageEventFactory; _configurationService = configurationService ?? throw new ArgumentNullException(nameof(configurationService)); _contentService = contentService ?? throw new ArgumentNullException(nameof(contentService)); _partyDataService = partyDataService; _documentsResolver = applicationDocumentsResolver ?? throw new ArgumentNullException(nameof(applicationDocumentsResolver)); _offerUtility = offerUtility ?? throw new ArgumentNullException(nameof(offerUtility)); _requestFactory = requestFactory ?? throw new ArgumentNullException(nameof(requestFactory)); _auditClient = auditClient ?? throw new ArgumentNullException(nameof(auditClient)); }
protected void Page_Load(object sender, EventArgs e) { var id = QueryTempOfferRuleId; if (string.IsNullOrEmpty(id)) { var guid = Guid.NewGuid().ToString(); Response.Redirect("/marketing/promo_cart_offer_new.aspx?tempid=" + guid); } if (OfferUtility.OfferRuleConditions[id] == null) { OfferUtility.OfferRuleConditions[id] = new OfferCondition { IsAny = false, IsAll = true, Matched = true }; OfferUtility.OfferActionConditions[id] = new OfferCondition { IsAny = false, IsAll = true, Matched = true }; } StringBuilder sb = new StringBuilder(); StringWriter tw = new StringWriter(sb); HtmlTextWriter hw = new HtmlTextWriter(tw); OfferUtility.RenderCondition(OfferUtility.OfferRuleConditions[id], hw, OfferUtility.OfferRenderType.Cart); ltlConditions.Text = sb.ToString(); StringBuilder sb2 = new StringBuilder(); StringWriter tw2 = new StringWriter(sb2); HtmlTextWriter hw2 = new HtmlTextWriter(tw2); OfferUtility.RenderCondition(OfferUtility.OfferActionConditions[id], hw2, OfferUtility.OfferRenderType.Action); ltlActionConditions.Text = sb2.ToString(); }
public void Test_highest_bidding_offer() { var offerlist = MockOffers.Offers; var highestBid = OfferUtility.GetHighestBid(offerlist); Assert.Equal(200, highestBid); }
public void Test_average_difference() { var estimates = new List <double> { 100, 50, 300, 200, 130 }; var highestBids = new List <double> { 160, 100, 600, 400, 230 }; var difference = OfferUtility.GetAverageDifference(highestBids, estimates); Assert.Equal(142, difference); }
protected override void Up(MigrationBuilder migrationBuilder) { List <string> list = new List <string>(); using (var context = new OfferDBContext()) { var arrRequests = context.ArrangementRequests.Where(a => !string.IsNullOrEmpty(a._ProductSnapshot) && string.IsNullOrEmpty(a._ProductSnapshotHash)).ToList(); foreach (var arr in arrRequests) { ProductSnapshot ps = new ProductSnapshot(); try { ps = JsonConvert.DeserializeObject <ProductSnapshot>(arr._ProductSnapshot); } catch { continue; } string hashCode = OfferUtility.CreateMD5(JsonConvert.SerializeObject(ps)); var sp = context.ProductSnapshots.Where(x => x.Hash.Equals(hashCode)).FirstOrDefault(); if (!list.Any(p => p.Equals(hashCode))) { list.Add(hashCode); migrationBuilder.InsertData( table: "product_snapshots", schema: _schema.Schema, columns: new[] { "Hash", "ProdctSnapshot" }, values: new object[, ] { { hashCode, JsonConvert.SerializeObject(ps) } }); } migrationBuilder.UpdateData( table: "arrangement_requests", schema: _schema.Schema, keyColumns: new string[] { "ApplicationId", "ArrangementRequestId" }, keyValues: new object[] { arr.ApplicationId, arr.ArrangementRequestId }, column: "ProductSnapshotHash", value: hashCode); } } }
public async Task <ProductSnapshotDb> PostProductSnapshot(ProductSnapshot productSnapshot) { string hashCode = OfferUtility.CreateMD5(JsonConvert.SerializeObject(productSnapshot)); var product = await _context.ProductSnapshots.Where(p => p.Hash.Equals(hashCode)).FirstOrDefaultAsync(); if (product != null) { return(product); } ProductSnapshotDb productSnapshotDb = new ProductSnapshotDb { Hash = hashCode, ProductSnapshot = productSnapshot }; ProductSnapshotDb _savedRequest = _context.ProductSnapshots.Add(productSnapshotDb).Entity; await _context.SaveChangesAsync(); return(_savedRequest); }
public async Task <IActionResult> AllAuctions(DateTime?date = null) { var stapleVM = new StapleViewModel(); var highestBidList = new List <double>(); var estimateList = new List <double>(); var auctionItems = await _auctionFacade.GetAllAuctionsAsync(); if (date.HasValue) { auctionItems = auctionItems.Where(a => a.StartDate.Month == date.Value.Month).ToArray(); } if (auctionItems.Length == 0) { stapleVM.WinningBidAvg = 0; stapleVM.EstimateAvg = 0; stapleVM.Difference = 0; return(PartialView("_AuctionList", stapleVM)); } foreach (var auction in auctionItems) { auction.OfferList.AddRange(await _auctionFacade.GetAllOffersAsync((int)auction.Id)); if (auction.OfferList.Count > 0) { estimateList.Add((double)auction.Estimate); highestBidList.Add(OfferUtility.GetHighestBid(auction.OfferList)); } } stapleVM.WinningBidAvg = highestBidList.Average(); stapleVM.EstimateAvg = estimateList.Average(); stapleVM.Difference = OfferUtility.GetAverageDifference(highestBidList, estimateList); return(PartialView("_AuctionList", stapleVM)); }
private void LoadCartOfferInfo() { var rule = OfferService.GetOfferRuleById(QueryOfferRuleId); if (rule == null) { Response.Redirect("/marketing/promo_cart_offer_default.aspx?" + QueryKey.MSG_TYPE + "=" + (int)MessageType.OfferNotFound); } ltlTitle.Text = string.Format("Offer '{0}' (ID: {1})", rule.Name, rule.Id); txtRuleName.Text = rule.Name; txtRuleAlias.Text = rule.Alias; if (IsFireFoxBrowser) { ftbDesc.Visible = false; txtDescription.Text = rule.HtmlMessage; ftbLongDesc.Visible = false; txtLongDesc.Text = rule.LongDescription; } else { txtDescription.Visible = false; ftbDesc.Text = rule.HtmlMessage; txtLongDesc.Visible = false; ftbLongDesc.Text = rule.LongDescription; } if (IsFireFoxBrowser) { ftbDesc.Visible = false; txtDescription.Text = rule.HtmlMessage; } else { txtDescription.Visible = false; ftbDesc.Text = rule.HtmlMessage; } if (rule.IsActive) { rblStatus.SelectedIndex = 0; } else { rblStatus.SelectedIndex = 1; } txtDateFrom.Text = rule.StartDate.HasValue ? rule.StartDate.Value.ToString(AppConstant.DATE_FORM1) : string.Empty; txtDateTo.Text = rule.EndDate.HasValue ? rule.EndDate.Value.ToString(AppConstant.DATE_FORM1) : string.Empty; txtPromoCode.Text = rule.PromoCode; txtTestPromoCode.Text = rule.PromoCode; txtUsesPerCust.Text = rule.UsesPerCustomer.ToString(); cbOfferedItemIncluded.Checked = rule.OfferedItemIncluded; txtPriority.Text = rule.Priority.ToString(); chkPointSpendable.Checked = rule.PointSpendable; cbUseInitialPrice.Checked = rule.UseInitialPrice; cbNewCustomerOnly.Checked = rule.NewCustomerOnly; var foundOfferType = ddlOfferTypes.Items.FindByValue(rule.OfferTypeId.ToString()); if (foundOfferType != null) { foundOfferType.Selected = true; } StringBuilder sb = new StringBuilder(); StringWriter tw = new StringWriter(sb); HtmlTextWriter hw = new HtmlTextWriter(tw); OfferUtility.OfferRuleConditions[rule.Id] = rule.Condition; if (rule.Condition != null) { OfferUtility.RenderCondition(rule.Condition, hw, OfferUtility.OfferRenderType.Cart); } else { OfferUtility.OfferRuleConditions[rule.Id] = new OfferCondition { IsAny = false, IsAll = true, Matched = true }; OfferUtility.RenderCondition(OfferUtility.OfferRuleConditions[rule.Id], hw, OfferUtility.OfferRenderType.Cart); } ltlConditions.Text = sb.ToString(); ddlAction.Items.FindByValue(rule.Action.OfferActionAttributeId.ToString()).Selected = true; if (rule.Action.DiscountAmount.HasValue) { txtDiscountAmount.Text = rule.Action.DiscountAmount.Value.ToString(); } else { txtDiscountAmount.Text = string.Empty; } if (rule.Action.OptionOperator != null) { ddlOptionOperator.Items.FindByValue(rule.Action.OptionOperatorId.ToString()).Selected = true; txtOption.Text = rule.Action.OptionOperand; } if (rule.ProceedForNext) { rblProceed.SelectedIndex = 1; } else { rblProceed.SelectedIndex = 0; } if (rule.Action.FreeProductItself.HasValue || rule.Action.FreeProductId.HasValue) { if (rule.Action.FreeProductItself.HasValue && rule.Action.FreeProductItself.Value) { rbFreeItself.Checked = true; } else { rbFreeItem.Checked = true; txtFreeProductId.Text = rule.Action.FreeProductId.Value.ToString(); txtFreeProductPriceId.Text = rule.Action.FreeProductPriceId.Value.ToString(); txtFreeQuantity.Text = rule.Action.FreeProductQty.Value.ToString(); } } txtXValue.Text = rule.Action.XValue.Value.ToString(); txtYValue.Text = rule.Action.YValue.Value.ToString(); if (rule.Action.DiscountQtyStep.HasValue) { txtDiscountQtyStep.Text = rule.Action.DiscountQtyStep.Value.ToString(); } if (rule.Action.MinimumAmount.HasValue) { txtMinimumAmount.Text = rule.Action.MinimumAmount.Value.ToString(); } txtRewardPoint.Text = rule.Action.RewardPoint.ToString(); StringBuilder sb2 = new StringBuilder(); StringWriter tw2 = new StringWriter(sb2); HtmlTextWriter hw2 = new HtmlTextWriter(tw2); OfferUtility.OfferActionConditions[rule.Id] = rule.Action.Condition; if (rule.Action.Condition != null) { OfferUtility.RenderCondition(rule.Action.Condition, hw2, OfferUtility.OfferRenderType.Action); } else { OfferUtility.OfferActionConditions[rule.Id] = new OfferCondition { IsAny = false, IsAll = true, Matched = true }; OfferUtility.RenderCondition(OfferUtility.OfferActionConditions[rule.Id], hw2, OfferUtility.OfferRenderType.Action); } ltlActionCondition.Text = sb2.ToString(); txtUrlKey.Text = rule.UrlRewrite; txtShortDescription.Text = rule.ShortDescription; ltlSmallImage.Text = string.Format("<img src='/get_image_handler.aspx?" + QueryKey.TYPE + "=" + ImageHandlerType.OFFER + "&img={0}'/><br />", rule.SmallImage); //ftbLongDesc.Text = rule.LongDescription; ltlLargeImage.Text = string.Format("<img src='/get_image_handler.aspx?" + QueryKey.TYPE + "=" + ImageHandlerType.OFFER + "&img={0}'/><br />", rule.LargeImage); chkShowOnOfferPage.Checked = rule.ShowInOfferPage; chkDisplayOnHeaderStrip.Checked = rule.DisplayOnHeaderStrip; txtViewOfferURL.Text = rule.OfferUrl; cbShowCountDownTimer.Checked = rule.ShowCountDown; cbDisplayOnProductPage.Checked = rule.DisplayOnProductPage; cbDisableOfferLabel.Checked = rule.DisableOfferLabel; txtOfferLabel.Text = rule.OfferLabel; if (rule.RelatedBrands != string.Empty) { ddlRelatedTypes.Items.FindByValue("brands").Selected = true; txtRelatedItems.Text = rule.RelatedBrands; } else if (rule.RelatedProducts != string.Empty) { ddlRelatedTypes.Items.FindByValue("products").Selected = true; txtRelatedItems.Text = rule.RelatedProducts; } else if (rule.RelatedCategory != string.Empty) { ddlRelatedTypes.Items.FindByValue("category").Selected = true; txtRelatedItems.Text = rule.RelatedCategory; } LoadProductsForRelatedProductSelector(); }
private void LoadCatalogInfo() { var rule = OfferService.GetOfferRuleById(QueryOfferRuleId); if (rule == null) { Response.Redirect("/marketing/promo_catalog_offer_default.aspx?" + QueryKey.MSG_TYPE + "=" + (int)MessageType.OfferNotFound); } ltlTitle.Text = string.Format("Offer '{0}' (ID: {1})", rule.Name, rule.Id); txtRuleName.Text = rule.Name; txtRuleAlias.Text = rule.Alias; if (rule.IsActive) { rblStatus.SelectedIndex = 0; } else { rblStatus.SelectedIndex = 1; } txtDateFrom.Text = rule.StartDate.HasValue ? rule.StartDate.Value.ToString(AppConstant.DATE_FORM1) : string.Empty; txtDateTo.Text = rule.EndDate.HasValue ? rule.EndDate.Value.ToString(AppConstant.DATE_FORM1) : string.Empty; txtPriority.Text = rule.Priority.ToString(); chkPointSpendable.Checked = rule.PointSpendable; var foundOfferType = ddlOfferTypes.Items.FindByValue(rule.OfferTypeId.ToString()); if (foundOfferType != null) { foundOfferType.Selected = true; } #region Conditions StringBuilder sb = new StringBuilder(); StringWriter tw = new StringWriter(sb); HtmlTextWriter hw = new HtmlTextWriter(tw); OfferUtility.OfferRuleConditions[rule.Id] = rule.Condition; if (rule.Condition != null) { OfferUtility.RenderCondition(rule.Condition, hw, OfferUtility.OfferRenderType.Catalog); } else { OfferUtility.OfferRuleConditions[rule.Id] = new OfferCondition { IsAny = false, IsAll = true, Matched = true }; OfferUtility.RenderCondition(OfferUtility.OfferRuleConditions[rule.Id], hw, OfferUtility.OfferRenderType.Catalog); } ltlConditions.Text = sb.ToString(); #endregion ddlAction.Items.FindByValue(rule.Action.OfferActionAttributeId.ToString()).Selected = true; txtDiscountAmount.Text = rule.Action.DiscountAmount.Value.ToString(); if (rule.Action.OptionOperator != null) { ddlOptionOperator.Items.FindByValue(rule.Action.OptionOperatorId.ToString()).Selected = true; txtOption.Text = rule.Action.OptionOperand; } rblProceed.SelectedIndex = rule.ProceedForNext ? 1 : 0; chkShowOfferTag.Checked = rule.ShowOfferTag; chkShowRRP.Checked = rule.ShowRRP; txtUrlKey.Text = rule.UrlRewrite; txtShortDescription.Text = rule.ShortDescription; ltlSmallImage.Text = string.Format("<img src='/get_image_handler.aspx?" + QueryKey.TYPE + "=" + ImageHandlerType.OFFER + "&img={0}'/><br />", rule.SmallImage); ftbLongDesc.Text = rule.LongDescription; ltlLargeImage.Text = string.Format("<img src='/get_image_handler.aspx?" + QueryKey.TYPE + "=" + ImageHandlerType.OFFER + "&img={0}'/><br />", rule.LargeImage); chkShowOnOfferPage.Checked = rule.ShowInOfferPage; chkDisplayOnHeaderStrip.Checked = rule.DisplayOnHeaderStrip; txtViewOfferURL.Text = rule.OfferUrl; cbShowCountDownTimer.Checked = rule.ShowCountDown; cbDisplayOnProductPage.Checked = rule.DisplayOnProductPage; cbDisableOfferLabel.Checked = rule.DisableOfferLabel; txtOfferLabel.Text = rule.OfferLabel; if (rule.RelatedBrands != string.Empty) { ddlRelatedTypes.Items.FindByValue("brands").Selected = true; txtRelatedItems.Text = rule.RelatedBrands; } else if (rule.RelatedProducts != string.Empty) { ddlRelatedTypes.Items.FindByValue("products").Selected = true; txtRelatedItems.Text = rule.RelatedProducts; } else if (rule.RelatedCategory != string.Empty) { ddlRelatedTypes.Items.FindByValue("category").Selected = true; txtRelatedItems.Text = rule.RelatedCategory; } LoadProductsForRelatedProductSelector(); }