Inheritance: System.Web.Services.WebService
        public void ListCouponsMaxedOut()
        {
            var coupon = new Coupon(GetMockCouponCode(), GetMockCouponName("Maxed Out test"), 10)
            {
                MaxRedemptions = 1
            };

            coupon.Create();
            coupon.CreatedAt.Should().NotBe(default(DateTime));

            var account = CreateNewAccountWithBillingInfo();

            var redemption = account.RedeemCoupon(coupon.CouponCode, "USD");

            redemption.CreatedAt.Should().NotBe(default(DateTime));

            var fromService = Coupons.Get(coupon.CouponCode);

            fromService.Should().NotBeNull();

            var expiredCoupons = Coupons.List(Coupon.CouponState.Expired);

            expiredCoupons.Should().NotContain(coupon,
                                               "the Recurly service marks this expired coupon as \"Inactive\", which cannot be searched for.");
        }
        public decimal[] GetCouponAccrualFactors()
        {
            var result = new List <decimal>();

            Coupons.ForEach(cashflow => result.Add(cashflow.CouponYearFraction));
            return(result.ToArray());
        }
示例#3
0
        public ActionResult Save(CouponListViewModel couponVM)
        {
            if (!ModelState.IsValid)
            {
                return(View("CouponForm", couponVM));
            }

            //New
            if (couponVM.CouponId == null)
            {
                var     cookie   = Request.Cookies["idCookie"];
                var     R_Id     = cookie.Values["r_id"];
                Coupons instance = new Coupons
                {
                    CouponId   = Guid.NewGuid().ToString("N"),
                    R_Id       = R_Id,
                    StartTime  = couponVM.StartTime,
                    EndTime    = couponVM.EndTime,
                    Title      = couponVM.Title,
                    Desciption = couponVM.Desciption
                };
                couponService.Create(instance);
            }
            else
            {
                var coupon = couponService.GetByID(couponVM.CouponId);
                Mapper.Map <CouponListViewModel, Coupons>(couponVM, coupon);
                couponService.Update(coupon);
            }

            return(RedirectToAction("Index"));
        }
示例#4
0
        public async Task <IActionResult> Create(Coupons coupons)
        {
            if (ModelState.IsValid)
            {
                var files = HttpContext.Request.Form.Files;
                if (files[0] != null && files[0].Length > 0)
                {
                    byte[] p1 = null;
                    using (var fs1 = files[0].OpenReadStream())
                    {
                        using (var ms1 = new MemoryStream())
                        {
                            fs1.CopyTo(ms1);
                            p1 = ms1.ToArray();
                        }
                    }
                    coupons.Picture = p1;
                    _db.Coupons.Add(coupons);
                    await _db.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(coupons));
        }
示例#5
0
        /// <summary>
        /// 优惠劵类型列表
        /// </summary>
        public ActionResult CouponTypeList()
        {
            CouponTypeListModel model = new CouponTypeListModel();

            model.CouponTypeList = Coupons.GetSendingCouponTypeList(WorkContext.StoreId, DateTime.Now);
            return(View(model));
        }
示例#6
0
        public IHttpActionResult CreateCoupon([FromBody] Coupons data)
        {
            CouponsService service = new CouponsService();

            service.CouponsCreate(data);
            return(Ok(data));
        }
示例#7
0
 public bool UpdateCouponMaster(Coupons cou)
 {
     SqlParameter[] aParms = GetParameters(cou);
     SetParameters(aParms, cou);
     using (SqlConnection conn = General.GetConnection())
     {
         bool status = false;
         using (SqlTransaction trans = conn.BeginTransaction())
         {
             try
             {
                 SqlHelper.ExecuteNonQuery(trans, CommandType.Text, SQL_UpdateCoupon, aParms);
                 trans.Commit();
                 status = true;
             }
             catch (System.Exception e)
             {
                 Console.Write(e);
                 trans.Rollback();
                 //log.Error(lobjError, e);
                 throw;
             }
         }
         return(status);
     }
 }
示例#8
0
        public Coupons GetSingleCouponDetails(string Id)
        {
            A_ADM_Coupon_RefDAL couDAL = new A_ADM_Coupon_RefDAL();
            Coupons             data   = couDAL.GetSingleCouponDetailDb(Id);

            return(data);
        }
        public IHttpActionResult PutCoupons(int id, Coupons coupons)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != coupons.idcoupon)
            {
                return(BadRequest());
            }

            db.Entry(coupons).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CouponsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#10
