public ActionResult EditCouponType(CouponType couponType) { couponTypes.Update(couponType); couponTypes.Commit(); return(RedirectToAction("CouponTypeList")); }
public Coupon(Guid couponID, string couponCode, CouponType couponType, int?discountAmount) { CouponID = couponID; CouponCode = couponCode; CouponType = couponType; DiscountAmount = discountAmount; }
public ActionResult Create(CouponTypeViewModel model) { //if (model.FileUpload.Images.Count() <= 0) //{ // ModelState.AddModelError("Image", "上传图片"); //} if (string.IsNullOrWhiteSpace(model.Name)) { ModelState.AddModelError("Name", "填写名称"); } //if (string.IsNullOrWhiteSpace(model.Keyword)) //{ // ModelState.AddModelError("Keyword", "填写关键字"); //} if (ModelState.IsValid) { var type = new CouponType() { Image = model.FileUpload.Images.FirstOrDefault(), Keyword = model.Keyword?.Replace(" ", "") ?? "", Name = model.Name, Sort = model.Sort, ParentID = model.ParentID, Platform = model.Platform, }; couponType.Add(type); return(RedirectToAction("Index", new { pid = model.ParentID, platform = model.Platform })); } Sidebar(); return(View(model)); }
public CouponTemplate( Guid id, Guid?tenantId, Guid?storeId, CouponType couponType, string uniqueName, string displayName, string description, TimeSpan?usableDuration, DateTime?usableBeginTime, DateTime?usableEndTime, decimal conditionAmount, decimal discountAmount, [NotNull] string currency, bool isUnscoped, List <CouponTemplateScope> scopes ) : base(id) { TenantId = tenantId; StoreId = storeId; CouponType = couponType; UniqueName = uniqueName; DisplayName = displayName; Description = description; UsableDuration = usableDuration; UsableBeginTime = usableBeginTime; UsableEndTime = usableEndTime; ConditionAmount = conditionAmount; DiscountAmount = discountAmount; Currency = currency; IsUnscoped = isUnscoped; Scopes = scopes ?? new List <CouponTemplateScope>(); }
public void CalculateDiscount_CouponHasExpired_ThrowCouponExpiredException(CouponType couponType) { var target = new CouponEngine(); Assert.Throws <CouponExpiredException>(() => target.CalculateDiscount(CreateCheckOutDto(), CreateCoupon(couponType: couponType, expiration: DateTime.Now.AddDays(-1)))); }
public CreateCouponCommand(string code, CouponType couponType, long tutorId, decimal value, DateTime expiration) { Code = code; CouponType = couponType; TutorId = tutorId; Value = value; Expiration = expiration; }
/// <summary> /// Returns a description of this coupon /// </summary> /// <param name="packages">if this coupon is package-based, then it needs the packages to return a user-friendly name</param> /// <returns></returns> public string GetDescription(List <PackageItem> packages = null) { string description = CouponType.ToString(); if (CouponType == PlayerComp.CouponTypes.FixedValue) { description = String.Format("{0:f} Off", Value); } else if (CouponType == PlayerComp.CouponTypes.PercentPackage) { string packageName = "Multiple Packages"; if (EarnedPackageIDs.Count == 1) { int packageID = EarnedPackageIDs.First(); PackageItem match = null; if (packages != null) { match = packages.FirstOrDefault(x => x.PackageId == packageID); // find the package name for display } if (match != null) { packageName = match.PackageName; } else { packageName = "Package " + packageID; } } description = String.Format("{0}% off {1}", Value.ToString(), packageName); } else // Alt Price Package { string packageName = "Multiple Packages"; if (EarnedPackageIDs.Count == 1) { int packageID = EarnedPackageIDs.First(); PackageItem match = null; if (packages != null) { match = packages.FirstOrDefault(x => x.PackageId == packageID); // find the package name for display } if (match != null) { packageName = match.PackageName; } else { packageName = "Package " + packageID; } } description = String.Format("Alt Price {0}", packageName); } return(description); }
public CouponType GetCouponTypeByCode(string code) { DynamicParameters paras = new DynamicParameters(); paras.Add("@code", code, System.Data.DbType.String); CouponType record = DapperSqlHelper.FindOne <CouponType>("select * from [dbo].[CouponType] where CouponTypeCode=@code", paras, false); return(record); }
public CouponType GetCouponTypeByIsGivedType(string taskcode) { DynamicParameters paras = new DynamicParameters(); paras.Add("@taskcode", taskcode, System.Data.DbType.String); CouponType record = DapperSqlHelper.FindOne <CouponType>("select * from [dbo].[CouponType] where IsGivedType=1 and TaskType=@taskcode", paras, false); return(record); }
public GetOneFreeCoupon(string code, CouponType type, string buyItemCode, int buyItemQuantity, string freeItemCode, IEnumerable <ShoppingItem> itemsInStore) { Code = code; Type = type; BuyItemCode = buyItemCode; BuyItemQuantity = buyItemQuantity; FreeItemCode = freeItemCode; ItemsInStore = itemsInStore; }
private void setValues() { double cartTotal = 0; double taxBase = 0; double tax = 0; double discount = 0; double delivery = 0; double total = 0; double userDiscount = 0; CouponType discountType = new CouponType(1, "Procentualni"); double totalForDiscount = 0; if (Page.User.Identity.IsAuthenticated) { eshopBE.User user = UserBL.GetUser(-1, Page.User.Identity.Name); userDiscount = user.Discount; discountType = new CouponBL().GetCouponType(user.DiscountTypeID); } for (int i = 0; i < _cart.Rows.Count; i++) { cartTotal += double.Parse(_cart.Rows[i]["productPrice"].ToString()) * double.Parse(_cart.Rows[i]["quantity"].ToString()); discount += double.Parse(_cart.Rows[i]["productPrice"].ToString()) * double.Parse(_cart.Rows[i]["quantity"].ToString()) - double.Parse(_cart.Rows[i]["total"].ToString()); totalForDiscount += !bool.Parse(ConfigurationManager.AppSettings["userDiscountOnlyOnProductNotOnPromotion"]) || double.Parse(_cart.Rows[i]["productPrice"].ToString()) == double.Parse(_cart.Rows[i]["userPrice"].ToString()) ? double.Parse(_cart.Rows[i]["productPrice"].ToString()) * double.Parse(_cart.Rows[i]["quantity"].ToString()) : 0; } lblNumberOfProducts.Text = _cart.Rows.Count.ToString(); double userDiscountValue = (discountType.CouponTypeID == 1) ? (totalForDiscount) * (userDiscount / 100) : userDiscount; double totalWithDiscount = cartTotal - discount - userDiscountValue; taxBase = (cartTotal - discount - userDiscountValue) / 1.2; tax = cartTotal - discount - userDiscountValue - taxBase; delivery = (cartTotal - discount - userDiscountValue > double.Parse(ConfigurationManager.AppSettings["freeDeliveryTotalValue"])) ? 0 : double.Parse(ConfigurationManager.AppSettings["deliveryCost"]); total = cartTotal - discount + delivery - userDiscountValue; lblTaxBase.Text = string.Format("{0:N2}", taxBase); lblPdv.Text = string.Format("{0:N2}", tax); lblTotalWithTax.Text = string.Format("{0:N2}", cartTotal); double totalDiscount = discount + userDiscountValue; lblDiscount.Text = string.Format("{0:N2}", (0 - totalDiscount)); lblTotalWithDiscount.Text = string.Format("{0:N2}", totalWithDiscount); //lblDiscount.Text = "42423424"; lblDelivery.Text = string.Format("{0:N2}", delivery); lblTotal.Text = string.Format("{0:N2}", total); }
private void Add() { var couponType = new CouponType { Name = NewType, Description = NewDescription }; MainDataSource.Instance.CouponTypes.Add(couponType); MainDataSource.Instance.Context.CouponTypes.Add(couponType); MainDataSource.Instance.Context.SaveChangesAsync(); }
public Bond(ICouponCalculationService couponCalculationService, DateTime startDate, int termYears, CouponType couponType, decimal notional, string currency, decimal interestRate) { _couponCalculationService = couponCalculationService; _startDate = startDate; _notional = notional; _maturityDate = _startDate.AddYears(termYears); _couponType = couponType; _currency = currency; _interestRate = interestRate; }
public void Adds_semi_annual_increment() { DateTime start = new DateTime(2018, 4, 1); DateTime expectedEnd = new DateTime(2018, 10, 1); CouponType coupon = CouponType.SemiAnnual; var sut = GetSUT(); var increment = sut.GetCouponIncrement(start, coupon); Assert.AreEqual(expectedEnd, start.Add(increment)); }
protected void createCoupon_Click(object sender, EventArgs e) { ViewState["CouponEditing"] = null; editCouponPanel.Controls.Clear(); editCouponPanel.Visible = true; CouponType newCouponType = CouponType.GetCouponType(int.Parse(ddlCouponTypes.SelectedValue)); LoadNewCouponEditor(newCouponType); }
private void LoadNewCouponEditor(CouponType newCouponType) { ViewState["NewCouponType"] = newCouponType.CouponTypeID; string editorControlPath = String.Format("~/Admin/CouponEditors/" + newCouponType.CouponClassType.FullName.Replace(".", "_") + ".ascx"); ICouponEditor editorControl = (ICouponEditor)Page.LoadControl(editorControlPath); editorControl.NewCoupon(newCouponType); editorControl.CouponSaved += new EventHandler <EventArgs>(editorControl_CouponSaved); editCouponPanel.Controls.Add((Control)editorControl); }
//public virtual void ApplyCoupon(User user, Tutor tutor) //{ // if (Expiration.GetValueOrDefault(DateTime.MaxValue) < DateTime.UtcNow) // { // throw new ArgumentException("invalid coupon"); // } // if (AmountOfUsers.HasValue && AmountOfUsers.Value <= _userCoupon.Count) // { // throw new OverflowException(); // } // var p = new UserCoupon(user, this, tutor); // if (!_userCoupon.Add(p)) // { // throw new ArgumentException("user already applied coupon"); // } //} public static decimal CalculatePrice(CouponType type, decimal price, decimal couponValue) { var result = type switch { CouponType.Flat => (price - couponValue), CouponType.Percentage => (price * ((100 - couponValue) / 100)), _ => throw new ArgumentOutOfRangeException() }; return(Math.Max(result, 0)); } }
public CreateCouponCommand(string code, CouponType couponType, long?tutorId, decimal value, DateTime?expiration, string description, string owner, int?amountOfUsers, int amountOfUsePerUser) { Code = code; CouponType = couponType; TutorId = tutorId; Value = value; Expiration = expiration; Description = description; Owner = owner; AmountOfUsers = amountOfUsers; AmountOfUsePerUser = amountOfUsePerUser; }
public TimeSpan GetCouponIncrement(DateTime startDate, CouponType couponType) { switch (couponType) { case CouponType.Annual: return(startDate.AddYears(1) - startDate); case CouponType.SemiAnnual: return(startDate.AddMonths(6) - startDate); default: throw new UnsupportedCouponTypeException(couponType); } }
protected void btnSave_Click(object sender, EventArgs e) { if ((bool)ViewState["IsNew"]) { PercentOffCoupon pctOffCoupon = new PercentOffCoupon( txtCouponCode.Text, CouponType.GetCouponType((int)ViewState["CouponTypeId"])); FillCouponValiues(pctOffCoupon); } else { PercentOffCoupon pctOffCoupon = (PercentOffCoupon)Coupon.GetCoupon(txtCouponCode.Text); FillCouponValiues(pctOffCoupon); } }
public static Coupon CreateCoupon( CouponType couponType = CouponType.Amount, double value = 0, DateTime?expiration = null ) { expiration ??= DateTime.Now.AddDays(1); return(new Coupon { CouponType = couponType, Value = value, Expiration = expiration.Value }); }
protected void Page_Load(object sender, EventArgs e) { System.Collections.Generic.Dictionary <int, CouponType> couponTypes = CouponType.GetAllCouponTypes(); GridView1.DataSource = couponTypes.Values; GridView1.DataBind(); PercentOffCoupon pctCoupon = new PercentOffCoupon("AAAA", couponTypes[1]); pctCoupon.PercentOff = 10; pctCoupon.SaveCoupon(); PercentOffCoupon savedCoupon = (PercentOffCoupon)Coupon.GetCoupon("AAAA"); this.DetailsView1.DataSource = new object[] { savedCoupon }; this.DetailsView1.DataBind(); }
public CouponModel AddCoupon(CouponType type, int amount, decimal minBasketPrice) { if (amount >= 0 && minBasketPrice >= 0) { var coupon = new CouponModel { Id = Guid.NewGuid(), Type = type, Amount = amount, MinBasketPrice = minBasketPrice }; CouponList.Add(coupon); return(coupon); } Console.WriteLine("Coupon could not be added. Coupon amount, minimum product price cannot be negative"); return(null); }
public static string ToText(this CouponType enumModel) { switch (enumModel) { case CouponType.AppointProductDiscount: return("指定商品折扣优惠券"); case CouponType.AppointProductFullcut: return("指定商品满减优惠券"); case CouponType.NormalDiscount: return("折扣优惠券"); case CouponType.NormalFullcut: return("满减优惠券"); default: return(""); } }
public decimal GetInterestAmount(decimal notional, decimal interestRate, CouponType couponType) { decimal couponFactor; switch (couponType) { case CouponType.Annual: couponFactor = 1m; break; case CouponType.SemiAnnual: couponFactor = 0.5m; break; default: throw new UnsupportedCouponTypeException(couponType); } return(notional * interestRate * couponFactor); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindCoupons(); ddlCouponTypes.DataSource = new Query("CSK_CouponTypes").ExecuteReader(); ddlCouponTypes.DataBind(); } if (ViewState["CouponEditing"] != null) { string couponCode = (string)ViewState["CouponEditing"]; LoadCouponEditor(couponCode); } if (ViewState["NewCouponType"] != null) { int newCouponTypeId = (int)ViewState["NewCouponType"]; CouponType newCouponType = CouponType.GetCouponType(newCouponTypeId); LoadNewCouponEditor(newCouponType); } }
public void AddCoupon(string couponCode, HttpContextBase httpContext) { Basket basket = GetBasket(httpContext); Coupon coupon = coupons.GetAll().FirstOrDefault(c => c.CouponCode == couponCode); if (coupon != null) { CouponType couponType = couponTypes.GetById(coupon.CouponTypeId); if (couponType != null) { BasketCoupon basketCoupon = new BasketCoupon(); if (couponType.Type == "MoneyOff") { MoneyOff(coupon, basket, basketCoupon); } if (couponType.Type == "PercentOff") { PercentOff(coupon, basket, basketCoupon); } baskets.Commit(); } //end couponType if } //end coupon if } //end addCoupon
public Coupon([NotNull] string code, CouponType couponType, Tutor tutor, decimal value, int?amountOfUsers, int amountOfUsePerUser, DateTime?expiration, string description, string owner) { if (value <= 0) { throw new ArgumentOutOfRangeException(nameof(value)); } if (amountOfUsers.HasValue && amountOfUsers.Value <= 0) { throw new ArgumentOutOfRangeException(nameof(value)); } if (couponType == CouponType.Percentage && value > 100) { throw new ArgumentException("value cannot be more than 100"); } if (code is null) { throw new ArgumentNullException(nameof(code)); } if (!code.Length.IsBetween(MinimumLength, MaxLength)) { throw new ArgumentOutOfRangeException(nameof(code)); } Code = code; CouponType = couponType; Tutor = tutor; Value = value; AmountOfUsers = amountOfUsers; AmountOfUsePerUser = amountOfUsePerUser; Expiration = expiration; Description = description; Owner = owner; CreateTime = DateTime.UtcNow; }
public Coupon(string code, Percent discountPercentage, CouponType couponType) { Code = code; DiscountPercentage = discountPercentage; CouponType = couponType; }
public UnsupportedCouponTypeException(CouponType couponType) : base(string.Format("Unsupported coupon type:{0}", couponType)) { }
public CouponCalculatorFactory(IRepository repository, CouponType type) { _repository = repository; _type = type; }