Пример #1
0
        public JsonResult CreateVoucherCode(int quantity, long codeValue, Guid voucherMethodId)
        {
            Dictionary <Guid, string> codes = new Dictionary <Guid, string>();

            for (int i = 0; i < quantity; i++)
            {
                codes.Add(Guid.NewGuid(), VoucherCodeServices.GenerateCode());
            }
            var currentUserId = UserSessionContext.CurrentUserId();
            var createdDate   = DateTime.Now;

            foreach (var code in codes)
            {
                MemoryMessageBuss.PushCommand(new CreateVoucherCode(code.Key, code.Value, codeValue, voucherMethodId, currentUserId, createdDate));
            }
            return(Json(new { Ok = true, Data = new { Codes = codes.Select(i => new { Id = i.Key, Code = i.Value }) }, Message = "Success" }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public void CalculateVoucher(string voucherCode, Guid?userId)
        {
            if (_items == null || _items.Count == 0)
            {
                throw new Exception("No item to calculate");
            }

            if (string.IsNullOrEmpty(voucherCode))
            {
                throw new Exception("voucher code required");
            }

            if (_isPreCalculated == false)
            {
                PreCalculate();
            }

            VoucherCode code;

            if (VoucherCodeServices.IsValidCode(voucherCode, out code) == false)
            {
                return;
            }
            if (code == null)
            {
                return;
            }

            var id = Guid.Parse(Id);

            userId = userId ?? Guid.Empty;

            var voucherValue = VoucherCodeServices.CalculateValue(id, voucherCode, _cartSubTotal, userId);

            ApplyChange(new ShoppingCartCalculatedVoucherCode(id, voucherCode, voucherValue, userId.Value));
        }