0
        public Coupons GetSingleCouponDetailDb(string id)
        {
            SqlConnection con = null;

            SqlParameter[] aParms = new SqlParameter[] { new SqlParameter(PARAM_Coupon_ID, id) };
            Coupons        cou    = new Coupons();

            try
            {
                con = General.GetConnection();
                SqlDataReader reader = SqlHelper.ExecuteReader(con, CommandType.Text, SQL_Select_Coupon_Details, aParms);
                while (reader.Read())
                {
                    cou.Coupon_id         = reader.GetString(0);
                    cou.Coupon_Name       = reader.GetString(1);
                    cou.Coupon_VenderName = reader.GetString(2);
                    cou.Coupon_Desc       = reader.GetString(3);
                    cou.Coupon_StartDate  = reader.GetDateTime(4);
                    cou.Coupon_EndDate    = reader.GetDateTime(5);
                    cou.Coupon_Status     = reader.GetString(6);
                    cou.Coupon_PicUrl     = reader.GetString(7);
                    cou.Create_Date       = reader.GetDateTime(8);
                    cou.Update_Date       = reader.GetDateTime(9);
                    cou.Create_By         = reader.GetString(10);
                    cou.Update_By         = reader.GetString(11);
                }
                reader.Close();
                return(cou);
            }
            catch (Exception e)
            {
                Console.Write(e);
                return(null);
            }
        }
示例#11
0
        public ActionResult Delete(CouponsDTO entity)
        {
            Coupons c = Mapper.Map <CouponsDTO, Coupons>(entity);

            couponRepository.Delete(c);
            return(Json(entity, JsonRequestBehavior.AllowGet));
        }
示例#12
0
        public override PromotionReward[] EvaluatePromotion(IEvaluationContext context)
        {
            var retVal       = new List <PromotionReward>();
            var promoContext = context as PromotionEvaluationContext;

            if (promoContext == null)
            {
                throw new ArgumentException("context should be PromotionEvaluationContext");
            }

            //Check coupon
            var couponValid = (Coupons != null && Coupons.Any()) ? Coupons.Any(x => String.Equals(x, promoContext.Coupon, StringComparison.InvariantCultureIgnoreCase)) : true;


            //Evaluate reward for all promoEntry in context
            foreach (var promoEntry in promoContext.PromoEntries)
            {
                //Set current context promo entry for evaluation
                promoContext.PromoEntry = promoEntry;
                foreach (var reward in Rewards.Select(x => x.Clone()))
                {
                    reward.Promotion = this;
                    reward.IsValid   = couponValid && Condition(promoContext);
                    var catalogItemReward = reward as CatalogItemAmountReward;
                    //Set productId for catalog item reward
                    if (catalogItemReward != null && catalogItemReward.ProductId == null)
                    {
                        catalogItemReward.ProductId = promoEntry.ProductId;
                    }
                    retVal.Add(reward);
                }
            }
            return(retVal.ToArray());
        }
示例#13
0
        public async Task <IActionResult> Create(Coupons model)
        {
            if (ModelState.IsValid)
            {
                var files = HttpContext.Request.Form.Files;

                // this line of Code is use to Store the Image into  the Database Not into the server

                if (files[0] != null && files[0].Length > 0)
                {
                    byte[] p1 = null;

                    using (var fs1 = files[0].OpenReadStream())  // using System.IO
                    {
                        using (var ms1 = new MemoryStream())
                        {
                            fs1.CopyTo(ms1);

                            p1 = ms1.ToArray();
                        }
                    }

                    model.Pitcher = p1;

                    _context.Coupons.Add(model);

                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(model));
        }
示例#14
0
        public ActionResult DeleteCoupons()
        {
            int appId = Context.GetRequestInt("appId", 0);
            int id    = Context.GetRequestInt("id", 0);

            if (id <= 0)
            {
                return(Json(new { isok = false, msg = "id不能小于0" }));
            }

            Coupons model = CouponsBLL.SingleModel.GetModel(id);

            if (model == null)
            {
                return(Json(new { isok = false, msg = "找不到优惠券,请刷新重试" }));
            }

            model.State      = (int)CouponState.已失效;
            model.UpdateTime = DateTime.Now;
            if (CouponsBLL.SingleModel.Update(model, "state,updatetime"))
            {
                return(Json(new { isok = true, msg = "保存成功" }));
            }
            else
            {
                return(Json(new { isok = true, msg = "保存失败" }));
            }
        }
示例#15
0
        public OperationResult CouponsCreate(Coupons input)
        {
            var result = new OperationResult();

            try
            {
                XbooxLibraryDBContext       context = new XbooxLibraryDBContext();
                GeneralRepository <Coupons> couRepo = new GeneralRepository <Coupons>(context);
                Coupons entity = new Coupons()
                {
                    Id         = Guid.NewGuid(),
                    CouponName = input.CouponName,
                    Discount   = input.Discount,
                    CouponCode = input.CouponCode,
                    StartTime  = input.StartTime,
                    EndTime    = input.EndTime
                };
                couRepo.Create(entity);
                couRepo.SaveContext();
                result.IsSuccessful = true;
            }
            catch (Exception ex)
            {
                result.IsSuccessful = false;
                result.exception    = ex;
            }
            return(result);
        }
示例#16
0
        public bool InsertNewCoupon(Coupons Coupon)
        {
            A_ADM_Coupon_RefDAL   obj     = new A_ADM_Coupon_RefDAL();
            U_ADM_MEDIA_MASTERDAL objImg  = new U_ADM_MEDIA_MASTERDAL();
            U_ADM_MEDIA_MASTER    imgData = new U_ADM_MEDIA_MASTER();
            DateTime now = System.DateTime.Now;

            imgData.Media_Id            = Guid.NewGuid().ToString();
            imgData.Media_Type          = "Image";
            imgData.Media_File_Location = Coupon.Coupon_PicUrl;
            imgData.Media_Source        = "";
            imgData.Media_Oth_Dtl       = "";
            imgData.Created_by          = Coupon.Create_By;
            imgData.Updated_by          = Coupon.Update_By;
            imgData.Created_Date        = now;
            imgData.Updated_Date        = now;

            Coupon.Coupon_id   = Guid.NewGuid().ToString();
            Coupon.Create_Date = now;
            Coupon.Update_Date = now;

            if (objImg.InsertU_ADM_MEDIA_MASTER(imgData))
            {
                Coupon.Coupon_PicUrl = imgData.Media_Id;
                if (obj.InsertCouponDb(Coupon))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#17
0
        public async Task LoadCoupons()
        {
            IsBusy         = true;
            LoadingMessage = "Loading...";

            var surveyResponses = await ServiceLocator.AzureService.GetSurveyResponsesByUserId(Helpers.Settings.UserId);

            if (surveyResponses.Count > 0)
            {
                foreach (SurveyResponse s in surveyResponses)
                {
                    if (s.CouponId != null)
                    {
                        var coupon = await ServiceLocator.AzureService.GetById <Coupon>(s.CouponId);

                        coupon.CreatedDate = s.CreatedAt;
                        Coupons.Add(coupon);
                    }
                }
            }
            else
            {
                await couponsPage.DisplayAlert("Sorry", "No coupons available, please take a survey.", "ok");
            }

            IsBusy = false;
        }
示例#18
0
 protected void ApplyButton_Click(object sender, EventArgs e)
 {
     Coupons coupon = new Coupons();
     DataLayer dLayer = new DataLayer();
     int OrgID;
     int serviceOrder;
     int shopperID;
     string url;
     string workflow = Session["workflow"].ToString();
     try
     {
         OrgID = System.Convert.ToInt32(Session["OrgID"]);
     }
     catch (Exception ex)
     {
         OrgID = 0;
     }
     try
     {
         shopperID = System.Convert.ToInt32(Session["shopperID"]);
     }
     catch (Exception ex)
     {
         shopperID = 0;
     }
     try
     {
         serviceOrder = System.Convert.ToInt32(Session["serviceOrder"]);
     }
     catch (Exception ex)
     {
         serviceOrder = 0;
     }
     double total = 0; //TODO: change to get from order
     try
     {
         total = System.Convert.ToDouble(Session["total"]);
         int couponID = System.Convert.ToInt32(txtCID.Text);
         TempLabel.Text = System.Convert.ToString(coupon.ValidateCoupon(couponID, OrgID, total));
     }
     catch (FormatException ex)
     {
         TempLabel.Text = "Can not convert string";
     }
     catch (OverflowException ex)
     {
         TempLabel.Text = "Number too large";
     }
     catch (Exception ex)
     {
     }
     serviceOrder = serviceOrder + 1;
     Session["serviceOrder"] = serviceOrder;
     url = dLayer.getNextService(OrgID, serviceOrder, workflow);
     if (url == "")
     {
         url = "ApplyCoupon.aspx";
     }
     Response.Redirect(url);
 }
示例#19
0
 public ISitePage ClickShowCouponCode(int v)
 {
     webElementComposer.Click(Coupons.ElementAtOrDefault(v).FindElement(By.XPath(".//a[@data-func='showCode']")));
     wait.UntilWindowsCountIsHigherThan(1);
     driverWrapper.SwitchToCouponFollowWindow();
     return(this);
 }
示例#20
0
        public IHttpActionResult SaveEditCoupon([FromBody] Coupons data)
        {
            CouponsService service = new CouponsService();

            service.CouponsEdit(data);
            return(Ok(data));
        }
 public static double DiscountedPrice(Coupons couponFromDb, double OriginalOrderTotal)
 {
     if (couponFromDb == null)
     {
         return(OriginalOrderTotal);
     }
     else
     {
         if (couponFromDb.MinimumAmount > OriginalOrderTotal)
         {
             return(OriginalOrderTotal);
         }
         else
         {
             //everything is valid
             if (Convert.ToInt32(couponFromDb.CouponType) == (int)Coupons.ECouponType.Dollar)
             {
                 //$10 off $100
                 return(Math.Round(OriginalOrderTotal - couponFromDb.Discount, 2));
             }
             if (Convert.ToInt32(couponFromDb.CouponType) == (int)Coupons.ECouponType.Percent)
             {
                 //10% off $100
                 return(Math.Round(OriginalOrderTotal - (OriginalOrderTotal * couponFromDb.Discount / 100), 2));
             }
         }
     }
     return(OriginalOrderTotal);
 }
示例#22
0
        /// <summary>
        /// 验证优惠劵编号
        /// </summary>
        /// <returns></returns>
        public ActionResult VerifyCouponSN()
        {
            string couponSN = WebHelper.GetQueryString("couponSN");//优惠劵编号

            if (couponSN.Length == 0)
            {
                return(AjaxResult("emptycouponsn", "请输入优惠劵编号"));
            }
            else if (couponSN.Length != 16)
            {
                return(AjaxResult("errorcouponsn", "优惠劵编号不正确"));
            }

            CouponInfo couponInfo = Coupons.GetCouponByCouponSN(couponSN);

            if (couponInfo == null)//不存在
            {
                return(AjaxResult("noexist", "优惠劵不存在"));
            }
            else if (couponInfo.Oid > 0)//已使用
            {
                return(AjaxResult("used", "优惠劵已使用"));
            }
            else if (couponInfo.Uid > 0)//已激活
            {
                return(AjaxResult("activated", "优惠劵已激活"));
            }
            else//未激活
            {
                return(AjaxResult("nonactivated", "优惠劵未激活"));
            }
        }
示例#23
0
        /// <summary>
        /// 立减金
        /// </summary>
        /// <param name="aid"></param>
        /// <param name="storeId"></param>
        /// <param name="coupons"></param>
        /// <param name="act"></param>
        /// <returns></returns>
        public ActionResult ReductionCardEdit(int aid = 0, int storeId = 0, int id = 0)
        {
            Coupons model = null;

            if (id > 0)
            {
                model = CouponsBLL.SingleModel.GetModel(id);
                if (model == null)
                {
                    return(Content("数据不存在"));
                }
                if (!string.IsNullOrEmpty(model.GoodsIdStr))
                {
                    List <DishGood> goodsList = DishGoodBLL.SingleModel.GetList($"id in ({model.GoodsIdStr}) and state=1");
                    if (goodsList != null && goodsList.Count > 0)
                    {
                        model.SelectGoods = new List <object>();
                        foreach (var goods in goodsList)
                        {
                            model.SelectGoods.Add(new { goods.id, goods.g_name, goods.add_time_str, goods.img });
                        }
                    }
                }
            }
            else
            {
                model            = new Coupons();
                model.appId      = aid;
                model.StoreId    = storeId;
                model.TicketType = (int)TicketType.立减金;
            }
            return(View(model));
        }
示例#24
0
    protected void BuyButton_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            return;
        }
        try
        {
            Customer customer = GetLoggedCustomer();
            if (customer == null)
            {
                customer = AddCustomer();
            }

            Order order = AddOrder(customer);
            //Take credit card payment
            if (ChargeCreditCard(order.OrderNumber))
            {
                //Expire any coupons, clear the cart and redirect to Receipt.aspx
                Cart.CartCoupons.Where(c => c.IsCouponUnique).All((c) => { Coupons.DeactivateCoupon(c.CouponID); return(true); });
                Cart = null;
                Response.Redirect("Receipt.aspx?CustomerID=" + WebUtility.EncodeParamForQueryString(customer.CustomerID.ToString()) + "&OrderID=" + WebUtility.EncodeParamForQueryString(order.OrderID.ToString()));
            }
            else
            {
                //Log in the customer and set the transaction to error
                FormsAuthentication.SetAuthCookie(customer.Email, true);
                Orders.UpdateOrderStatus(order.OrderID, (int)OrderStatusEnum.PaymentError);
            }
        }
        catch (Exception ex)
        {
            MessageLabel.Text = "Transaction error: " + ex.Message;
        }
    }
示例#25
0
        public bool InsertNewCoupon(Coupons cou)
        {
            try
            {
                StreamReader   readStream;
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(@"http://" + GeneralBLL.Service_Link + "/Services/AdminService.svc/CreateNewCoupon");
                httpWebRequest.Method      = "POST";
                httpWebRequest.ContentType = @"application/json; charset=utf-8";

                using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                {
                    string json = new JavaScriptSerializer().Serialize(cou);

                    streamWriter.Write(json);
                }

                HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                readStream = new StreamReader(httpResponse.GetResponseStream());

                var serializer = new DataContractJsonSerializer(typeof(bool));

                bool obj = Convert.ToBoolean(serializer.ReadObject(readStream.BaseStream));

                return(obj);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
示例#26
0
        public void Update(Coupons user)
        {
            var couponToUpdate = Get(user.Id);

            couponToUpdate = user;
            dbContext.SaveChanges();
        }
示例#27
0
        /// <summary>
        /// 获取优惠券减免金额文案信息:(代金券,100元):-90元
        /// </summary>
        /// <param name="userCoupon"></param>
        /// <returns></returns>
        public string GetCouponPriceStr(CouponLog userCoupon, int payment)
        {
            Coupons couponConf = CouponsBLL.SingleModel.GetModel(userCoupon.CouponId);
            string  couponType = couponConf.CouponWay == 0 ? $"代金券,{couponConf.Money / 100f}元" : $"折扣,{couponConf.Money / 100f}折";

            return($"({couponType}):-{GetCouponPrice(couponConf, payment) / 100f}元");
        }
        public decimal[] GetCouponNotionals()
        {
            var result = new List <decimal>();

            Coupons.ForEach(cashflow => result.Add(cashflow.Notional));
            return(result.ToArray());
        }
示例#29
0
        public static AuthorCouponDTO Entity2AuthorCouponDTO(this Coupons entity)
        {
            CourseEnums.eCouponKinds kind;
            if (entity.CourseId != null)
            {
                kind = CourseEnums.eCouponKinds.Course;
            }
            else if (entity.BundleId != null)
            {
                kind = CourseEnums.eCouponKinds.Bundle;
            }
            else
            {
                kind = CourseEnums.eCouponKinds.Author;
            }

            return(new AuthorCouponDTO
            {
                CouponId = entity.Id
                , Kind = kind
                , KindDisplayName = kind.ToString()
                , OwnerUserId = entity.OwnerUserId
                , BundleId = entity.BundleId
                , CourseId = entity.CourseId
                , CouponName = entity.CouponName
                , Amount = Math.Round((decimal)(entity.CouponTypeAmount ?? 0), 2)
                , AutoGeneration = entity.AutoGenerate
                , Type = Utils.ParseEnum <CourseEnums.CouponType>(entity.CouponTypeId.ToString())
                , ExpirationDate = entity.ExpirationDate
                , SubscriptionMonths = entity.SubscriptionMonths
                , IsActive = entity.ExpirationDate == null || DateTime.Now.Date <= entity.ExpirationDate
            });
        }
        public decimal[] GetPaymentDiscountFactors()
        {
            var result = new List <decimal>();

            Coupons.ForEach(cashflow => result.Add(cashflow.PaymentDiscountFactor));
            return(result.ToArray());
        }
        public ActionResult AddGiftCard(GiftCardViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            var customer = HttpContext.GetCustomer();

            var coupons = Coupons.LoadCoupons(model.Code, customer.StoreID);

            if (!coupons.Any())
            {
                ModelState.AddModelError("Code", "Gift card not found.");
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            var cart = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID());

            cart.SetCoupon(model.Code, true);

            //If the gift card covers the whole order, do some setup that Gateway.MakeOrder requires
            if (cart.GiftCardCoversTotal())
            {
                customer.UpdateCustomer(requestedPaymentMethod: AppLogic.ro_PMCreditCard);
            }

            return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
        }